【问题标题】:Running exported Inception on Google ML: Expected float32 got 'str'在 Google ML 上运行导出的 Inception:预期 float32 得到“str”
【发布时间】:2018-07-25 10:23:58
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2021-10-14
      • 2019-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-11
      • 2022-01-05
      相关资源
      最近更新 更多