简体   繁体   中英

error PlaceholderWithDefault when converting Tensorflow model to CoreML model

I am trying to convert a tensorflow model i trained with tensorflow for poets to a CoreML model so i can run it on my iphone. But when i tried to convert it using this python script:

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)

It gives me this error:

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

I am using a mac with MacOS Sierra.

Hope someone can help.

Greetings Sieuwe

EDIT:

I eventually got it working. I am not 100% sure what fixed it but it was probably something to do with that i hve 2 python versions. I did was:

Uninstalling tensorflow and tfcoreml from pip and from pip3. Installing tfcoreml and tensorflow with pip not pip3 Uninstalling and installing numpy with pip(this gave me some errors while doing but got it eventually uninstalled)

If it still wont work mayby try to build tfcoreml and tensorflow from source.

I haven't used tfcoreml yet, but the error "Unsupported Ops of type: PlaceholderWithDefault" means that your TF graph uses an operation that is not supported by the converter.

If you look at the list of supported ops at https://github.com/tf-coreml/tf-coreml you'll see that Placeholder is supported but not PlaceholderWithDefault.

In the TensorFlow for Poets 2 tutorial there is a step that lets you optimize the model for mobile. I'm not 100% sure but this might replace the PlaceholderWithDefault with a regular Placeholder. It's worth doing anyway. :-)

i see that you've submitted a github ticket: https://github.com/tf-coreml/tf-coreml/issues/99 for this issue as well... i had the same issue you saw, but by following the responder's advice and got it to work. can you update your answer if that helped?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM