在ML-Engine上获得错误预测,但本地预测工作正常

时间:2017-08-30 06:24:52

标签: tensorflow google-prediction

我在这里搜索了很多,但遗憾的是找不到答案。

我正在本地计算机上运行TensorFlow 1.3(通过MacOS上的PiP安装),并使用providedssd_mobilenet_v1_coco”检查点创建了一个模型。

我设法在本地和ML-Engine(Runtime 1.2)上进行训练,并成功将我的savedModel部署到ML-Engine。

本地预测(代码下方)工作正常,我得到模型结果

gcloud ml-engine local predict --model-dir=... --json-instances=request.json

 FILE request.json: {"inputs": [[[242, 240, 239], [242, 240, 239], [242, 240, 239], [242, 240, 239], [242, 240, 23]]]}

但是,在部署模型并尝试使用以下代码在ML-ENGINE上运行远程预测时:

gcloud ml-engine predict --model "testModel" --json-instances request.json(SAME JSON FILE AS BEFORE)

我收到此错误:

{
  "error": "Prediction failed: Exception during model execution: AbortionError(code=StatusCode.INVALID_ARGUMENT, details=\"NodeDef mentions attr 'data_format' not in Op<name=DepthwiseConv2dNative; signature=input:T, filter:T -> output:T; attr=T:type,allowed=[DT_FLOAT, DT_DOUBLE]; attr=strides:list(int); attr=padding:string,allowed=[\"SAME\", \"VALID\"]>; NodeDef: FeatureExtractor/MobilenetV1/MobilenetV1/Conv2d_1_depthwise/depthwise = DepthwiseConv2dNative[T=DT_FLOAT, _output_shapes=[[-1,150,150,32]], data_format=\"NHWC\", padding=\"SAME\", strides=[1, 1, 1, 1], _device=\"/job:localhost/replica:0/task:0/cpu:0\"](FeatureExtractor/MobilenetV1/MobilenetV1/Conv2d_0/Relu6, FeatureExtractor/MobilenetV1/Conv2d_1_depthwise/depthwise_weights/read)\n\t [[Node: FeatureExtractor/MobilenetV1/MobilenetV1/Conv2d_1_depthwise/depthwise = DepthwiseConv2dNative[T=DT_FLOAT, _output_shapes=[[-1,150,150,32]], data_format=\"NHWC\", padding=\"SAME\", strides=[1, 1, 1, 1], _device=\"/job:localhost/replica:0/task:0/cpu:0\"](FeatureExtractor/MobilenetV1/MobilenetV1/Conv2d_0/Relu6, FeatureExtractor/MobilenetV1/Conv2d_1_depthwise/depthwise_weights/read)]]\")"
}

我在这里看到了类似的内容:https://github.com/tensorflow/models/issues/1581

关于“data-format”参数的问题。 但不幸的是,由于我已经在TensorFlow 1.3上,我无法使用该解决方案。

它似乎也可能是MobilenetV1的一个问题:https:// github.com/ tensorflow / models / issues / 2153

有什么想法吗?

2 个答案:

答案 0 :(得分:3)

我有一个类似的issue。此问题是由于用于训练和推理的Tensorflow版本不匹配所致。我通过使用Tensorflow - 1.4来解决这个问题,用于训练和推理。

请参阅this回答。

答案 1 :(得分:2)

如果您想知道如何确保您的模型版本正在运行您需要运行的正确张量流版本,请先查看此model versions list page

您需要知道哪个型号版本支持您需要的Tensorflow版本。在撰写本文时:

  • ML 1.4版支持TensorFlow 1.4.0和1.4.1
  • ML 1.2版支持TensorFlow 1.2.0和
  • ML版本1.0支持TensorFlow 1.0.1

现在您知道需要哪个型号版本,您需要从模型中创建一个新版本,如下所示:

gcloud ml-engine versions create <version name> \
--model=<Name of the model> \
--origin=<Model bucket link. It starts with gs://...> \
--runtime-version=1.4

在我的情况下,我需要预测使用Tensorflow 1.4.1,所以我使用了运行时版本1.4。

请参阅此official MNIST tutorial page以及此ML Versioning Page

相关问题