Google ML 引擎上的批量预测抛出异常。
我在 Google 机器学习引擎上有一个 tensorflow 模型。我的模型对图像进行推断。虽然输入不是普通数组。该模型只接受图像的 b64 编码字符串。
我的输入是托管在 Google Cloud Platform 存储桶中的文本文件。 该文件如下所示:
{"image": "b64 encoded image string", "key": "0"}
{"image": "b64 encoded image string", "key": "1"}
{"image": "b64 encoded image string", "key": "2"}
输出应该是对所有图像的影响,但我得到以下异常:
('Exception during running the graph: Expected image (JPEG, PNG, or GIF), got unknown format starting with \'{\\"image\\": \\"/9j/4\'\n\t [[node encoder/map/while/DecodeJpeg (defined at /usr/local/lib/python2.7/dist-packages/google/cloud/ml/prediction/frameworks/tf_prediction_lib.py:210) ]]', 1)
请您参考如下方法:
如果您的模型“只接受图像的 b64 编码字符串”,这意味着签名有一个输入张量且其数据类型为字符串,那么 ML Engine 会将输入文件的每一行直接输入到单个字符串输入张量中。在这种情况下,没有完成 JSON/b64 解码,因此您的模型将获得整行作为输入。
如果您的模型属于这种情况,那么您可以通过向模型添加一个新操作来处理输入中的“键”字段来解决异常。
