-2
$\begingroup$
acc += history_fine.history['accuracy']

val_acc += history_fine.history['val_accuracy']

loss += history_fine.history['loss']

val_loss += history_fine.history['val_loss']

plt.figure(figsize=(8, 8))
plt.subplot(2, 1, 1)
plt.plot(acc, label='Training Accuracy')
plt.plot(val_acc, label='Validation Accuracy')
plt.ylim([0.8, 1])
plt.plot([initial_epochs-1,initial_epochs-1],
          plt.ylim(), label='Start Fine Tuning')
plt.legend(loc='lower right')
plt.title('Training and Validation Accuracy')

plt.subplot(2, 1, 2)
plt.plot(loss, label='Training Loss')

plt.plot(val_loss, label='Validation Loss')
plt.ylim([0, 1.0])
plt.plot([initial_epochs-1,initial_epochs-1],
         plt.ylim(), label='Start Fine Tuning')
plt.legend(loc='upper right')
plt.title('Training and Validation Loss')
plt.xlabel('epoch')
plt.show()
New contributor
Sukhpal Kaur is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
$\endgroup$
6
  • $\begingroup$ Please provide a sample of your data, because I cannot reproduce the erroneous behaviour. For me it looks exactly how it should look like. $\endgroup$ – Albo Apr 8 at 6:39
  • $\begingroup$ sir my dataset is MR images of healthy and PD patients and i am using pretrained RESNET $\endgroup$ – Sukhpal Kaur Apr 8 at 9:18
  • $\begingroup$ sir i am using MR images $\endgroup$ – Sukhpal Kaur Apr 8 at 9:36
  • $\begingroup$ Sorry for my unclear question... Could you please provide some sample of the acc, val_acc, loss and val_loss (like the first 10 values of each?). $\endgroup$ – Albo Apr 8 at 10:05
  • $\begingroup$ Found 100 images belonging to 2 classes. Found 37 images belonging to 2 classes. Epoch 1/10 4/4 [==============================] - 54s 14s/step - loss: 0.6015 - accuracy: 0.7000 - val_loss: 0.6964 - val_accuracy: 0.6486 Epoch 2/10 4/4 [==============================] - 49s 12s/step - loss: 0.5935 - accuracy: 0.7000 - val_loss: 0.5359 - val_accuracy: 0.6486 Epoch 3/10 4/4 [==============================] - 49s 12s/step - loss: 0.4653 - accuracy: 0.7000 - val_loss: 0.6738 - val_accuracy: 0.6486 like this sir $\endgroup$ – Sukhpal Kaur Apr 8 at 10:15
0
$\begingroup$

Based on this data, I extracted from a comment of yours:

initial_epochs = 2.0
val_acc = [0.6486, 0.6486, 0.6486]
acc = [0.7000, 0.7000, 0.7000]
loss = [0.6015, 0.5935, 0.4653]
val_loss = [0.6964, 0.5359, 0.6738]

I can plot with:

plt.figure(figsize=(8, 8))
plt.subplot(2, 1, 1)
plt.plot(acc, label='Training Accuracy')
plt.plot(val_acc, label='Validation Accuracy')

plt.ylim([0.4, 1]) # You had plt.ylim([0.8, 1])
plt.plot([initial_epochs-1, initial_epochs-1], plt.ylim(), label='Start Fine Tuning')
plt.legend(loc='lower right')
plt.grid() # I added a grid for both plots
plt.title('Training and Validation Accuracy')

plt.subplot(2, 1, 2)
plt.plot(loss, label='Training Loss')
plt.plot(val_loss, label='Validation Loss')

plt.ylim([0, 1.0])
plt.plot([initial_epochs-1, initial_epochs-1], plt.ylim(), label='Start Fine Tuning')
plt.legend(loc='upper right')
plt.title('Training and Validation Loss')
plt.xlabel('epoch')
plt.grid() # I added a grid for both plots
plt.show()

I assume (based on the data I have), that the problem was due to plt.ylim([0.8, 1]), because val_acc, as well as acc both, were < 0.8, meaning the axis limits were focusing on a part of the plot where no data is.

See the following plot with plt.ylim([0.4, 1]):

enter image description here

New contributor
Albo is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
$\endgroup$
8
  • $\begingroup$ Thanks sir my first graph works well but validation loss graph have still problem it is showing validation loss curve only $\endgroup$ – Sukhpal Kaur Apr 8 at 12:01
  • $\begingroup$ Have you checked the min and max values of the training loss? Might it be outside of the y-axis limits? $\endgroup$ – Albo Apr 8 at 12:17
  • $\begingroup$ yes sir checked no much difference $\endgroup$ – Sukhpal Kaur Apr 8 at 12:20
  • $\begingroup$ Epoch 18/20 4/4 [==============================] - 59s 15s/step - loss: 0.5577 - accuracy: 0.8850 - val_loss: 0.7220 - val_accuracy: 0.5000 Epoch 19/20 4/4 [==============================] - 59s 15s/step - loss: 0.5488 - accuracy: 0.9100 - val_loss: 0.7214 - val_accuracy: 0.5000 Epoch 20/20 4/4 [==============================] - 65s 16s/step - loss: 0.5464 - accuracy: 0.9200 - val_loss: 0.7204 - val_accuracy: 0.5000 $\endgroup$ – Sukhpal Kaur Apr 8 at 12:20
  • $\begingroup$ If I use this data: loss = [0.5577, 0.5488, 0.5464] acc = [0.8850, 0.9100, 0.9200] val_loss = [0.7220, 0.7214, 0.7204] val_acc = [0.5000, 0.5000, 0.5000] I still get a nice graph, similar to the one above. $\endgroup$ – Albo Apr 8 at 12:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.