-
Notifications
You must be signed in to change notification settings - Fork 2
/
callTFModel.py
36 lines (27 loc) · 916 Bytes
/
callTFModel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import PIL.Image
from PIL import ImageDraw
import numpy
import requests
from pprint import pprint
import time
import json
import sys
imagePath = str(sys.argv[1])
threshold=0.95
timeTheashold = 2.5
image = PIL.Image.open(imagePath)
image_np = numpy.array(image)
draw = ImageDraw.Draw(image)
payload = {"instances": [image_np.tolist()]}
start = time.time()
res = requests.post("<Model_Server_IP_Address>:8501/v1/models/saved_model:predict", json=payload)
processTime = time.time()-start
jsonStr= json.dumps(res.json())
jsonDict = json.loads(jsonStr)
predScore = jsonDict['predictions'][0]['detection_scores'][0]
if((predScore >= threshold) and (timeTheashold >= processTime)):
response = {"response":"B2Found","confidence": predScore , "duration": processTime }
else:
response = {"response":"B2NotFound","confidence":predScore,"duration":processTime}
jsonresponse = json.dumps(response)
print(jsonresponse)