将带有图像的请求发送到 Tensorflow 服务器 API

时间:2021-01-27 09:13:10

标签: python tensorflow machine-learning object-detection

我正在研究一个身份证检测系统,实际上,我训练了模型,我想为这个模型提供服务器以便能够向它发送 API 请求,所以我遵循了这个教程 https://www.tensorflow.org/tfx/tutorials/serving/rest_simple 服务器现在正在工作,但我的问题是我需要将图像发送到该服务器,然后我希望它返回真/假结果,就好像该图像是否是身份证一样, 我怎样才能做到这一点? 这是我的 python 脚本,我想用图像向服务器发送请求

import json
import requests
data = json.dumps({"signature_name": "serving_default", "instances": "test_images/image1.png"})
print('Data: {} ... {}'.format(data[:50], data[len(data)-52:]))
IMAGE_NAME = 'test_images/image1.png'


headers = {"content-type": "application/json"}
json_response = requests.post('http://localhost:8501/v1/models/saved_model:predict', data=data, headers=headers)
predictions = json.loads(json_response.text)
print(predictions)

我不确定实例的含义,当然,我在尝试发送请求时收到此错误

<块引用>

{'error': 'JSON Value: {\n "signature_name": "serving_default",\n "instances": "test_images/image1.png"\n} 除了 'instances' 是一个列表/数组' }

模型已成功训练并加载到服务器,我的问题是如何使用模型检查图像是否为身份证

0 个答案:

没有答案