Google cloudml总是给我相同的结果 [英] Google cloudml Always Gives Me The Same Results

查看:88
本文介绍了Google cloudml总是给我相同的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究机器学习,我想使用Google Cloud ml服务.

I'm working on machine learning and I would like to use Google Cloud ml service.

此刻,我已经使用restor.py代码(Tensorflow)( https://cloud来预测新数据时. google.com/ml/reference/commandline/predict ):

At this moment, I have trained my model with retrain.py code of Tensorflow (https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/image_retraining/retrain.py#L103) and I have exported the results to a cloudml (export and export.meta files). However when I try to make a prediction of new data with command (https://cloud.google.com/ml/reference/commandline/predict):

gcloud beta ml predict

它总是返回相同的结果(我想预测不同的数据).怎么可能?

it always returns the same result (I want to predict different data). How is it possible?

我的数据是从jpeg解码的图像,其文本格式为:

My data are images that are decoded from jpeg in a text format with:

echo "{\"image_bytes\": {\"b64\": \"`base64 image.jpg`\"}}" > instances

您有什么建议吗?

推荐答案

此问题可能有多种原因.首先想到的是,导入模型时,模型中的权重可能会初始化为零.如果在图形中定义了初始化,则可能会发生这种情况(cf

There are multiple possible causes of this issue. The first that comes to mind is that the weights in your model may be being initialized to zero when it is imported. This can happen if there is an initialization defined in the graph (c.f. the loader). To check for this, use the following commands:

from tensorflow.contrib.session_bundle import session_bundle

session, _ = session_bundle.load_session_bundle_from_path("/path/to/model")
print(s.graph.get_collection("serving_init_op"))

如果该集合中有内容,请确保它没有初始化变量.

If there is something in that collection, make sure that it isn't initializing variables.

如果没有初始化程序,请确保权重本身看起来合理,例如,

If there are no initializers, make sure the weights themselves look reasonable, e.g.,

session, _ = session_bundle.load_session_bundle_from_path("/path/to/model")
print(session.run("name_of_var:0"))

如果所有这些都检出,那么您可能要在转换这些输入后注意图形的输入和输出.为此,可以使用session.run来运行图形的各个部分.例如,您可以在调用session.run时使用适当的提要和提取来提供jpeg字符串并查看此过程中各个步骤的输出.

If all of that checks out, then you'll probably want to pay attention to the inputs to the graph and the output after transforming those inputs. To this end, you can use session.run to run parts of the graph. For instance, you can feed a jpeg string and view the output of various steps along the way by using the appropriate feeds and fetches in a call to session.run.

例如,使用

For example, using the example from this post, we can load a JPEG from disk, feed it to the graph, and see what the data looks like after resizing and after scaling:

INPUT_PLACEHOLDER = 'Placeholder:0'
DECODE_AND_RESIZE = 'map/TensorArrayPack_1/TensorArrayGather:0'
SCALED = 'Mul:0'

# Read in a sample image, preferably with small dimensions.
jpg = open("/tmp/testing22222.jpg", "rb").read()

session, _ = session_bundle.load_session_bundle_from_path("/path/to/model")
resized, scaled = session.run([DECODE_AND_RESIZE, SCALED], feed_dict={INPUT_PLACEHOLDER: [jpg]})

通过策略性地将张量的名称放置在图的fetch列表中,您可以检查神经网络的任何给定层中发生的情况,尽管最可能的问题在于输入和/或变量.

By strategically placing the names of tensors in your graph in the fetch list, you can inspect what is going on in any given layer of the neural net, although the most likely problems reside with the inputs and/or variables.

棘手的部分是找出张量的名称.定义大多数操作时,可以使用name属性,这可能会有所帮助.您还可以使用类似的内容:

The tricky part is figuring out the names of tensors. You can use the name property when defining most operations, which might be helpful. You can also use something like:

 print([o.name for o in session.graph.get_operations()])

为帮助检查图中的操作.

To help inspect the operations in the graph.

最后,您可能还想尝试在本地运行图形,以最大程度地减少调试时的反馈周期.在示例中查看 local_predict.py 有关如何执行此操作的示例.这将帮助您快速迭代以识别模型本身的问题.

Finally, you may also want to try running the graph locally in order to minimize the feedback cycle while debugging. Check out local_predict.py in the samples for an example of how to do this. This will help you iterate quickly to identify issues with the model itself.

这篇关于Google cloudml总是给我相同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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