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

时间:2018-07-25 10:23:58

标签: python tensorflow machine-learning google-cloud-ml

我使用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的模型?

1 个答案:

答案 0 :(得分:1)

错误消息表明导出的模型需要浮点数数组,而不是原始图像字节。我跟踪代码以确认这一点。具体来说,export_model调用build_eval_session来获取resized_input_tensor,它是在create_module_graph中创建的,如下所示(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作为模型的入口点来导出模型,这将允许您在当前尝试发送数据时发送数据。