Is it possible to save the trained model "Object Detection with TensorFlow Lite Model Maker" in a single file as model.keras zip archive?

According to ‘Object Detection with TensorFlow Lite Model Maker’, a detector model can be created and trained.
I will omit the installation of dependencies and the creation of datasets, the working code for creating and training the model looks like this:

import tensorflow as tf
import numpy as np
import os from tflite_model_maker.config
import ExportFormat, QuantizationConfig from tflite_model_maker
import model_spec from tflite_model_maker
import object_detector from tflite_support import metadata
    
# Load model spec
spec = object_detector.EfficientDetSpec(model_name='efficientdet-lite2', uri='https://tfhub.dev/tensorflow/efficientdet/lite2/feature-vector/1', model_dir='/content/checkpoints', hparams={'max_instances_per_image': 8000})
    
# Train the model
model = object_detector.create(train_data, model_spec=spec, batch_size=4, train_whole_model=True, epochs=20, validation_data=val_data)
    
# Evaluate the model
eval_result = model.evaluate(val_data)
    
# Print COCO metrics
print("COCO metrics:") for label, metric_value in eval_result.items():
        print(f"{label}: {metric_value}")

COCO metrics show that everything is fine with the trained model. In the documentation example tensorflow.org, next, the model is exported and saved in the *.tflite format.
The question is, is there a way to save this already trained model as “Save the entire model” (ذخیره و بارگذاری مدل ها  |  TensorFlow Core ) ?

When trying to execute on the next line:

model.save('trained_detector_model.h5', save_format='h5')
or
model.save('trained_detector_model.keras')

leads to:

Traceback (most recent call last):
  File "/content/train.py", line 66, in <module>
    model.save('trained_detector_model.h5', save_format='h5')
AttributeError: 'ObjectDetector' object has no attribute 'save'

Hi @Yustas

I am not sure if this would surely help.

you would require to create a path to save the model, and how to do this, will require you to go through the below GitHub link where model are converted to json format

but surely not in zip.archive form

Regards
DP

1 Like

Hi @Deepti_Prasad , thank you very much for your reply.