【问题标题】:Encoding issues with cloud mlcloud ml 的编码问题
【发布时间】: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


【解决方案1】:

问题在于图形的导出方式,在调用脚本 export_inference_graph.py 时添加标志 --input_type 非常重要,否则 API 模型的输入是 UINT8 而不是字符串。

--input_type encoded_image_string_tensor

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-05
    • 1970-01-01
    • 1970-01-01
    • 2019-01-09
    • 2017-08-03
    • 2019-07-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多