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.get_runtime_version()

Returns the Edge TPU runtime (libedgetpu.so) version.

This runtime version is dynamically retrieved from the shared object.

Returns

A string for the version name.

pycoral.utils.edgetpu.invoke_with_bytes()

Invoke the given tflite.Interpreter with bytes as input.

Parameters
  • interpreter – The tflite:Interpreter to invoke.

  • input_data (bytes) – Raw bytes as input data.

pycoral.utils.edgetpu.invoke_with_dmabuffer()

Invoke the given tflite.Interpreter using a given Linux dma-buf file descriptor as an input tensor.

Works only for Edge TPU models running on PCIe-based Coral devices. You can verify device support with supports_dmabuf().

Parameters
  • interpreter – The tflite:Interpreter to invoke.

  • dma_fd (int) – DMA file descriptor.

  • size (size_t) – DMA buffer size.

pycoral.utils.edgetpu.invoke_with_membuffer()

Invoke the given tflite.Interpreter with a pointer to a native memory allocation.

Works only for Edge TPU models running on PCIe TPU devices.

Parameters
  • interpreter – The tflite:Interpreter to invoke.

  • buffer (intptr_t) – Pointer to memory buffer with input data.

  • size (size_t) – The buffer size.

pycoral.utils.edgetpu.list_edge_tpus()

Lists all available Edge TPU devices.

Returns

A list of dictionary, each representing a device record of type and path.

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.

pycoral.utils.edgetpu.supports_dmabuf()

Checks whether the device supports Linux dma-buf.

Parameters

interpreter – The tflite:Interpreter that’s bound to the Edge TPU you want to query.

Returns

True if the device supports DMA buffers.

API version 1.0