Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. # import the necessary packages
  2. import requests
  3.  
  4. # initialize the Keras REST API endpoint URL along with the input
  5. # image path
  6. KERAS_REST_API_URL = "http://localhost:5000/predict"
  7. IMAGE_PATH = "me.jpg"
  8.  
  9. # load the input image and construct the payload for the request
  10. image = open(IMAGE_PATH, "rb").read()
  11. payload = {"image": image}
  12.  
  13. # submit the request
  14. r = requests.post(KERAS_REST_API_URL, files=payload).json()
  15.  
  16. # ensure the request was successful
  17. if r["success"]:
  18.     # loop over the predictions and display them
  19.     for (i, result) in enumerate(r["predictions"]):
  20.         print("{}. {}: {:.4f}".format(i + 1, result["label"],
  21.             result["probability"]))
  22.  
  23. # otherwise, the request failed
  24. else:
  25.     print("Request failed")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement