Created
September 20, 2019 10:02
-
-
Save dipanjanS/d8a51fa5de6c92331ea0ebb7609c0194 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 | |
| sample_test_data_processed = np.expand_dims(sample_test_data / 255., axis=3) | |
| # create payload | |
| data = json.dumps({"signature_name": "serving_default", | |
| "instances": sample_test_data_processed.tolist()}) | |
| HEADERS = {'content-type': 'application/json'} | |
| MODEL1_API_URL = 'http://localhost:8501/v1/models/fashion_model_serving/versions/1:predict' | |
| # inference request | |
| json_response = requests.post(MODEL1_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