将Tensorflow模型转换为CoreML模型时出现错误PlaceholderWithDefault

时间:2018-01-04 19:02:44

标签: python ios tensorflow deep-learning coreml

我正在尝试将使用tensorflow训练的张量流模型转换为CoreML模型,以便我可以在我的iphone上运行它。但是当我尝试使用这个python脚本转换它时:

import tfcoreml as tf_converter

tf_model_path = 'retrained_graph.pb'
mlmodel_path = 'mobilenet_v1_1.0_224.mlmodel'

mlmodel = tf_converter.convert(
                                   tf_model_path = tf_model_path,
                                   mlmodel_path = mlmodel_path,
                                   output_feature_names = ['MobilenetV1/Predictions/Softmax:0'],
                                   input_name_shape_dict = {'input:0':[1,224,224,3]},
                                   image_input_names = ['input:0'],
                                   red_bias = -1,
                                   green_bias = -1,
                                   blue_bias = -1,
                                   image_scale = 2.0/255.0)

它给了我这个错误:

dyld: warning, LC_RPATH $ORIGIN/../../_solib_darwin_x86_64/_U_S_Stensorflow_Spython_C_Upywrap_Utensorflow_Uinternal.so___Utensorflow in /Library/Python/2.7/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so being ignored in restricted program because it is a relative path
2018-01-04 19:47:30.977648: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.2 AVX
Traceback (most recent call last):
  File "co.py", line 15, in <module>
    image_scale = 2.0/255.0)
  File "/Library/Python/2.7/site-packages/tfcoreml/_tf_coreml_converter.py", line 478, in convert
    predicted_probabilities_output=predicted_probabilities_output)
  File "/Library/Python/2.7/site-packages/tfcoreml/_tf_coreml_converter.py", line 143, in _convert_pb_to_mlmodel
    _check_unsupported_ops(OPS, output_feature_names)
  File "/Library/Python/2.7/site-packages/tfcoreml/_tf_coreml_converter.py", line 111, in _check_unsupported_ops
    ','.join(unsupported_op_types)))
NotImplementedError: Unsupported Ops of type: PlaceholderWithDefault

我正在使用Mac OS Sierra的Mac。

希望有人可以提供帮助。

问候Sieuwe

编辑:

我最终得到了它的工作。我不是100%肯定是什么修复它但它可能与我有2个python版本。我做的是:

从pip和pip3卸载tensorflow和tfcoreml。 用pip而不是pip3安装tfcoreml和tensorflow 使用pip卸载和安装numpy(这样做会给我带来一些错误,但最终会卸载它)

如果它仍然无法工作,可以尝试从源代码构建tfcoreml和tensorflow。

2 个答案:

答案 0 :(得分:0)

我还没有使用过tfcoreml,但是错误&#34;不支持的Ops类型:PlaceholderWithDefault&#34;表示您的TF图使用转换器不支持的操作。

如果您查看https://github.com/tf-coreml/tf-coreml支持的操作列表,您会看到Placeholder受支持,但不支持PlaceholderWithDefault。

在TensorFlow for Poets 2教程中,有一个步骤可让您优化移动模型。我不是100%肯定,但这可能会用常规占位符替换PlaceholderWithDefault。无论如何,它值得做。 : - )

答案 1 :(得分:0)

我发现你已经为这个问题提交了一张github票:https://github.com/tf-coreml/tf-coreml/issues/99 ...我遇到了同样的问题,但是按照响应者的建议得到了它上班。如果有帮助,你能更新你的答案吗?