ML引擎预测出现错误,但本地预测工作正常



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

我在本地机器上运行TensorFlow 1.3(通过MacOS上的PiP安装(,并使用提供的"ssd_mobilenet_v1_coco"检查点创建了一个模型。

我设法在本地和ML引擎(Runtime 1.2(上进行了训练,并成功地将我的savedModel部署到了ML引擎中。

本地预测(下面的代码(运行良好,我得到了模型结果

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)nt [[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

关于"数据格式"参数的问题。但不幸的是,我无法使用该解决方案,因为我已经使用了TensorFlow 1.3。

MobilenetV1似乎也有问题:https://github.com/tensorflow/models/sissues/2153

有什么想法吗?

我也遇到了类似的问题。这个问题是由于用于训练和推理的Tensorflow版本不匹配。我通过使用Tensorflow-1.4进行训练和推理来解决这个问题。

请参考这个答案。

如果您想知道如何确保您的模型版本运行所需的正确tensorflow版本,请首先查看此模型版本列表页面

您需要知道哪个型号版本支持您需要的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。

请参阅此MNIST官方教程页面,以及此ML版本控制页面

最新更新