tensorflow / tensorflow/tflite-support

YOLOv8 `tensorflow>=2.14.0` ImportError: generic_type: cannot initialize type "StatusCode": an object with that name is already defined

Open
#954 6 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
441
Forks
146
PR merge metrics
No merged PRs in 30d

Description

YOLOv8 TFLite export is failing with the latest release of tensorflow==2.14.0 but works with tensorflow==2.13.1, the prior release.

The error originates from the tflite_support package.

Traceback (most recent call last):
  File "/usr/local/bin/yolo", line 8, in <module>
    sys.exit(entrypoint())
  File "/usr/local/lib/python3.10/dist-packages/ultralytics/cfg/__init__.py", line 445, in entrypoint
    getattr(model, mode)(**overrides)  # default args from model
  File "/usr/local/lib/python3.10/dist-packages/ultralytics/engine/model.py", line 306, in export
    return Exporter(overrides=args, _callbacks=self.callbacks)(model=self.model)
  File "/usr/local/lib/python3.10/dist-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/ultralytics/engine/exporter.py", line 261, in __call__
    f[5], keras_model = self.export_saved_model()
  File "/usr/local/lib/python3.10/dist-packages/ultralytics/engine/exporter.py", line 122, in outer_func
    raise e
  File "/usr/local/lib/python3.10/dist-packages/ultralytics/engine/exporter.py", line 117, in outer_func
    f, model = inner_func(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/ultralytics/engine/exporter.py", line 707, in export_saved_model
    f.unlink() if 'quant_with_int16_act.tflite' in str(f) else self._add_tflite_metadata(file)
  File "/usr/local/lib/python3.10/dist-packages/ultralytics/engine/exporter.py", line 813, in _add_tflite_metadata
    from tflite_support import flatbuffers  # noqa
  File "/usr/local/lib/python3.10/dist-packages/tflite_support/__init__.py", line 53, in <module>
    from tflite_support import task
  File "/usr/local/lib/python3.10/dist-packages/tflite_support/task/__init__.py", line 32, in <module>
    from . import vision
  File "/usr/local/lib/python3.10/dist-packages/tflite_support/task/vision/__init__.py", line 20, in <module>
    from tensorflow_lite_support.python.task.vision import image_classifier
  File "/usr/local/lib/python3.10/dist-packages/tensorflow_lite_support/python/task/vision/image_classifier.py", line 23, in <module>
    from tensorflow_lite_support.python.task.vision.core import tensor_image
  File "/usr/local/lib/python3.10/dist-packages/tensorflow_lite_support/python/task/vision/core/tensor_image.py", line 19, in <module>
    from tensorflow_lite_support.python.task.vision.core.pybinds import image_utils
ImportError: generic_type: cannot initialize type "StatusCode": an object with that name is already defined
Reproduce

Run in Google Colab:
https://colab.research.google.com/github/ultralytics/ultralytics/blob/main/examples/tutorial.ipynb

!pip install 'tensorflow>=2.14.0' ultralytics
import ultralytics
ultralytics.checks()

!yolo export format=tflite
Screenshot 2023-09-29 at 14 21 09
Additional

Tracked in https://github.com/ultralytics/ultralytics/issues/5161

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the Google Colab reproduction from examples/tutorial.ipynb with tensorflow>=2.14.0 and inspect ultralytics/engine/exporter.py at _add_tflite_metadata. Trace the tflite_support import that raises the StatusCode error and verify that YOLOv8 TFLite export completes successfully with TensorFlow 2.14.0.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, tensorflow
Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.