2

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!

  • Does this answer your question? [Python/Keras - How to access each epoch prediction?](https://stackoverflow.com/questions/36864774/python-keras-how-to-access-each-epoch-prediction) – AlexK May 20 '22 at 06:39
  • I think, as other commenters pointed out, we don't want to re-run the prediction again since this takes time/resources. The goal is to access the predictions that we know keras already made during the epoch, and get them out to use for our purposes. – tim654321 Nov 24 '22 at 01:14

1 Answers1

0

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.

  • 2
    This calls predict, even though evaluate is doing the prediction itself. That is potentially excessive recomputation. Is there any way to get the predicted values that evaluate was using? Perhaps this is what the OP had in mind. – SolverWorld Aug 11 '22 at 22:22