我设法使用此 tutorial 之后的通用初始模型重新训练我的特定分类模型.我现在想在这个 steps 之后将它部署在谷歌云机器学习上.
我已经设法将其导出为 MetaGraph,但无法获得正确的输入和输出。
在本地使用它,我的图形入口点是 DecodeJpeg/contents:0
,它以二进制格式提供 jpeg 图像。输出是我的预测。
我在本地使用(有效)的代码是:
softmax_tensor = sess.graph.get_tensor_by_name('final_result:0')
predictions = sess.run(softmax_tensor,{'DecodeJpeg/contents:0': image_data})
输入张量应该是DecodeJpeg
吗?如果我想将 base64 图像
作为输入,我需要做哪些更改?
我将输出定义为:
outputs = {'prediction':softmax_tensor.name}
非常感谢任何帮助。
最佳答案
在您的示例中,输入张量是“DecodeJpeg/contents:0”,因此您会得到如下内容:
inputs = {'image': 'DecodeJpeg/contents:0')
outputs = {'prediction': 'final_result:0')
(请务必遵循 preparing 模型的所有说明)。
您要导出的模型目录应该包含如下文件:
gs://my_bucket/path/to/model/export.meta
gs://my_bucket/path/to/model/checkpoint*
部署模型时,请务必将 gs://my_bucket/path/to/model
设置为 deployment_uri
。
如您所建议的,要将图像发送到服务,您需要对图像字节进行 base64 编码。您的请求正文应如下所示(注意“标签”、“b64”,表示数据是 base-64 编码的):
{'instances': [{'b64': base64.b64encode(image)}]}
关于tensorflow - 在谷歌云机器学习上部署 Retrained inception 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39978526/