如何使用tensorflow-serving使用我自己的自定义函数导出模型?

问题描述 投票:0回答:1

当使用tensorflow-serving导出我的模型时,我有一个新的要求,如果我只需要知道输入图像上的数字而不是用大测试数据测试这个模型怎么办?我该怎么做才能实现这一点,或者不可能做到这一点?任何建议将不胜感激,谢谢!

tensorflow tensorflow-serving
1个回答
0
投票

如果我正确理解了您的问题,在保存训练模型后,您不想在测试数据上运行模型,而是希望在单个实例上使用推理进行预测。

如果我的理解是正确的,是的,这是可能的。请查找以下代码段以进行推断。

pip install -q requests

import requests

headers = {"content-type": "application/json"}

json_response = requests.post('http://localhost:8501/v1/models/fashion_model: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])], test_labels[0], class_names[np.argmax(predictions[0])], test_labels[0]))

有关更多详细信息,请参阅链接https://www.tensorflow.org/tfx/tutorials/serving/rest_simple#make_rest_requests

© www.soinside.com 2019 - 2024. All rights reserved.