Skip to content

Instantly share code, notes, and snippets.

@dipanjanS
Created September 20, 2019 11:03
Show Gist options
  • Select an option

  • Save dipanjanS/0f4134764abff749723c1f97b29e28ab to your computer and use it in GitHub Desktop.

Select an option

Save dipanjanS/0f4134764abff749723c1f97b29e28ab to your computer and use it in GitHub Desktop.
# create serving function
def predict_apparel_model2_serving(img, img_dims=(32,32), label_map=class_names):
sample_img_processed = (np.array([resize_image_array(img,
img_size_dims=img_dims)
for img in np.stack([[img]]*3,
axis=-1)])) / 255.
data = json.dumps({"signature_name": "serving_default",
"instances": sample_img_processed.tolist()})
HEADERS = {'content-type': 'application/json'}
MODEL2_API_URL = 'http://localhost:8501/v1/models/fashion_model_serving/versions/2:predict'
json_response = requests.post(MODEL2_API_URL, data=data, headers=HEADERS)
prediction = json.loads(json_response.text)['predictions']
prediction = np.argmax(np.array(prediction), axis=1)[0]
return label_map[prediction]
# benchmark 10K requests
%%time
pred_labels = []
for img in tqdm(test_images):
pred_label = predict_apparel_model2_serving(img)
pred_labels.append(img)
len(pred_labels)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment