Created
September 28, 2020 07:57
-
-
Save CleanPegasus/3a2491d6cdddf21dcfa0c7e98bdcf344 to your computer and use it in GitHub Desktop.
Get the prediction from the served model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
EMOTIONS = ["angry", "disgust", "scared", "happy", "sad", "surprised", "neutral"] # Emotions corresponding to the output | |
data = json.dumps({"signature_name": "serving_default", "instances": img.tolist()}) # making the input in the format required for serving | |
headers = {"content-type": "application/json"} # specifying that the input will be in json format | |
json_response = requests.post('http://localhost:8501/v1/models/emotion_model:predict', data=data, headers=headers) # post request to the served model | |
predictions = json.loads(json_response.text)['predictions'] # getting the predictions | |
label = EMOTIONS[predictions.index(max(predictions))] # Matching the prediction with it's correseponding label | |
print(label) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment