我使用 slim 包resnet_v2_152
来训练分类模型。然后将其导出为 .pb 文件以提供服务。因为输入是图像,所以它将使用网络安全的 base64 编码进行编码。看起来像:
serialized_tf_example = tf.placeholder(dtype=tf.string, name='tf_example')
decoded = tf.decode_base64(serialized_tf_example)
然后我用 base64 对图像进行编码,这样:
img_path = '/Users/wuyanxue/Desktop/not_emoji1.jpeg'
img_b64 = base64.b64encode(open(img_path, 'rb').read())
s = str(img_b64, encoding='utf-8')
s = s.replace('+', '-').replace(r'/', '_')
我的发布数据结构如下:
post_data = {
'signature_name': 'predict',
'instances':[ {
'inputs':
{ 'b64': s }
}]
}
最后,我向该服务器发布一个 HTTP 请求:
res = requests.post('server_address', json=post_data)
它给了我:
'{ "error": "Failed to process element: 0 key: inputs of \\\'instances\\\' list. Error: Invalid argument: Unable to base64 decode" }'
我想知道怎么会遇到?是否有一些解决方案?