我正在尝试使用REST API从mnist服务器中提取图像,类似于在以下网站的示例部分中使用数字example(半加两个)完成操作。
简而言之:我正在尝试使用REST取代从mnist服务器提取图像的gRPC方法。
答案 0 :(得分:-1)
用于拉出/推断MNIST图像的代码如下所示:
!pip install -q requests
import requests
import json
headers = {"content-type": "application/json"}
json_response = requests.post('http://localhost:8501/v1/models/fashion_model/versions/1:predict', data=data, headers=headers)
predictions = json.loads(json_response.text)['predictions']
for i in range(0,3):
show(i, 'The model thought this was a {} (class {}), and it was actually a {} (class {})'.format(
class_names[np.argmax(predictions[i])], test_labels[i], class_names[np.argmax(predictions[i])], test_labels[i]))
以下链接https://www.tensorflow.org/tfx/tutorials/serving/rest_simple#import_the_fashion_mnist_dataset
中提供了使用REST API从MNIST服务器(时尚MNIST)提取图像的教程。如果上面提供的链接有任何问题,您可以导航到
Tensorflow.org网站->学习->用于生产->教程->服务->使用REST训练和提供模型。