【发布时间】:2018-11-02 07:04:56
【问题描述】:
我正在运行 tutorial 中生成的代码,当我尝试使用包含我的 b64 编码图片的 JSON 进行在线预测时,我收到消息,它期望 uint8 并得到一个十六进制字符串. 我已经检查了 JSON,它的格式没问题。可能是什么问题?
我使用 google 的 CLI 进行预测,我的模型版本是 tensorflow 1.10 以及我的运行时版本。我使用了 tf API 和 fast-rcnn 进行对象检测
将图像转换为 b64 和 JSON 和 tfrecord 的代码
import base64
import io
import json
from PIL import Image
import tensorflow as tf
width = 1024
height = 768
predict_instance_json = "inputs.json"
predict_instance_tfr = "inputs.tfr"
with tf.python_io.TFRecordWriter(predict_instance_tfr) as tfr_writer:
with open(predict_instance_json, "wb") as fp:
for image in ["image1.jpg", "image2.jpg"]:
img = Image.open(image)
img = img.resize((width, height), Image.ANTIALIAS)
output_str = io.BytesIO()
img.save(output_str, "JPEG")
fp.write(
json.dumps({"b64": base64.b64encode(output_str.getvalue())}) + "\n")
tfr_writer.write(output_str.getvalue())
output_str.close()
预测命令:
gcloud ml-engine predict --model=${YOUR_MODEL} --version=${YOUR_VERSION} --json-instances=inputs.json
我已经在本地测试了我的模型并创建了一个带有 tensorflow 服务的 docker 容器,它运行良好,但在 cloud ml 上没有成功。
错误提示:
"error": "Prediction failed: Error processing input: Expected uint8, got '\\xff\\xd8\\...
\\xff\\xd9' of type 'str' instead."
【问题讨论】:
-
请给出完整的回溯
-
不是评论;请编辑原始问题以包含它,格式正确
标签: python tensorflow google-cloud-ml