Skip to content

Instantly share code, notes, and snippets.

@PallawiSinghal
Created March 13, 2019 12:22
Show Gist options
  • Save PallawiSinghal/c12e4a1c2fc332b9c8030442b13dc1c0 to your computer and use it in GitHub Desktop.
Save PallawiSinghal/c12e4a1c2fc332b9c8030442b13dc1c0 to your computer and use it in GitHub Desktop.
# import the necessary packages
from keras.models import load_model
import argparse
import pickle
import cv2
import os
import imutils
test_image_path = "/panda_00125.jpg"
model_path = "/simple_binary_classifcation_model.model"
image = cv2.imread(test_image_path)
output = image.copy()
image = cv2.resize(image, (32,32))
# scale the pixel values to [0, 1]
image = image.astype("float") / 255.0
image = image.flatten()
print ("image after flattening",len(image))
image = image.reshape((1, image.shape[0]))
print ("image--reshape",image.shape)
# load the trained convolutional neural network
print("[INFO] loading network...")
model = load_model(model_path)
# classify the input image
(pands, dogs) = model.predict(image)[0]
# build the label
label = "dogs" if dogs > pands else "Not a dog"
proba = dogs if dogs > pands else pands
label = "{}: {:.2f}%".format(label, proba * 100)
# draw the label on the image
output = imutils.resize(output, width=400)
cv2.putText(output, label, (10, 25), cv2.FONT_HERSHEY_SIMPLEX,
0.7, (0, 255, 0), 2)
# show the output image
cv2.imshow("Output", output)
cv2.waitKey(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment