pycoral.utils

pycoral.utils.dataset

Utilities to help process a dataset.

pycoral.utils.dataset.read_label_file(file_path)

Reads labels from a text file and returns it as a dictionary.

This function supports label files with the following formats:

  • Each line contains id and description separated by colon or space. Example: 0:cat or 0 cat.

  • Each line contains a description only. The returned label id’s are based on the row number.

Parameters

file_path (str) – path to the label file.

Returns

Dict of (int, string) which maps label id to description.

pycoral.utils.edgetpu

Utilities for using the TensorFlow Lite Interpreter with Edge TPU.

pycoral.utils.edgetpu.load_edgetpu_delegate(options=None)

Loads the Edge TPU delegate with the given options.

pycoral.utils.edgetpu.make_interpreter(model_path_or_content, device=None)

Returns a new interpreter instance.

Interpreter is created from either model path or model content and attached to an Edge TPU device.

Parameters
  • model_path_or_content (str or bytes) – str object is interpreted as model path, bytes object is interpreted as model content.

  • device (str) –

    The type of Edge TPU device you want:

    • None – use any Edge TPU

    • ”:<N>” – use N-th Edge TPU

    • ”usb” – use any USB Edge TPU

    • ”usb:<N>” – use N-th USB Edge TPU

    • ”pci” – use any PCIe Edge TPU

    • ”pci:<N>” – use N-th PCIe Edge TPU

Returns

New tf.lite.Interpreter instance.

pycoral.utils.edgetpu.run_inference(interpreter, input_data)

Performs interpreter invoke() with a raw input tensor.

Parameters
  • interpreter – The tf.lite.Interpreter to invoke.

  • input_data – A 1-D array as the input tensor. Input data must be uint8 format. Data may be Gst.Buffer or numpy.ndarray.