aiy.vision.inference

An inference engine that communicates with the Vision Bonnet from the Raspberry Pi side.

It can be used to load a model, analyze local image or image from camera shot. It automatically unload the model once the associated object is deleted. See image_classification.py and object_recognition.py as examples on how to use this API.

class aiy.vision.inference.CameraInference(descriptor, params=None, sparse_configs=None)

Bases: object

Helper class to run camera inference.

close()
count
engine
rate
run(count=None)
class aiy.vision.inference.FirmwareVersion(major, minor)

Bases: tuple

major

Alias for field number 0

minor

Alias for field number 1

exception aiy.vision.inference.FirmwareVersionException(*args, **kwargs)

Bases: Exception

class aiy.vision.inference.FromSparseTensorConfig(logical_shape, tensor_name, squeeze_dims)

Bases: tuple

logical_shape

Alias for field number 0

squeeze_dims

Alias for field number 2

tensor_name

Alias for field number 1

class aiy.vision.inference.ImageInference(descriptor)

Bases: object

Helper class to run image inference.

close()
engine
run(image, params=None, sparse_configs=None)
class aiy.vision.inference.InferenceEngine

Bases: object

Class to access InferenceEngine on VisionBonnet board.

Inference result has the following format:

message InferenceResult {
  string model_name;  // Name of the model to run inference on.
  int32 width;        // Input image/frame width.
  int32 height;       // Input image/frame height.
  Rectangle window;   // Window inside width x height image/frame.
  int32 duration_ms;  // Inference duration.
  map<string, FloatTensor> tensors;  // Output tensors.

  message Frame {
    int32 index;        // Frame number.
    int64 timestamp_us; // Frame timestamp.
  }

  Frame frame;          // Frame-specific inference data.
}
camera_inference()

Returns the latest inference result from VisionBonnet.

close()
get_camera_state()

Returns current camera state.

get_firmware_info()

Returns firmware version as (major, minor) tuple.

get_inference_state()

Returns inference state.

get_system_info()

Returns system information: uptime, memory usage, temperature.

image_inference(model_name, image, params=None, sparse_configs=None)

Runs inference on image using model identified by model_name.

Parameters:
  • model_name – string, unique identifier used to refer a model.
  • image – PIL.Image,
  • params – dict, additional parameters to run inference
Returns:

pb2.Response.InferenceResult

load_model(descriptor)

Loads model on VisionBonnet.

Parameters:descriptor – ModelDescriptor, meta info that defines model name, where to get the model and etc.
Returns:Model identifier.
reset()
start_camera_inference(model_name, params=None, sparse_configs=None)

Starts inference running on VisionBonnet.

stop_camera_inference()

Stops inference running on VisionBonnet.

unload_model(model_name)

Deletes model on VisionBonnet.

Parameters:model_name – string, unique identifier used to refer a model.
exception aiy.vision.inference.InferenceException(*args, **kwargs)

Bases: Exception

class aiy.vision.inference.ModelDescriptor(name, input_shape, input_normalizer, compute_graph)

Bases: tuple

compute_graph

Alias for field number 3

input_normalizer

Alias for field number 2

input_shape

Alias for field number 1

name

Alias for field number 0

class aiy.vision.inference.ThresholdingConfig(logical_shape, threshold, top_k, to_ignore)

Bases: tuple

logical_shape

Alias for field number 0

threshold

Alias for field number 1

to_ignore

Alias for field number 3

top_k

Alias for field number 2