KeyError: 1720: Python

45 Views Asked by At

I'm following this tutorial on how to export my saved model to tflite for building an android app using my custom detection model Link

But after executing this code

ObjectDetectorWriter = object_detector.MetadataWriter

_MODEL_PATH = "/content/detect.tflite"
_LABEL_FILE = "/content/labelmap.txt"
_SAVE_TO_PATH = "/content/tflite_with_metadata/detect.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())

model_meta = _metadata_fb.ModelMetadataT()
model_meta.name = "SSD_Detector"
model_meta.description = (
    "Identify which of a known set of objects might be present and provide "
    "information about their positions within the given image or a video "
    "stream.")

# Creates input info.
input_meta = _metadata_fb.TensorMetadataT()
input_meta.name = "image"
input_meta.content = _metadata_fb.ContentT()
input_meta.content.contentProperties = _metadata_fb.ImagePropertiesT()
input_meta.content.contentProperties.colorSpace = (
...

it gave an error:

KeyError                                  Traceback (most recent call last)
<ipython-input-31-2e8ec3b1f9af> in <cell line: 7>()
      5 _SAVE_TO_PATH = "/content/tflite_with_metadata/detect.tflite"
      6 
----> 7 writer = ObjectDetectorWriter.create_for_inference(
      8     writer_utils.load_file(_MODEL_PATH), [127.5], [127.5], [_LABEL_FILE])
      9 writer_utils.save_file(writer.populate(), _SAVE_TO_PATH)

2 frames
/usr/local/lib/python3.10/dist-packages/tensorflow_lite_support/metadata/python/metadata_writers/object_detector.py in <listcomp>(.0)
    210 
    211     # Output metadata according to output_tensor_indices.
--> 212     output_metadata = [indices_to_tensors[i] for i in output_tensor_indices]
    213 
    214     # Create subgraph info.

KeyError: 1720

here's my jupyter notebook Link

I've tried other methods but all give the same error.

0

There are 0 best solutions below