tensorflow/lite/g3doc/api_docs/python/tflite_model_maker/object_detector/EfficientDetSpec.md
page_type: reference description: A specification of the EfficientDet model.
<link rel="stylesheet" href="/site-assets/css/style.css"> <!-- DO NOT EDIT! Automatically generated file. --> <div itemscope itemtype="http://developers.google.com/ReferenceObject"> <meta itemprop="name" content="tflite_model_maker.object_detector.EfficientDetSpec" /> <meta itemprop="path" content="Stable" /> <meta itemprop="property" content="__init__"/> <meta itemprop="property" content="create_model"/> <meta itemprop="property" content="evaluate"/> <meta itemprop="property" content="evaluate_tflite"/> <meta itemprop="property" content="export_saved_model"/> <meta itemprop="property" content="export_tflite"/> <meta itemprop="property" content="get_default_quantization_config"/> <meta itemprop="property" content="train"/> <meta itemprop="property" content="compat_tf_versions"/> </div>View source on GitHub
A specification of the EfficientDet model.
<pre class="devsite-click-to-copy prettyprint lang-py tfo-signature-link"> <code>tflite_model_maker.object_detector.EfficientDetSpec( model_name: str, uri: str, hparams: str = '', model_dir: Optional[str] = None, epochs: int = 50, batch_size: int = 64, steps_per_execution: int = 1, moving_average_decay: int = 0, var_freeze_expr: str = '(efficientnet|fpn_cells|resample_p6)', tflite_max_detections: int = 25, strategy: Optional[str] = None, tpu: Optional[str] = None, gcp_project: Optional[str] = None, tpu_zone: Optional[str] = None, use_xla: bool = False, profile: bool = False, debug: bool = False, tf_random_seed: int = 111111, verbose: int = 0 ) -> None </code></pre> <!-- Placeholder for "Used in" --> <!-- Tabular view --> <table class="responsive fixed orange"> <colgroup><col width="214px"><col></colgroup> <tr><th colspan="2"><h2 class="add-link">Args</h2></th></tr> <tr> <td> `model_name`<a id="model_name"></a> </td> <td> Model name. </td> </tr><tr> <td> `uri`<a id="uri"></a> </td> <td> TF-Hub path/url to EfficientDet module. </td> </tr><tr> <td> `hparams`<a id="hparams"></a> </td> <td> Hyperparameters used to overwrite default configuration. Can be<a target="_blank" class="external" href="https://github.com/tensorflow/examples/blob/master/tensorflow_examples/lite/model_maker/core/task/model_spec/object_detector_spec.py#L235-L238">View source</a>
<pre class="devsite-click-to-copy prettyprint lang-py tfo-signature-link"> <code>create_model() -> tf.keras.Model </code></pre>Creates the EfficientDet model.
<h3 id="evaluate"><code>evaluate</code></h3><a target="_blank" class="external" href="https://github.com/tensorflow/examples/blob/master/tensorflow_examples/lite/model_maker/core/task/model_spec/object_detector_spec.py#L303-L346">View source</a>
<pre class="devsite-click-to-copy prettyprint lang-py tfo-signature-link"> <code>evaluate( model: tf.keras.Model, dataset: tf.data.Dataset, steps: int, json_file: Optional[str] = None ) -> Dict[str, float] </code></pre>Evaluate the EfficientDet keras model.
<!-- Tabular view --> <table class="responsive fixed orange"> <colgroup><col width="214px"><col></colgroup> <tr><th colspan="2">Args</th></tr> <tr> <td> `model` </td> <td> The keras model to be evaluated. </td> </tr><tr> <td> `dataset` </td> <td> tf.data.Dataset used for evaluation. </td> </tr><tr> <td> `steps` </td> <td> Number of steps to evaluate the model. </td> </tr><tr> <td> `json_file` </td> <td> JSON with COCO data format containing golden bounding boxes. Used for validation. If None, use the ground truth from the dataloader. Refer to <a href="https://towardsdatascience.com/coco-data-format-for-object-detection-a4c5eaf518c5">https://towardsdatascience.com/coco-data-format-for-object-detection-a4c5eaf518c5</a> for the description of COCO data format. </td> </tr> </table> <!-- Tabular view --> <table class="responsive fixed orange"> <colgroup><col width="214px"><col></colgroup> <tr><th colspan="2">Returns</th></tr> <tr class="alt"> <td colspan="2"> A dict contains AP metrics. </td> </tr> </table> <h3 id="evaluate_tflite"><code>evaluate_tflite</code></h3><a target="_blank" class="external" href="https://github.com/tensorflow/examples/blob/master/tensorflow_examples/lite/model_maker/core/task/model_spec/object_detector_spec.py#L348-L401">View source</a>
<pre class="devsite-click-to-copy prettyprint lang-py tfo-signature-link"> <code>evaluate_tflite( tflite_filepath: str, dataset: tf.data.Dataset, steps: int, json_file: Optional[str] = None ) -> Dict[str, float] </code></pre>Evaluate the EfficientDet TFLite model.
<!-- Tabular view --> <table class="responsive fixed orange"> <colgroup><col width="214px"><col></colgroup> <tr><th colspan="2">Args</th></tr> <tr> <td> `tflite_filepath` </td> <td> File path to the TFLite model. </td> </tr><tr> <td> `dataset` </td> <td> tf.data.Dataset used for evaluation. </td> </tr><tr> <td> `steps` </td> <td> Number of steps to evaluate the model. </td> </tr><tr> <td> `json_file` </td> <td> JSON with COCO data format containing golden bounding boxes. Used for validation. If None, use the ground truth from the dataloader. Refer to <a href="https://towardsdatascience.com/coco-data-format-for-object-detection-a4c5eaf518c5">https://towardsdatascience.com/coco-data-format-for-object-detection-a4c5eaf518c5</a> for the description of COCO data format. </td> </tr> </table> <!-- Tabular view --> <table class="responsive fixed orange"> <colgroup><col width="214px"><col></colgroup> <tr><th colspan="2">Returns</th></tr> <tr class="alt"> <td colspan="2"> A dict contains AP metrics. </td> </tr> </table> <h3 id="export_saved_model"><code>export_saved_model</code></h3><a target="_blank" class="external" href="https://github.com/tensorflow/examples/blob/master/tensorflow_examples/lite/model_maker/core/task/model_spec/object_detector_spec.py#L403-L446">View source</a>
<pre class="devsite-click-to-copy prettyprint lang-py tfo-signature-link"> <code>export_saved_model( model: tf.keras.Model, saved_model_dir: str, batch_size: Optional[int] = None, pre_mode: Optional[str] = 'infer', post_mode: Optional[str] = 'global' ) -> None </code></pre>Saves the model to Tensorflow SavedModel.
<!-- Tabular view --> <table class="responsive fixed orange"> <colgroup><col width="214px"><col></colgroup> <tr><th colspan="2">Args</th></tr> <tr> <td> `model` </td> <td> The EfficientDetNet model used for training which doesn't have pre and post processing. </td> </tr><tr> <td> `saved_model_dir` </td> <td> Folder path for saved model. </td> </tr><tr> <td> `batch_size` </td> <td> Batch size to be saved in saved_model. </td> </tr><tr> <td> `pre_mode` </td> <td> Pre-processing Mode in ExportModel, must be {None, 'infer'}. </td> </tr><tr> <td> `post_mode` </td> <td> Post-processing Mode in ExportModel, must be {None, 'global', 'per_class', 'tflite'}. </td> </tr> </table> <h3 id="export_tflite"><code>export_tflite</code></h3><a target="_blank" class="external" href="https://github.com/tensorflow/examples/blob/master/tensorflow_examples/lite/model_maker/core/task/model_spec/object_detector_spec.py#L466-L513">View source</a>
<pre class="devsite-click-to-copy prettyprint lang-py tfo-signature-link"> <code>export_tflite( model: tf.keras.Model, tflite_filepath: str, quantization_config: Optional[<a href="../../tflite_model_maker/config/QuantizationConfig"><code>tflite_model_maker.config.QuantizationConfig</code></a>] = None ) -> None </code></pre>Converts the retrained model to tflite format and saves it.
The exported TFLite model has the following inputs & outputs:
One input:
image: a float32 tensor of shape[1, height, width, 3] containing the
normalized input image. self.config.image_size is [height, width].
<a target="_blank" class="external" href="https://github.com/tensorflow/examples/blob/master/tensorflow_examples/lite/model_maker/core/task/model_spec/object_detector_spec.py#L448-L464">View source</a>
<pre class="devsite-click-to-copy prettyprint lang-py tfo-signature-link"> <code>get_default_quantization_config( representative_data: <a href="../../tflite_model_maker/object_detector/DataLoader"><code>tflite_model_maker.object_detector.DataLoader</code></a> ) -> <a href="../../tflite_model_maker/config/QuantizationConfig"><code>tflite_model_maker.config.QuantizationConfig</code></a> </code></pre>Gets the default quantization configuration.
<h3 id="train"><code>train</code></h3><a target="_blank" class="external" href="https://github.com/tensorflow/examples/blob/master/tensorflow_examples/lite/model_maker/core/task/model_spec/object_detector_spec.py#L240-L272">View source</a>
<pre class="devsite-click-to-copy prettyprint lang-py tfo-signature-link"> <code>train( model: tf.keras.Model, train_dataset: tf.data.Dataset, steps_per_epoch: int, val_dataset: Optional[tf.data.Dataset], validation_steps: int, epochs: Optional[int] = None, batch_size: Optional[int] = None, val_json_file: Optional[str] = None ) -> tf.keras.Model </code></pre>Run EfficientDet training.
<!-- Tabular view --> <table class="responsive fixed orange"> <colgroup><col width="214px"><col></colgroup> <tr><th colspan="2"><h2 class="add-link">Class Variables</h2></th></tr> <tr> <td> compat_tf_versions<a id="compat_tf_versions"></a> </td> <td> `[2]` </td> </tr> </table>