View source on GitHub |
ObjectDetector class for inference and exporting to tflite.
tflite_model_maker.object_detector.ObjectDetector(
model_spec: tflite_model_maker.object_detector.EfficientDetSpec
,
label_map: Dict[int, str],
representative_data: Optional[tflite_model_maker.object_detector.DataLoader
] = None
) -> None
Methods
create
@classmethod
create( train_data:
tflite_model_maker.object_detector.DataLoader
, model_spec:tflite_model_maker.object_detector.EfficientDetSpec
, validation_data: Optional[tflite_model_maker.object_detector.DataLoader
] = None, epochs: Optional[tflite_model_maker.object_detector.DataLoader
] = None, batch_size: Optional[int] = None, train_whole_model: bool = False, do_train: bool = True ) -> T
Loads data and train the model for object detection.
Args | |
---|---|
train_data
|
Training data. |
model_spec
|
Specification for the model. |
validation_data
|
Validation data. If None, skips validation process. |
epochs
|
Number of epochs for training. |
batch_size
|
Batch size for training. |
train_whole_model
|
Boolean, False by default. If true, train the whole
model. Otherwise, only train the layers that are not match
model_spec.config.var_freeze_expr .
|
do_train
|
Whether to run training. |
Returns | |
---|---|
An instance based on ObjectDetector. |
create_model
create_model() -> tf.keras.Model
create_serving_model
create_serving_model()
Returns the underlining Keras model for serving.
evaluate
evaluate(
data: tflite_model_maker.object_detector.DataLoader
,
batch_size: Optional[int] = None
) -> Dict[str, float]
Evaluates the model.
evaluate_tflite
evaluate_tflite(
tflite_filepath: str,
data: tflite_model_maker.object_detector.DataLoader
) -> Dict[str, float]
Evaluate the TFLite model.
export
export(
export_dir,
tflite_filename='model.tflite',
label_filename='labels.txt',
vocab_filename='vocab.txt',
saved_model_filename='saved_model',
tfjs_folder_name='tfjs',
export_format=None,
**kwargs
)
Converts the retrained model based on export_format
.
Args | |
---|---|
export_dir
|
The directory to save exported files. |
tflite_filename
|
File name to save tflite model. The full export path is {export_dir}/{tflite_filename}. |
label_filename
|
File name to save labels. The full export path is {export_dir}/{label_filename}. |
vocab_filename
|
File name to save vocabulary. The full export path is {export_dir}/{vocab_filename}. |
saved_model_filename
|
Path to SavedModel or H5 file to save the model. The full export path is {export_dir}/{saved_model_filename}/{saved_model.pb|assets|variables}. |
tfjs_folder_name
|
Folder name to save tfjs model. The full export path is {export_dir}/{tfjs_folder_name}. |
export_format
|
List of export format that could be saved_model, tflite, label, vocab. |
**kwargs
|
Other parameters like quantized_config for TFLITE model.
|
summary
summary()
train
train(
train_data: tflite_model_maker.object_detector.DataLoader
,
validation_data: Optional[tflite_model_maker.object_detector.DataLoader
] = None,
epochs: Optional[int] = None,
batch_size: Optional[int] = None
) -> tf.keras.Model
Feeds the training data for training.
Class Variables | |
---|---|
ALLOWED_EXPORT_FORMAT |
(<ExportFormat.TFLITE: 'TFLITE'>,
<ExportFormat.SAVED_MODEL: 'SAVED_MODEL'>,
<ExportFormat.LABEL: 'LABEL'>)
|
DEFAULT_EXPORT_FORMAT |
<ExportFormat.TFLITE: 'TFLITE'>
|