如何对cloud-ml中的jpeg图像做出正确的预测 [英] how make correct predictions of jpeg image in cloud-ml

查看:54
本文介绍了如何对cloud-ml中的jpeg图像做出正确的预测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想预测cloud-ml中的jpeg图像.

I want to predict a jpeg image in cloud-ml.

我的训练模型是初始模型,我想将输入发送到图的第一层:'DecodeJpeg/contents:0'(必须在其中发送jpeg图像).我通过添加 retrain来将这一层设置为可能的输入.py :

My training model is the inception model, and I would like to send the input to the first layer of the graph: 'DecodeJpeg/contents:0' (where I have to send a jpeg image). I have set this layer as possible input by adding in retrain.py:

inputs = {'image_bytes': 'DecodeJpeg/contents:0'}
tf.add_to_collection('inputs', json.dumps(inputs))

然后,我将训练结果保存在两个文件中(export和export.meta),

Then I save the results of the training in two files (export and export.meta) with:

saver.save(sess, os.path.join(output_directory,'export'))

,然后我使用这些文件在cloud-ml中创建一个模型.

and I create a model in cloud-ml using these files.

如某些帖子中所建议(这里这里,以及

As suggested in some posts (here, here, and here from Google cloud official blog) I'm trying to make the prediction with

gcloud beta ml predict --json-instances=request.json --model=MODEL

其中实例是使用以下格式以base64格式解码的jpeg图像:

where the instance is the jpeg image decoded in base64 format with:

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

但是,请求返回了我

error: 'Prediction failed: '

我的程序有什么问题?你有什么建议吗? 我特别从发布后,我假设cloud-ml在读取带有image_bytes的请求时会自动将jpeg格式的base64图像转换为.这是正确的吗?否则我该怎么办?

What is the problem of my procedure? Do you have any suggestion? I particular from this post I assume that cloud-ml automatically convert the base64 image in jpeg format when it reads a request with image_bytes. Is it correct? Otherwise how can I do?

推荐答案

在您的文章中,您指出输入集合仅具有"image_bytes"张量别名.但是,在构成请求的代码中,您包括2个输入:一个是键",另一个是"image_bytes".因此,我的建议是从请求中删除键"或在输入集合中添加键".

In your post, you indicated that your inputs collection has only "image_bytes" tensor alias. However, in the code where you are framing the request, you are including 2 inputs: One is "key" and the other is "image_bytes". So, my suggestion would be to remove "key" from the request or add "key" to the inputs collection.

第二个问题是DecodeJpeg/contents:0'的形状为().对于Cloud ML,您需要具有类似(None,)的形状,以便可以将其输入.

Second issue is that the shape of DecodeJpeg/contents:0', is (). For Cloud ML, you need to have a shape like (None, ) so that you can feed that in.

您在此问题的其他答案中有一些建议,关于您如何能够按照公开帖子来修改图形,但是在手边我可以告诉这两个问题.

There are some suggestions in other answers to your question here, on how you might be able to follow the public posts to modify your graph, but at hand I can tell these two issues.

如果您遇到任何其他问题,请告知我们.

Let us know if you encounter any further issues.

这篇关于如何对cloud-ml中的jpeg图像做出正确的预测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆