无法使用Conv3D在CPU上为保存的模型运行推理

时间:2019-12-03 11:09:34

标签: python tensorflow

我的处境很特殊。我已经收到一个saved_model.pb文件,并要求在CPU机器上对其进行推断。在其上运行saved_model_cli表明该模型具有以下结构:

MetaGraphDef with tag-set: 'serve' contains the following SignatureDefs:

signature_def['serving_default']:
  The given SavedModel SignatureDef contains the following input(s):
    inputs['image_bytes'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1, 1, 128, 128, 128)
        name: input_1:0
  The given SavedModel SignatureDef contains the following output(s):
    outputs['score_categories'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1, 5, 128, 128, 128)
        name: activation_1/Sigmoid:0
  Method name is: tensorflow/serving/predict

我使用Tensorflow 2.0使用以下脚本加载文件:

MODEL_PATH = 'phase_2_model/'
loaded = tf.saved_model.load(MODEL_PATH)
infer = loaded.signatures["serving_default"]

然后使用它来尝试进行推断:

labeling = infer(tf.constant(img))

其中img的形状为(1, 1, 128, 128, 128)

但是,在CPU上运行推理(不附加GPU)会抛出以下错误:

tensorflow.python.framework.errors_impl.InvalidArgumentError:  CPU implementation of Conv3D currently only supports the NHWC tensor format.
         [[node conv3d_1/Conv3D (defined at usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/ops.py:1751) ]] [Op:__inference_pruned_3347]

我发现此错误很奇怪,因为Conv3D操作应该以{{1​​}}接受输入,但是错误仍然希望输入为data_format='NDHWC'格式。

对于解决此错误的任何帮助,将不胜感激。

0 个答案:

没有答案