question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Converting DeepLabv3+ made in Tensorflow v2 beta 1

See original GitHub issue

Hi, I’m running this code to try to convert a frozen .pb model I’ve saved to a coreml model:

import tfcoreml as tf_converter
tf_converter.convert(tf_model_path = './archived models/DeepLabv3+_15_epochs/saved_model.pb',
                     mlmodel_path = './archived models/CoreML/DeepLabv3+_15_epochs.mlmodel',
                     output_feature_names = ['Output'],
                     use_coreml_3 = True)

This is my error:

---------------------------------------------------------------------------
DecodeError                               Traceback (most recent call last)
<ipython-input-3-45de1822b420> in <module>()
      3                      mlmodel_path = './archived models/CoreML/DeepLabv3+_15_epochs.mlmodel',
      4                      output_feature_names = ['Output'],
----> 5                      use_coreml_3 = True)

~/anaconda3/envs/Python3.5/lib/python3.5/site-packages/tfcoreml/_tf_coreml_converter.py in convert(tf_model_path, mlmodel_path, output_feature_names, input_name_shape_dict, image_input_names, is_bgr, red_bias, green_bias, blue_bias, gray_bias, image_scale, class_labels, predicted_feature_name, predicted_probabilities_output, add_custom_layers, custom_conversion_functions, use_coreml_3)
    592         tf_model_path,
    593         inputs=input_name_shape_dict,
--> 594         outputs=output_feature_names)
    595     if mlmodel_path is not None:
    596       mlmodel.save(mlmodel_path)

~/anaconda3/envs/Python3.5/lib/python3.5/site-packages/coremltools/converters/tensorflow/_tf_converter.py in convert(filename, inputs, outputs, **kwargs)
      9     try:
     10         from ..nnssa.frontend.tensorflow import load as frontend_load
---> 11         ssa = frontend_load(filename, **kwargs)
     12     except ImportError as err:
     13         raise ImportError("Frontend converter not found! Error message:\n%s" % err)

~/anaconda3/envs/Python3.5/lib/python3.5/site-packages/coremltools/converters/nnssa/frontend/tensorflow/load.py in load(tfgraph, resume_on_errors, **kwargs)
     35         gd = tfgraph
     36 
---> 37     ssa = graphdef_to_ssa(gd)
     38 
     39     placeholder_shape = kwargs.get("placeholder_shape", {})

~/anaconda3/envs/Python3.5/lib/python3.5/site-packages/coremltools/converters/nnssa/frontend/tensorflow/graphdef_to_ssa.py in graphdef_to_ssa(graphdef_or_file, main_method_name)
     36     """
     37     if isinstance(graphdef_or_file, (bytes, str)):
---> 38         gdorig, g = load_tf_graph(graphdef_or_file)
     39     else:
     40         gdorig = graphdef_or_file

~/anaconda3/envs/Python3.5/lib/python3.5/site-packages/coremltools/converters/nnssa/frontend/tensorflow/graphdef_to_ssa.py in load_tf_graph(graph_file)
     21     with tf.gfile.GFile(graph_file, "rb") as f:
     22         graph_def = tf.GraphDef()
---> 23         graph_def.ParseFromString(f.read())
     24 
     25     # Then, we import the graph_def into a new Graph and returns it

DecodeError: Error parsing message

I’ve tried saving the model two different ways, both using Tensorflow 2.0.0b1:

tf.keras.experimental.export_saved_model(model, "./archived models/DeepLabv3+_15_epochs", custom_objects={'relu6': relu6}) tf.keras.experimental.export_saved_model(model, "./archived models/DeepLabv3+_15_epochs", as_text=True, custom_objects={'relu6': relu6})

Note the additional attribute ‘as_text=True’ in the second example. When saving ‘as_text=True’, my conversion code is reading from .../saved_model.pbtxt instead of .../saved_model.pb.

When converting, I’ve been running my conversion code with CoreMLtools 3.0b1, TF-CoreML 0.4.0b1, and I’ve tried reading/converting with both Tensorflow 2.0.0b1 and Tensorflow 1.13.1.

I’ve tried a couple other things the past ~2-3 hours… I’m sort of forgetting all the little paths I’ve gone down.

=====

Most recently, using Tensorflow 1.13.1 and use_coreml_3 = False) in the convert function, I changed code in tf_coreml_converter.py to read the model differently, via the answer on this StackOverflow page by user anujonthemove.

That failed with this error: MetaGraphDef associated with tags could not be found in SavedModel. To inspect available tag-sets in the SavedModel, please use the SavedModel CLI: saved_model_cli``, as I passed in an empty list of tags, and tags=‘None’ didn’t work, either.

=====

Most of the things I’ve tried usually end with the saved model I’ve made not being read correctly and failing somewhere when loading.

Any ideas? Thanks so much.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:9

github_iconTop GitHub Comments

3reactions
Oktai15commented, Jul 1, 2019

@not-Ian if you convert your model in tf 2.0 to coreml, please, write here.

0reactions
Mstronachcommented, Nov 6, 2019

Experimental support for TensorFlow 2.x and tf.keras was added in coremltools 3.1 with some known issues, could you please try again with the latest version of coremltools 3.1 and/or tfcoreml 1.1. Please see the neural network conversion guide and/or Jupyter notebooks for some conversion examples. If you encounter any issues while converting your model, please file a new GitHub issue with steps to reproduce. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Training a machine learning model on your own dataset with ...
Use Tensorflow's Deeplab to segment humans from their backgrounds in a photo for the purpose of background replacement.
Read more >
(deeplabv3+) (mobilenetv2) training mobilenet_v2 on ... - GitHub
1.System information the top-level directory of the model ... is missing variable [MobilenetV2/Conv/BatchNorm/beta/Momentum] W0726 ...
Read more >
@tensorflow-models/deeplab - npm
To get started, pick the model name from pascal , cityscapes and ade20k , and decide whether you want your model quantized to...
Read more >
Semantic Segmentation using PyTorch DeepLabV3 ResNet50
Semantic segmentation on images and videos using PyTorch DeepLabV3 ResNet50 with the PyTorch Deep Learning framework.
Read more >
Image segmentation | TensorFlow Core
In addition, the image color values are normalized to the [0, 1] range. Finally, as mentioned above the pixels in the segmentation mask...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found