Created
September 20, 2019 10:11
-
-
Save dipanjanS/8fdffe1ac17847fcbfa9042de19d1b85 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# get some sample data | |
sample_test_data = test_images[580:590] | |
sample_test_labels = test_labels[580:590] | |
# pre-process data | |
IMG_DIMS = (32, 32) | |
sample_test_data_processed = (np.array([resize_image_array(img, | |
img_size_dims=IMG_DIMS) | |
for img in np.stack([sample_test_data]*3, | |
axis=-1)])) / 255. | |
# create payload | |
data = json.dumps({"signature_name": "serving_default", | |
"instances": sample_test_data_processed.tolist()}) | |
HEADERS = {'content-type': 'application/json'} | |
MODEL2_API_URL = 'http://localhost:8501/v1/models/fashion_model_serving/versions/2:predict' | |
# inference request | |
json_response = requests.post(MODEL2_API_URL, data=data, headers=HEADERS) | |
# view server response | |
predictions = json.loads(json_response.text)['predictions'] | |
predictions = np.argmax(np.array(predictions), axis=1) | |
prediction_labels = [class_names[p] for p in predictions] | |
fig, ax = plt.subplots(2, 5, figsize=(14, 6)) | |
for idx, img in enumerate(sample_test_data): | |
rowidx = idx // 5 | |
colidx = idx % 5 | |
ax[rowidx, colidx].imshow(img) | |
ax[rowidx, colidx].set_title('Actual: {}\nPredicted: {}'.format(class_names[sample_test_labels[idx]], | |
prediction_labels[idx]), fontsize=10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment