tflite_support.metadata_writers.object_detector.MetadataWriter

Writes metadata into an object detector.

Inherits From: MetadataWriter

model_buffer valid buffer of the model file.
metadata_buffer valid buffer of the metadata.
associated_files path to the associated files to be populated.

Methods

create_for_inference

View source

Creates mandatory metadata for TFLite Support inference.

The parameters required in this method are mandatory when using TFLite Support features, such as Task library and Codegen tool (Android Studio ML Binding). Other metadata fields will be set to default. If other fields need to be filled, use the method create_from_metadata_info to edit them.

Args
model_buffer valid buffer of the model file.
input_norm_mean the mean value used in the input tensor normalization 1.
input_norm_std the std value used in the input tensor normalizarion 1.
label_file_paths paths to the label files 2 in the category tensor. Pass in an empty list, If the model does not have any label file.
score_calibration_md information of the score calibration operation 3 in the classification tensor. Optional if the model does not use score calibration.

Returns
A MetadataWriter object.

create_from_metadata

View source

Creates MetadataWriter based on the metadata Flatbuffers Python Objects.

Args
model_buffer valid buffer of the model file.
model_metadata general model metadata 1. The subgraph_metadata will be refreshed with input_metadata and output_metadata.
input_metadata a list of metadata of the input tensors 2.
output_metadata a list of metadata of the output tensors 3.
associated_files path to the associated files to be populated.
input_process_units a lits of metadata of the input process units 4.
output_process_units a lits of metadata of the output process units 5.

Returns
A MetadataWriter Object.

create_from_metadata_info

View source

Creates MetadataWriter based on general/input/outputs information.

Args
model_buffer valid buffer of the model file.
general_md general information about the model.
input_md input image tensor informaton.
output_location_md output location tensor informaton. The location tensor is a multidimensional array of N floating point values between 0 and 1, the inner arrays representing bounding boxes in the form [top, left, bottom, right].
output_category_md output category tensor information. The category tensor is an array of N integers (output as floating point values) each indicating the index of a class label from the labels file.
output_score_md output score tensor information. The score tensor is an array of N floating point values between 0 and 1 representing probability that a class was detected. Use ClassificationTensorMd to calibrate score.
output_number_md output number of detections tensor information. This tensor is an integer value of N.

Returns
A MetadataWriter object.

get_metadata_json

View source

Gets the generated JSON metadata string before populated into model.

This method returns the metadata buffer before populated into the model. More fields could be filled by MetadataPopulator, such as min_parser_version. Use get_populated_metadata_json() if you want to get the final metadata string.

Returns
The generated JSON metadata string before populated into model.

get_populated_metadata_json

View source

Gets the generated JSON metadata string after populated into model.

More fields could be filled by MetadataPopulator, such as min_parser_version. Use get_metadata_json() if you want to get the original metadata string.

Returns
The generated JSON metadata string after populated into model.

populate

View source

Populates the metadata and label file to the model file.

Returns
A new model buffer with the metadata and associated files.