daily pastebin goal
95%
SHARE
TWEET

Untitled

a guest Mar 22nd, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # import the necessary packages
  2. from keras.models import load_model
  3. import argparse
  4. import pickle
  5. import cv2
  6. import os
  7.  
  8. test_image_path = "cat.jpg"
  9.  
  10. model_path = "smallvggnet.model"
  11. label_binarizer_path = "smallvggnet_lb.pickle"
  12.  
  13. image = cv2.imread(test_image_path)
  14. output = image.copy()
  15. image = cv2.resize(image, (64,64))
  16.  
  17. # scale the pixel values to [0, 1]
  18. image = image.astype("float") / 255.0
  19. image = image.flatten()
  20. print("image.shape[0]",image.shape)
  21. print ("image after flattening",len(image))
  22. image = image.reshape((1, 64,64,3))
  23. print ("image--reshape",image.shape)
  24.  
  25. # load the model and label binarizer
  26. print("[INFO] loading network and label binarizer...")
  27. model = load_model(model_path)
  28. lb = pickle.loads(open(label_binarizer_path, "rb").read())
  29.  
  30. # # make a prediction on the image
  31. print (image.shape)
  32. preds = model.predict(image)
  33.  
  34. # find the class label index with the largest corresponding
  35. # probability
  36. print ("preds.argmax(axis=1)",preds.argmax(axis=1))
  37. i = preds.argmax(axis=1)[0]
  38. print (i)
  39. label = lb.classes_[i]
  40.  
  41. # draw the class label + probability on the output image
  42. text = "{}: {:.2f}%".format(label, preds[0][i] * 100)
  43. cv2.putText(output, text, (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.7,
  44.     (0, 0, 255), 2)
  45. # output = cv2.resize(output, (500,400))
  46. cv2.imwrite("cat_predictvgg.png",output)
  47. # show the output image
  48. cv2.imshow("Image", output)
  49. cv2.waitKey(0)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top