0

I am a beginner, working on CNN for image classification and I have a callback function as bellow;

class Metrics(Callback):
    def on_train_begin(self, logs = {}):
        self.val_kappas = []

    def on_epoch_end(self, epoch, logs = {}):
        X_val, y_val = self.validation_data[:2]
        y_val = y_val.sum(axis = 1) - 1

        y_pred = self.model.predict(X_val) > 0.5
        y_pred = y_pred.astype(int).sum(axis = 1) - 1

        _val_kappa = cohen_kappa_score(
            y_val,
            y_pred, 
            weights = 'quadratic'
        )

        self.val_kappas.append(_val_kappa)

        print(f"val_kappa: {_val_kappa:.4f}")

        if _val_kappa == max(self.val_kappas):
            print("Validation Kappa has improved. Saving model.")
            self.model.save('/path_to/model.h5')

        return

When I trained the model;

kappa_metrics = Metrics()

history = model.fit(
    data_generator,
    steps_per_epoch = x_train.shape[0] / BATCH_SIZE,
    epochs = 15,
    validation_data = (x_val, y_val),
    callbacks = [kappa_metrics]
)

I get the following error; enter image description here

Unfortunately I don't understand whats the mistake I do. Please note that I am beginner for CNN and Python.

Mass17
  • 1,555
  • 2
  • 14
  • 29

1 Answers1

1

I solved the problem using the following link. I post it here if someone is interested in it.

https://github.com/keras-team/keras/issues/10472
Mass17
  • 1,555
  • 2
  • 14
  • 29