google-cloud-ml - ML-Engine 本地预测 - 无法运行模型
问题描述
gcloud ml-engine 本地预测失败
首先,我用Response确定了所需的input.json
结构:saved_model_cli show --all --dir saved_model/
MetaGraphDef with tag-set: 'serve' contains the following SignatureDefs:
signature_def['serving_default']:
The given SavedModel SignatureDef contains the following input(s):
inputs['inputs'] tensor_info:
dtype: DT_UINT8
shape: (-1, -1, -1, 3)
name: image_tensor:0
....
由此我将我input.json
的 for格式化gcloud ml-engine local predict
为:
{"inputs": {"b64": "ENCODED"}}
...
最后,我跑了gcloud ml-engine local predict --model-dir saved_model/ --json-instances=PATH-TO-INPUTS.json
回复:
ERROR: (gcloud.ml-engine.local.predict) /usr/local/lib/python2.7/dist-packages/requests/__init__.py:83:
2018-10-03 09:20:06.598090: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
ERROR:root:Exception during running the graph: invalid literal for long() with base 10: '\xff\xd8\xff\xdb'
Traceback (most recent call last):
File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/command_lib/ml_engine/local_predict.py", line 172, in <module>
main()
File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/command_lib/ml_engine/local_predict.py", line 167, in main
signature_name=args.signature_name)
File "/usr/lib/google-cloud-sdk/lib/third_party/ml_sdk/cloud/ml/prediction/prediction_lib.py", line 106, in local_predict
predictions = model.predict(instances, signature_name=signature_name)
File "/usr/lib/google-cloud-sdk/lib/third_party/ml_sdk/cloud/ml/prediction/prediction_utils.py", line 233, in predict
preprocessed, stats=stats, **kwargs)
File "/usr/lib/google-cloud-sdk/lib/third_party/ml_sdk/cloud/ml/prediction/frameworks/tf_prediction_lib.py", line 350, in predict
"Exception during running the graph: " + str(e))
cloud.ml.prediction.prediction_utils.PredictionError: Failed to run the provided model: Exception during running the graph: invalid literal for long() with base 10: '\xff\xd8\xff\xdb' (Error code: 2)
克服这个障碍的任何帮助都会很棒。到目前为止,我还无法从在线研究中找到解决方案。谢谢!
解决方案
中的数据input.json
与 的形状不匹配inputs['inputs']
。您没有提供有关各种尺寸代表什么的足够信息,但我怀疑这是图像的 NHWC(批量大小 x 高度 x 宽度 x 通道)编码。
我还怀疑这些应该是原始像素值。在这种情况下,您不应该对值进行 base64 编码,即,您应该像这样发送数据:
{"inputs": [[[0, 0, 0], ... [0, 0, 0]]]}
话虽如此,您应该考虑将图像作为字节字符串发送并在图中解码图像。可以在此处找到有关各种方法的更多信息:
https://stackoverflow.com/a/46222990/1399222
看来您正在使用“编码为 JSON 的原始张量”,我推荐“压缩图像数据”,或者稍微简单的“打包为字节字符串的张量”
推荐阅读
- sql - 如何将表组合为没有 id 或其他东西的列?
- python - 如何冻结Python pandas数据框中NaN之间序列中的第一个数字
- java - getRootFolder() 上的 CmisObjectNotFoundException
- css - 菜单按钮不起作用(wordpress 主题)
- javascript - 我有对象数组,然后我必须使用 mat 复选框
- react-native - 无法删除 Expo-cli
- php - 比较两个日期时间以检查日期是否有效 PHP
- search - 在 Alfresco 中按节点搜索文档
- javascript - 本地 node.js 应用程序在 localhost 上运行良好,但不能从外部访问
- c# - 如何检查 IUser 是否有昵称?