错误 占位符默认 将 Tensorflow 模型转换为 CoreML 模型时



我正在尝试将我用Tensorflow for Poets训练的张量流模型转换为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

我正在使用装有MacOS Sierra的Mac。

希望有人能帮忙。

问候谢威

编辑:

我最终让它工作了。我不是 100% 确定是什么修复了它,但这可能与我有 2 个 python 版本有关。我做的是:

从 pip 和 pip3 卸载 tensorflow 和 tfcoreml。使用 pip 而不是 pip3 安装 tfcoreml 和张量流使用 pip 卸载和安装 numpy(这在执行时给了我一些错误,但最终将其卸载(

如果它仍然不起作用,可以尝试从源代码构建tfcoreml和tensorflow。

我还没有使用 tfcoreml,但错误"不支持的类型操作:占位符与默认值"意味着您的 TF 图使用了转换器不支持的操作。

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

在 TensorFlow for Poets 2 教程中,有一个步骤可让您针对移动设备优化模型。我不是 100% 确定,但这可能会用常规占位符替换占位符与默认。无论如何,这是值得做的。:-(

我看到您已经提交了GitHub票证:https://github.com/tf-coreml/tf-coreml/issues/99 此问题也是如此...我遇到了您看到的相同问题,但是通过遵循响应者的建议并使其正常工作。如果有帮助,你能更新你的答案吗?

最新更新