forked from cwetherill-ps/onnx-deployment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprediction-client.py
44 lines (35 loc) · 871 Bytes
/
prediction-client.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
37
38
39
40
41
42
43
44
#!?usr/bin/env python3
import tensorflow as tf
import numpy as np
import requests
import json
import sys
fashion_mnist = tf.keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()
train_images = train_images / 255.0
test_images = test_images / 255.0
data = {
'signature_name': 'serving_default',
'instances': {
'image_data': test_images[:5].tolist()
}
}
predictions = requests.post(
f'{sys.argv[1]}/v1/models/fashion-mnist:predict',
json=data
)
predictions = json.loads(predictions.text)[0]
class_names = [
'T-shirt/top',
'Trouser',
'Pullover',
'Dress',
'Coat',
'Sandal',
'Shirt',
'Sneaker',
'Bag',
'Ankle boot'
]
print(f'Predicted class: {class_names[np.argmax(predictions[0])]}')
print(f'Actual class: {class_names[test_labels[0]]}')