DAY 100-100 DAYS MLCODE: Cat Vs Dog Predictions

My Tech World

DAY 100-100 DAYS MLCODE: Cat Vs Dog Predictions

February 20, 2019 100-Days-Of-ML-Code blog 0

In the previous blog, we discussed and developed a Cat Vs Dog classification and saved the model, in this blog, we’ll load the model and use the unlabeled image to see cat vs dog Predictions.

Fore predictions, we first have to load the model which we saved yesterday with name modelcat.h5 .

Let’s load the model for predictions.

# load the model we saved
model = load_model(‘modelcat.h5’)

Now once we loaded the model, we have to activate and complete the model.

model.compile(loss=’binary_crossentropy’,
optimizer=’rmsprop’,
metrics=[‘accuracy’])

Now, our model is active and compiled, we can now use to predict the image and check whether it is cat or dog.

# predicting images
img = image.load_img(‘tcat.jpg’, target_size=(img_width, img_height))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)

images = np.vstack([x])
classes = model.predict_classes(images, batch_size=10)
print(classes)

This above will print the predicted class.

Now, we can also predicts the class of Multiple images by appending .

# predicting multiple images at once
img = image.load_img(‘test2.jpg’, target_size=(img_width, img_height))
y = image.img_to_array(img)
y = np.expand_dims(y, axis=0)

# pass the list of multiple images np.vstack()
images = np.vstack([x, y])
classes = model.predict_classes(images, batch_size=10)

You can find the entire code here. This was a #100daysofMLCode challenge and able to complete the challenge. This was interesting journey and will keep working on Kaggle competition.