运行 在 Google ML 上导出 Inception:预期的 float32 得到了 'str'

Running exported Inception on Google ML: Expected float32 got 'str'

我使用 retrain.py 示例和 --saved_model_dir 标志重新训练了 Inception 模型以导出模型以供最终使用。

我成功地将最终模型上传到 Google ML 引擎,现在我正尝试从中 运行 进行预测。

我的请求是这样的:

{"image": {"b64": "/9j/4AAQxh6AP/2Q== ..."}}

但我收到一条错误消息:

{"error": "Prediction failed: Error processing input: Expected float32, got '\xff\xd8\xff\xe0 ...' of type 'str' instead."}

retrain.py中的导出示例是否没有导出模型以用于Google ML Engine?

错误消息表明导出的模型需要浮点数组而不是原始图像字节。我追踪代码以确认这一点。具体来说,export_model calls build_eval_session to get the resized_input_tensor which is created in create_module_graph as follows (link):

resized_input_tensor = tf.placeholder(tf.float32, [None, height, width, 3])

因此,数据应类似于:

{
  "image": [
    [
      [0.0, 0.0, 0.0],
        # ... (num entries = height)
    ],
    # (num entries = width)
  ]
}

当然,这是一种相当低效的图像编码方式(浮动为 ASCII)。如果预期的图像尺寸很小(通常为 200 x 200),这并不可怕。如果示例的作者允许通过调用 add_jpeg_decoding 作为模型的入口点来导出模型,那会更好,这将允许您发送当前正在尝试发送的数据.