I want to create a tf.keras callback to save model predictions for each batch and each epoch during the training
i have tried the following callback, however it gives error like
AttributeError: 'PredictionCallback' object has no attribute 'X_train'
My code is
class PredictionCallback(tf.keras.callbacks.Callback):
def on_epoch_end(self, epoch, logs={}):
y_pred = self.model.predict(self.X_train)
print('prediction: {} at epoch: {}'.format(y_pred, epoch))
pd.DataFrame(y_pred).assign(epoch=epoch).to_csv('{}_{}.csv'.format(filename, epoch))
cnn_model.fit(X_train, y_train,validation_data=[X_valid,y_valid],epochs=epochs,batch_size=batch_size,
callbacks=[model_checkpoint,reduce_lr,csv_logger, early_stopping,PredictionCallback()],
verbose=1)
i also tried Create keras callback to save model predictions and targets for each batch during training but not get success yet.Hope experts will help me.Thanks.