Reputation: 11
I trained a CNN to categorize between dogs and cats and saved it as: MiniProject_01.hdf5 with accuracy of 80%
Now I want to test my model. Here is my code:
import cv2
import keras
CATEGORIES =["Dog", "Cat"]
def data(file):
IMG_SIZE = 64
img_array = cv2.imread(file, cv2.IMREAD_GRAYSCALE)
new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE))
return new_array.reshape(-1, IMG_SIZE, IMG_SIZE, 1)
model = keras.models.load_model("MiniProject_01.hdf5")
prediction = model.predict([data("dog13.jpg")])
print(CATEGORIES[int(prediction[:])])
It just prints: Dog.
Can I get the percent accuracy/probability by which my model said it is a dog?
Upvotes: 0
Views: 868
Reputation: 119
model.predict()
returns a 2dim array with the probability for each output.
So try it with prediction[0][0]
for the Dog or prediction[0][1]
for the Cat.
Upvotes: 0
Reputation: 11
Maybe you mean is percentage confidence. You can use prediction = model.predict_proba([data("dog13.jpg")])
to get it.
Upvotes: 1