In Keras is it possible to see what were the predictions on each step during model.fit() or model.evaluate?

Viewed 110

I am fitting an ANN using Keras. As I don't trust the loss function output, I would like to see, what are the intermediate values that are compared to the target ones in order to calculate the loss after every epoch.

history = model.fit(X, Y, epochs=epoc,batch_size=bs)
    
scores = model.evaluate(X, Y, verbose=0)

As an alternative, could you please tell me, is there a way to get the values for model.evaluate(x,y), because once again it gives only the score.

Thank you in advance for your answer!

1 Answers

To get predictions for each epoch you have to create callbacks and declare a on_epoch_end function as shown in this document.

class prediction_for_each_epoch(tf.keras.callbacks.Callback):
    def on_epoch_end(self, epoch, logs=None):
        self.epoch_predictions = []
        self.epoch_predictions.append(model.predict(test_images))

Here i have created a list to store the results of each epoch.

You have to pass the callbacks while training the model.

model.fit(train_images,train_labels, epochs=2,callbacks=[prediction_for_each_epoch()])

Please refer to this working gist.

Related