# Convert TFLite Model Maker Object detection model to OpenVino

**URL:** <https://discuss.ai.google.dev/t/convert-tflite-model-maker-object-detection-model-to-openvino/25464>\
**Category:** General Discussion\
**Tags:** tflite, models, help\_request, model\_maker\
**Created:** [June 16, 2021, 9:43pm UTC](https://discuss.ai.google.dev/t/convert-tflite-model-maker-object-detection-model-to-openvino/25464 "2021-06-16T21:43:20Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gi\_T](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/gi_t/32/8488_2.png) [@Gi\_T](https://discuss.ai.google.dev/u/Gi_T)\
**Post date:** [June 16, 2021, 9:43pm UTC](https://discuss.ai.google.dev/t/convert-tflite-model-maker-object-detection-model-to-openvino/25464/1 "2021-06-16T21:43:20Z")

</div>

I was wondering how I can convert a Tensorflow Lite object detection model created with the TFLite Model Maker. I don’t think this is possible after exporting the model to Tensorflow Lite but it should work if the model is exported as a saved model.

Any help is greatly appreciated.

---

<div class="post-metadata">

**Author:** ![George](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/george/32/19412_2.png) [@George](https://discuss.ai.google.dev/u/George)\
**Post date:** [June 17, 2021, 3:29am UTC](https://discuss.ai.google.dev/t/convert-tflite-model-maker-object-detection-model-to-openvino/25464/2 "2021-06-17T03:29:08Z")

</div>

Hi @Gi_T

After training the model with `create()` method you can do:

```auto
serving_model = model.create_serving_model()

print(f'Model\'s input shape and type: {serving_model.inputs}')
print(f'Model\'s output shape and type: {serving_model.outputs}')

```

and then save it to saved model format as always:

```auto
saved_model_path = './object_model_maker'
serving_model.save(saved_model_path, include_optimizer=False)

```

Check a workflow [here](https://github.com/farmaker47/Yamnet_Speech_commands/blob/main/Model_Maker_Speech_commands.ipynb) with an audio classification example (it is still an ongoing project).

---

<div class="post-metadata">

**Author:** ![Sayak\_Paul](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/sayak_paul/32/13002_2.png) [@Sayak\_Paul](https://discuss.ai.google.dev/u/Sayak_Paul)\
**Post date:** [June 17, 2021, 3:59am UTC](https://discuss.ai.google.dev/t/convert-tflite-model-maker-object-detection-model-to-openvino/25464/3 "2021-06-17T03:59:10Z")

</div>

@George\_Soloupis’s workflow is the recommended one. As long as you can create a `SavedModel` for your OD network and ensure it’s supported in OpenVINO you should be good to go. However, I must mention that OpenVINO’s TensorFlow 2 support is still very experimental and limited. So you might want to keep that in mind.

---

<div class="post-metadata">

**Author:** ![Gi\_T](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/gi_t/32/8488_2.png) [@Gi\_T](https://discuss.ai.google.dev/u/Gi_T)\
**Post date:** [June 17, 2021, 4:38pm UTC](https://discuss.ai.google.dev/t/convert-tflite-model-maker-object-detection-model-to-openvino/25464/4 "2021-06-17T16:38:56Z")

</div>

Thanks for the replies. I tried the code suggested by @George\_Soloupis, but I couldn’t get the conversion to work. I’m currently getting the following error:

```auto
[FRAMEWORK ERROR] Cannot load input model: TensorFlow cannot read the model file: "/content/object_model_maker/saved_model.pb" is incorrect TensorFlow model file. 
The file should contain one of the following TensorFlow graphs:
1. frozen graph in text or binary format
2. inference graph for freezing with checkpoint (--input_checkpoint) in text or binary format
3. meta graph

Make sure that --input_model_is_text is provided for a model in text format. By default, a model is interpreted in binary format. Framework error details: Error parsing message. 
 For more information please refer to Model Optimizer FAQ, question #43. (https://docs.openvinotoolkit.org/latest/openvino_docs_MO_DG_prepare_model_Model_Optimizer_FAQ.html?question=43#question-43)

```

Unfortunately, it seems like I can’t embed any links, so I can’t share my current notebook with you, but after creating the saved model, I’m using the following code to convert the model:

```auto
output_dir = '/content/output'

!source /opt/intel/openvino_2021/bin/setupvars.sh && \
    python /opt/intel/openvino_2021/deployment_tools/model_optimizer/mo.py \
    --input_model /content/object_model_maker/saved_model.pb \
    --transformations_config /opt/intel/openvino_2021/deployment_tools/model_optimizer/extensions/front/tf/automl_efficientdet.json \
    --reverse_input_channels \
    --output_dir {output_dir} \

```

Any help is greatly appreciated.

---

<div class="post-metadata">

**Author:** ![George](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/george/32/19412_2.png) [@George](https://discuss.ai.google.dev/u/George)\
**Post date:** [June 18, 2021, 5:20am UTC](https://discuss.ai.google.dev/t/convert-tflite-model-maker-object-detection-model-to-openvino/25464/5 "2021-06-18T05:20:49Z")

</div>

It seems like even when someone saves the model maker ‘model’ in saved \_model format with the provided code [here](https://www.tensorflow.org/lite/tutorials/model_maker_object_detection):  
`model.export(export_dir='.', export_format=[ExportFormat.SAVED_MODEL, ExportFormat.LABEL])`  
and then tries to reload it like:  
`reloaded_model = tf.saved_model.load('./object_detection_model_maker_saved_model/saved_model) reloaded_model.summary()`

it throws an error. I have also checked it with the audioclassifier example.

I hope @Yuqi_Li can sed some light here.

---

<div class="post-metadata">

**Author:** ![Yuqi\_Li](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/yuqi_li/32/7251_2.png) [@Yuqi\_Li](https://discuss.ai.google.dev/u/Yuqi_Li)\
**Post date:** [June 18, 2021, 6:02am UTC](https://discuss.ai.google.dev/t/convert-tflite-model-maker-object-detection-model-to-openvino/25464/6 "2021-06-18T06:02:39Z")

</div>

Yes, please just use `model.export(export_dir='.', export_format=ExportFormat.SAVED_MODEL)` to export as saved\_model.

---

<div class="post-metadata">

**Author:** ![Gi\_T](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/gi_t/32/8488_2.png) [@Gi\_T](https://discuss.ai.google.dev/u/Gi_T)\
**Post date:** [June 18, 2021, 7:37am UTC](https://discuss.ai.google.dev/t/convert-tflite-model-maker-object-detection-model-to-openvino/25464/7 "2021-06-18T07:37:38Z")

</div>

I now used ` model.export(export_dir='.', export_format=ExportFormat.SAVED_MODEL)` as suggested but when running

```auto
reloaded_model = tf.saved_model.load('/content/saved_model') 
reloaded_model.summary()

```

I’m getting the following error:

```auto
AttributeError Traceback (most recent call last)
<ipython-input-13-38f2d2297174> in <module>()
      1 reloaded_model = tf.saved_model.load('/content/saved_model')
----> 2 reloaded_model.summary()

AttributeError: '_UserObject' object has no attribute 'summary'

```

Also, while trying to convert the model to OpenVino:

```auto
output_dir = '/content/output'

!source /opt/intel/openvino_2021/bin/setupvars.sh && \
    python /opt/intel/openvino_2021/deployment_tools/model_optimizer/mo.py \
    --input_model /content/saved_model/saved_model.pb \
    --transformations_config /opt/intel/openvino_2021/deployment_tools/model_optimizer/extensions/front/tf/automl_efficientdet.json \
    --reverse_input_channels \
    --output_dir {output_dir} \

```

I’m still getting the following error message:

```auto
Please install required versions of components or use install_prerequisites script
/opt/intel/openvino_2021.3.394/deployment_tools/model_optimizer/install_prerequisites/install_prerequisites_tf2.sh
Note that install_prerequisites scripts may install additional components.
[FRAMEWORK ERROR] Cannot load input model: TensorFlow cannot read the model file: "/content/saved_model/saved_model.pb" is incorrect TensorFlow model file. 
The file should contain one of the following TensorFlow graphs:
1. frozen graph in text or binary format
2. inference graph for freezing with checkpoint (--input_checkpoint) in text or binary format
3. meta graph

Make sure that --input_model_is_text is provided for a model in text format. By default, a model is interpreted in binary format. Framework error details: Error parsing message. 
 For more information please refer to Model Optimizer FAQ, question #43. (https://docs.openvinotoolkit.org/latest/openvino_docs_MO_DG_prepare_model_Model_Optimizer_FAQ.html?question=43#question-43)

```

---

<div class="post-metadata">

**Author:** ![George](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/george/32/19412_2.png) [@George](https://discuss.ai.google.dev/u/George)\
**Post date:** [June 18, 2021, 7:54am UTC](https://discuss.ai.google.dev/t/convert-tflite-model-maker-object-detection-model-to-openvino/25464/8 "2021-06-18T07:54:15Z")

</div>

Tag @Yuqi_Li at your previous answer.  
This is also what I have noticed! `summary()` is not working after reloading the model and throws the same error:  
`AttributeError: '_UserObject' object has no attribute 'summary'`

---

<div class="post-metadata">

**Author:** ![Yuqi\_Li](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/yuqi_li/32/7251_2.png) [@Yuqi\_Li](https://discuss.ai.google.dev/u/Yuqi_Li)\
**Post date:** [June 21, 2021, 2:42am UTC](https://discuss.ai.google.dev/t/convert-tflite-model-maker-object-detection-model-to-openvino/25464/9 "2021-06-21T02:42:59Z")

</div>

I see. Not sure why it happened. While it can still be used to load the model and run inference.

---

<div class="post-metadata">

**Author:** ![Bhack](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/bhack/32/6388_2.png) [@Bhack](https://discuss.ai.google.dev/u/Bhack)\
**Post date:** [June 21, 2021, 8:07pm UTC](https://discuss.ai.google.dev/t/convert-tflite-model-maker-object-detection-model-to-openvino/25464/10 "2021-06-21T20:07:21Z")

</div>

> [@Gi\_T](#):
>
> rtunately, it seems like I can’t e

I think you can track this at:

[https://github.com/tensorflow/models/issues/8990](https://github.com/tensorflow/models/issues/8990)
