0

I have 2 categories of classes Dogs and cats. I've made a list for these categories:

labels = ["cats", "dogs"]

I've tried using

pred_name = labels[np.argmax(prob)]

to show me the label. But I have a problem with model.predict(img).

It only shows me 1. instead of array [0. 1.].

import cv2
import numpy as np


img = cv2.imread('D:cat.jpg')
img = cv2.resize(img,(150,150))
img = np.reshape(img,[1,150,150,3])

labels=["cats", "dogs"]

classes = model.predict_classes(img)
print(classes)

prob=model.predict(img)
print("%.2f" % prob)

pred_name = labels[np.argmax(prob)]
print(pred_name)

i want my model.predict shows me an array ([0. 1.] or [1. 0.]) instead of just a single number 0 or 1, so I can apply the array into argmax.

thank you in advance.

1 Answers1

0

model.predict should return probabilities of classes. Since you are getting [1] or [0] This might be some different problem related with the training part.

Refering this Returning Probabilities in Keras, your actual problem may be the normalization in data. Otherwise predict should give an output of probabilities. Not the exact classes.

Physicing
  • 532
  • 5
  • 17