关于算法:Deploy-a-trained-model

1次阅读

共计 830 个字符,预计需要花费 3 分钟才能阅读完成。

本次教程的目标是率领大家学会用 Tensorflow serving 部署训练好的模型

这里咱们用到的数据集是 Fashion MNIST,所以训练进去的模型能够实现以下几个类别的分类

'T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat',
               'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot'

因为这篇教程次要关注部署,所以咱们间接从曾经训练好的模型开始,保留的格局是 SavedModel,如上图所示

在这之前呢,咱们须要先装置好 tensorflow_model_server

接下来咱们能够在控制台执行以下指令,就能够启动一个 serving 服务了,咱们能够通过 REST API 进行申请,并返回预测后果

import requests
headers = {"content-type": "application/json"}
json_response = requests.post('http://localhost:8501/v1/models/fashion_mnist:predict', data=data, headers=headers)

predictions = json.loads(json_response.text)["predictions"]

show(0, "The model thought this was a {} (class {}), and it was actually a {} (class {})".format(class_names[np.argmax(predictions[0])], np.argmax(predictions[0]), class_names[test_labels[0]], test_labels[0]))

上图是通过申请,而后预测失去的后果,到此,咱们实现了模型的 Tensorflow serving 的部署

代码链接: https://codechina.csdn.net/cs…

正文完
 0