pycoral.adapters
pycoral.adapters.common
Functions to work with any model.
-
pycoral.adapters.common.
input_details
(interpreter, key)[source]¶ Gets a model’s input details by specified key.
- Parameters
interpreter – The
tf.lite.Interpreter
holding the model.key (int) – The index position of an input tensor.
- Returns
The input details.
-
pycoral.adapters.common.
input_size
(interpreter)[source]¶ Gets a model’s input size as (width, height) tuple.
- Parameters
interpreter – The
tf.lite.Interpreter
holding the model.- Returns
The input tensor size as (width, height) tuple.
-
pycoral.adapters.common.
input_tensor
(interpreter)[source]¶ Gets a model’s input tensor view as numpy array of shape (height, width, 3).
- Parameters
interpreter – The
tf.lite.Interpreter
holding the model.- Returns
The input tensor view as
numpy.array
(height, width, 3).
-
pycoral.adapters.common.
output_tensor
(interpreter, i)[source]¶ Gets a model’s ith output tensor.
- Parameters
interpreter – The
tf.lite.Interpreter
holding the model.i (int) – The index position of an output tensor.
- Returns
The output tensor at the specified position.
-
pycoral.adapters.common.
set_input
(interpreter, data)[source]¶ Copies data to a model’s input tensor.
- Parameters
interpreter – The
tf.lite.Interpreter
to update.data – The input tensor.
-
pycoral.adapters.common.
set_resized_input
(interpreter, size, resize)[source]¶ Copies a resized and properly zero-padded image to a model’s input tensor.
- Parameters
interpreter – The
tf.lite.Interpreter
to update.size (tuple) – The original image size as (width, height) tuple.
resize – A function that takes a (width, height) tuple, and returns an image resized to those dimensions.
- Returns
The resized tensor with zero-padding as tuple (resized_tensor, resize_ratio).
pycoral.adapters.classify
Functions to work with a classification model.
-
pycoral.adapters.classify.
get_classes
(interpreter, top_k=inf, score_threshold=- inf)[source]¶ Gets results from a classification model as a list of ordered classes.
- Parameters
- Returns
A list of
Class
objects representing the classification results, ordered by scores.
-
pycoral.adapters.classify.
get_classes_from_scores
(scores, top_k=inf, score_threshold=- inf)[source]¶ Gets results from a classification model as a list of ordered classes, based on given scores.
- Parameters
- Returns
A list of
Class
objects representing the classification results, ordered by scores.
-
pycoral.adapters.classify.
get_scores
(interpreter)[source]¶ Gets the output (all scores) from a classification model, dequantizing it if necessary.
- Parameters
interpreter – The
tf.lite.Interpreter
to query for output.- Returns
The output tensor (flattened and dequantized) as
numpy.array
.
pycoral.adapters.detect
Functions to work with a detection model.
-
pycoral.adapters.detect.
get_objects
(interpreter, score_threshold=- inf, image_scale=1.0, 1.0)[source]¶ Gets results from a detection model as a list of detected objects.
- Parameters
interpreter – The
tf.lite.Interpreter
to query for results.score_threshold (float) – The score threshold for results. All returned results have a score greater-than-or-equal-to this value.
image_scale (float, float) – Scaling factor to apply to the bounding boxes as (x-scale-factor, y-scale-factor), where each factor is from 0 to 1.0.
- Returns
A list of
Object
objects, which each contains the detected object’s id, score, and bounding box asBBox
.
-
class
pycoral.adapters.detect.
Object
(id, score, bbox)[source]¶ Represents a detected object.
-
id
¶ The object’s class id.
-
score
¶ The object’s prediction score.
-
-
class
pycoral.adapters.detect.
BBox
[source]¶ The bounding box for a detected object.
-
xmin
¶ X-axis start point
-
ymin
¶ Y-axis start point
-
xmax
¶ X-axis end point
-
ymax
¶ Y-axis end point
-
property
width
¶ The bounding box width.
-
property
height
¶ The bounding box height.
-
property
area
¶ The bound box area.
-
property
valid
¶ Indicates whether bounding box is valid or not (boolean).
A valid bounding box has xmin <= xmax and ymin <= ymax (equivalent to width >= 0 and height >= 0).
-
map
(f)[source]¶ Maps all box coordinates to a new position using a given function.
- Parameters
f – A function that takes a single coordinate and returns a new one.
- Returns
A
BBox
with the new coordinates.
-
API version 2.0
Is this content helpful?