1

I'm using 2.4.0 and to plot Loss vs epochs history for the test and training set. I was able to do it when I was using 1.1.5, using the code below; however, when trying to shift it to the new version, it doesn't work

model.fit(X2_train ,y2_train, epochs =100, batch_size = 32)
plt.subplot(1,1,1)
plt.plot(model.history.history['loss'])
plt.plot(model.history.history['val_loss'])
plt.title('Loss function of CNN Model')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper right')
plt.ylim(0,200)
plt.grid()
plt.tight_layout()
plt.subplots_adjust(left=0.0, bottom=0.0, right=2.0, top=0.8, wspace=0.2, hspace=0.2)
plt.show()

enter image description here

Mario
  • 1,631
  • 2
  • 21
  • 51
  • It's not clear what's your main issue. The code works in tf 1 but not in tf 2? Give some reproducible code. – Innat Mar 20 '21 at 19:14
  • yes it is working in tf 1 and not in tf 2 – Karim Mokdad Mar 20 '21 at 20:58
  • Provided information is not sufficient. Can you share standalone code to replicate your issue? so that we can try to help you. Thanks! –  Mar 31 '21 at 12:52
  • This could be the same issue [here](https://stackoverflow.com/questions/56847576/keyerror-val-loss-when-training-model) or I assume that the problem is what you define as metric in `model.compile( metrics=["ACC"])` like this [post](https://stackoverflow.com/a/68979038/10452700) – Mario Mar 01 '22 at 10:25

1 Answers1

1

Credit to this answer you can plot the graphs with the available metrics of the history for all datasets of the history.history:

model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
history = model.fit(X_train, y_train, nb_epoch=10, validation_data=(X_test, y_test), shuffle=True)

...

pd.DataFrame(history.history).plot(figsize=(8,5))
plt.show()

you can also save/log it. there nice workaround here.

Mario
  • 1,631
  • 2
  • 21
  • 51