"预测失败:模型执行期间出错:无法将字节解码为JPEG,PNG,GIF或BMP"

时间:2018-03-22 23:16:33

标签: python tensorflow keras tensorflow-serving google-cloud-ml

我在gcloud ml-engine上部署了一个keras模型,但在尝试在线预测时收到了上述错误。

我通过关注@Chase Midler的示例代码from here(这是Hayato Yoshikawa的示例代码from here的改编版来保存和部署。但是,它抱怨没有preprocess_image函数存在。我认为这是一个自定义函数,用于在将图像传递给模型之前想要对图像做什么;这是正确的吗?因此,我只是评论了这一行。

我继续将保存的模型部署到gcloud ml引擎并尝试在线预测。不幸的是我收到了以下#34;无法解码字节为JPEG,PNG,GIF或BMP"错误:

{
  "error": "Prediction failed: Error during model execution: 
AbortionError(code=StatusCode.INVALID_ARGUMENT, details=
\"assertion failed: [Unable to decode bytes as JPEG, PNG, GIF, or BMP]\n\t
 [[Node: import/decode_image/cond_jpeg/cond_png/cond_gif/Assert_1/
Assert = Assert[T=[DT_STRING], summarize=3, _device=
\"/job:localhost/replica:0/task:0/device:CPU:0\"](import/decode_image/cond_jpeg/
cond_png/cond_gif/is_bmp, import/decode_image/cond_jpeg/cond_png/
cond_gif/Assert_1/Assert/data_0)]]\")"
}

问题是什么?

1 个答案:

答案 0 :(得分:1)

问题得到解决。我用于测试的json请求是问题所在。我在Python中手动生成了它,然后我将它发送给Chase Midler,后者发现他在我的json请求中遇到了类似的问题。我用以下代码纠正了它。

python -c 'import base64, sys, json; img = base64.b64encode(open(sys.argv[1], "rb").read()); print json.dumps({"image_bytes": {"b64": img}}) ' dog.jpg &> shepherd_dog.json`