Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # import the necessary packages
- from keras.models import load_model
- import argparse
- import pickle
- import cv2
- import os
- test_image_path = "cat.jpg"
- model_path = "smallvggnet.model"
- label_binarizer_path = "smallvggnet_lb.pickle"
- image = cv2.imread(test_image_path)
- output = image.copy()
- image = cv2.resize(image, (64,64))
- # scale the pixel values to [0, 1]
- image = image.astype("float") / 255.0
- image = image.flatten()
- print("image.shape[0]",image.shape)
- print ("image after flattening",len(image))
- image = image.reshape((1, 64,64,3))
- print ("image--reshape",image.shape)
- # load the model and label binarizer
- print("[INFO] loading network and label binarizer...")
- model = load_model(model_path)
- lb = pickle.loads(open(label_binarizer_path, "rb").read())
- # # make a prediction on the image
- print (image.shape)
- preds = model.predict(image)
- # find the class label index with the largest corresponding
- # probability
- print ("preds.argmax(axis=1)",preds.argmax(axis=1))
- i = preds.argmax(axis=1)[0]
- print (i)
- label = lb.classes_[i]
- # draw the class label + probability on the output image
- text = "{}: {:.2f}%".format(label, preds[0][i] * 100)
- cv2.putText(output, text, (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.7,
- (0, 0, 255), 2)
- # output = cv2.resize(output, (500,400))
- cv2.imwrite("cat_predictvgg.png",output)
- # show the output image
- cv2.imshow("Image", output)
- cv2.waitKey(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement