ModuleNotFoundError: No module named 'tflite_support.metadata_writers'

Viewed 1653
from tflite_support.metadata_writers import object_detector
from tflite_support.metadata_writers import writer_utils
from tflite_support import metadata

ObjectDetectorWriter = object_detector.MetadataWriter
_MODEL_PATH = "mobile.tflite"
_LABEL_FILE = "labelmap.txt"
_SAVE_TO_PATH = "detect_metadata.tflite"

writer = ObjectDetectorWriter.create_for_inference(
    writer_utils.load_file(_MODEL_PATH), [127.5], [127.5], [_LABEL_FILE])
writer_utils.save_file(writer.populate(), _SAVE_TO_PATH)

# Verify the populated metadata and associated files.
displayer = metadata.MetadataDisplayer.with_model_file(_SAVE_TO_PATH)
print("Metadata populated:")
print(displayer.get_metadata_json())
print("Associated file(s) populated:")
print(displayer.get_packed_associated_file_list())

I use this code from link Github: https://github.com/tensorflow/tensorflow/issues/43775

But this code was a bug. Below that is an error after running the above code.


ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-87-39fd915e7a2a> in <module>()

---->     1 from tflite_support.metadata_writers import object_detector
          2 from tflite_support.metadata_writers import writer_utils
          3 from tflite_support import metadata
          4 
          5 ObjectDetectorWriter = object_detector.MetadataWriter

ModuleNotFoundError: No module named 'tflite_support.metadata_writers'

NOTE: If your import is failing due to a missing package, you can manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the "Open Examples" button below.

How to fix this bug?

2 Answers

The tflite_support package on pypi now includes tflite_support.task

However, it will not run on Python 3.6. Version 0.3.1 is the latest one that supports Python 3.6. Using Python 3.7 instead of 3.6, and then installing verison 0.4.2 of tflite_support fixed the problem for me.

Related