Back to Tensorflow

tflite_support.task.vision.ObjectDetector

tensorflow/lite/g3doc/api_docs/python/tflite_support/task/vision/ObjectDetector.md

2.21.05.7 KB
Original Source

page_type: reference description: Class that performs object detection on images.

<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_support.task.vision.ObjectDetector" /> <meta itemprop="path" content="Stable" /> <meta itemprop="property" content="__init__"/> <meta itemprop="property" content="create_from_file"/> <meta itemprop="property" content="create_from_options"/> <meta itemprop="property" content="detect"/> </div>

tflite_support.task.vision.ObjectDetector

<!-- Insert buttons and diff --> <table class="tfo-notebook-buttons tfo-api nocontent" align="left"> <td> <a target="_blank" href="https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/vision/object_detector.py#L45-L110">
View source on GitHub
</a> </td> </table>

Class that performs object detection on images.

<pre class="devsite-click-to-copy prettyprint lang-py tfo-signature-link"> <code>tflite_support.task.vision.ObjectDetector( options: <a href="../../../tflite_support/task/vision/ObjectDetectorOptions"><code>tflite_support.task.vision.ObjectDetectorOptions</code></a>, detector: _CppObjectDetector ) -> None </code></pre> <!-- Placeholder for "Used in" -->

Methods

<h3 id="create_from_file"><code>create_from_file</code></h3>

<a target="_blank" class="external" href="https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/vision/object_detector.py#L55-L72">View source</a>

<pre class="devsite-click-to-copy prettyprint lang-py tfo-signature-link"> <code>@classmethod</code> <code>create_from_file( file_path: str ) -> 'ObjectDetector' </code></pre>

Creates the ObjectDetector object from a TensorFlow Lite model.

<!-- Tabular view --> <table class="responsive fixed orange"> <colgroup><col width="214px"><col></colgroup> <tr><th colspan="2">Args</th></tr> <tr> <td> `file_path` </td> <td> Path to the model. </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"> `ObjectDetector` object that's created from the model file. </td> </tr> </table> <!-- Tabular view --> <table class="responsive fixed orange"> <colgroup><col width="214px"><col></colgroup> <tr><th colspan="2">Raises</th></tr> <tr> <td> `ValueError` </td> <td> if failed to create `ObjectDetector` object from the provided file such as invalid file. </td> </tr><tr> <td> `RuntimeError` </td> <td> If other types of error occurred. </td> </tr> </table> <h3 id="create_from_options"><code>create_from_options</code></h3>

<a target="_blank" class="external" href="https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/vision/object_detector.py#L74-L92">View source</a>

<pre class="devsite-click-to-copy prettyprint lang-py tfo-signature-link"> <code>@classmethod</code> <code>create_from_options( options: <a href="../../../tflite_support/task/vision/ObjectDetectorOptions"><code>tflite_support.task.vision.ObjectDetectorOptions</code></a> ) -> 'ObjectDetector' </code></pre>

Creates the ObjectDetector object from object detector options.

<!-- Tabular view --> <table class="responsive fixed orange"> <colgroup><col width="214px"><col></colgroup> <tr><th colspan="2">Args</th></tr> <tr> <td> `options` </td> <td> Options for the object detector task. </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"> `ObjectDetector` object that's created from `options`. </td> </tr> </table> <!-- Tabular view --> <table class="responsive fixed orange"> <colgroup><col width="214px"><col></colgroup> <tr><th colspan="2">Raises</th></tr> <tr> <td> `ValueError` </td> <td> If failed to create `ObjectDetector` object from `ObjectDetectorOptions` such as missing the model. </td> </tr><tr> <td> `RuntimeError` </td> <td> If other types of error occurred. </td> </tr> </table> <h3 id="detect"><code>detect</code></h3>

<a target="_blank" class="external" href="https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/vision/object_detector.py#L94-L110">View source</a>

<pre class="devsite-click-to-copy prettyprint lang-py tfo-signature-link"> <code>detect( image: <a href="../../../tflite_support/task/vision/TensorImage"><code>tflite_support.task.vision.TensorImage</code></a> ) -> <a href="../../../tflite_support/task/processor/DetectionResult"><code>tflite_support.task.processor.DetectionResult</code></a> </code></pre>

Performs object detection on the provided TensorImage.

<!-- Tabular view --> <table class="responsive fixed orange"> <colgroup><col width="214px"><col></colgroup> <tr><th colspan="2">Args</th></tr> <tr> <td> `image` </td> <td> Tensor image, used to extract the feature vectors. </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"> detection result. </td> </tr> </table> <!-- Tabular view --> <table class="responsive fixed orange"> <colgroup><col width="214px"><col></colgroup> <tr><th colspan="2">Raises</th></tr> <tr> <td> `ValueError` </td> <td> If any of the input arguments is invalid. </td> </tr><tr> <td> `RuntimeError` </td> <td> If object detection failed to run. </td> </tr> </table>