Tensorflow Transfer learning and fine-tuning Tutorial Predict Only 1 class

Hi, I try the colab tutorial of Transfer learning and fine-tuning of tensorflow but when I try to check the metrics It shows that the model predicts only 1 class.

Here’s my google colab sample : Code

I don’t think labels is hot encoded on:

for images, labels in validation_dataset.unbatch(): # unbatch the test data and get images and labels
  y_labels.append(labels.numpy().argmax()) # append the index which has the largest value (labels are one-hot)

so that argmax makes every item in y_labels be a 0 (the first item is always the biggest one)

if you remove the argmax the confusion matrix will make more sense

by the way, you could also use the confusion matrix from TensorFlow if you want, there’s an example here.

1 Like

@lgusm Thanksss, I remove the argmax in y_labels and change the y_pred to tf.where(preds <0.5, 0, 1) is that correct?

1 Like