tensorflow / tensorflow/tflite-support

TFlite export wrong

Open
#974 0 comments 0 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

I want to export yolov8n.pt through TFLite, but encountered the following bug during the export process.
TensorFlow SavedModel: export failure ❌ 20.8s: cannot import name 'metadata_schema_py_generated' from 'tflite_support.metadata' (C:\conda\envs\yolov8\lib\site-packages\tflite_support\metadata.py)
Traceback (most recent call last):
File "c:\my_programm\yolov8\test.py", line 7, in
model.export(format="tflite") # creates 'yolov8n_float32.tflite'
File "C:\conda\envs\yolov8\lib\site-packages\ultralytics\engine\model.py", line 591, in export
return Exporter(overrides=args, _callbacks=self.callbacks)(model=self.model)
File "C:\conda\envs\yolov8\lib\site-packages\torch\utils_contextlib.py", line 115, in decorate_context
return func(*args, **kwargs)
File "C:\conda\envs\yolov8\lib\site-packages\ultralytics\engine\exporter.py", line 313, in call
f[5], keras_model = self.export_saved_model()
File "C:\conda\envs\yolov8\lib\site-packages\ultralytics\engine\exporter.py", line 142, in outer_func
raise e
File "C:\conda\envs\yolov8\lib\site-packages\ultralytics\engine\exporter.py", line 137, in outer_func
f, model = inner_func(*args, **kwargs)
File "C:\conda\envs\yolov8\lib\site-packages\ultralytics\engine\exporter.py", line 900, in export_saved_model
f.unlink() if "quant_with_int16_act.tflite" in str(f) else self._add_tflite_metadata(file)
File "C:\conda\envs\yolov8\lib\site-packages\ultralytics\engine\exporter.py", line 1024, in _add_tflite_metadata
from tflite_support.metadata import metadata_schema_py_generated as schema # noqa
ImportError: cannot import name 'metadata_schema_py_generated' from 'tflite_support.metadata' (C:\conda\envs\yolov8\lib\site-packages\tflite_support\metadata.py)
This is where the error occurred.
屏幕截图 2024-07-01 093653
But after I imported the same module in both branches, the bug was resolved.
屏幕截图 2024-07-01 094034

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

Reproduce the TFLite export using the reported yolov8n.pt example and inspect the _add_tflite_metadata path in ultralytics/engine/exporter.py together with the tflite_support.metadata import. Verify the behavior across the relevant package versions; done means the export completes and the generated TFLite model receives metadata without the ImportError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, tensorflow
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.