Utilities to help process a dataset.


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.


file_path (str) – path to the label file.


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


Utilities for using the TensorFlow Lite Interpreter with Edge TPU.


Returns the Edge TPU runtime ( version.

This runtime version is dynamically retrieved from the shared object.


A string for the version name.


Invoke the given tf.lite.Interpreter with bytes as input.

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

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


Invoke the given tf.lite.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().

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

  • dma_fd (int) – DMA file descriptor.

  • size (size_t) – DMA buffer size.


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

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

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

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

  • size (size_t) – The buffer size.


Lists all available Edge TPU devices.


A list of dictionary items, each representing an Edge TPU in the system. Each dictionary includes a “type” (either “usb” or “pci”) and a “path” (the device location in the system). Note: The order of the Edge TPUs in this list are not guaranteed to be consistent across system reboots.


Loads the Edge TPU delegate with the given options.


options (dict) – Options that are passed to the Edge TPU delegate, via tf.lite.load_delegate. The only option you should use is “device”, which defines the Edge TPU to use. Supported values are the same as device in make_interpreter().


The Edge TPU delegate object.

pycoral.utils.edgetpu.make_interpreter(model_path_or_content, device=None, delegate=None)[source]

Creates a new tf.lite.Interpreter instance using the given model.

Note: If you have multiple Edge TPUs, you should always specify the device argument.

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

  • device (str) –

    The Edge TPU device you want:

    • None – use any Edge TPU (this is the default)

    • ”:<N>” – use N-th Edge TPU (this corresponds to the enumerated index position from list_edge_tpus())

    • ”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

    If left as None, you cannot reliably predict which device you’ll get. So if you have multiple Edge TPUs and want to run a specific model on each one, then you must specify the device.

  • delegate – A pre-loaded Edge TPU delegate object, as provided by load_edgetpu_delegate(). If provided, the device argument is ignored.


New tf.lite.Interpreter instance.

pycoral.utils.edgetpu.run_inference(interpreter, input_data)[source]

Performs interpreter invoke() with a raw input tensor.

  • 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.


Sets the verbosity of operating logs related to each Edge TPU. 10 is the most verbose; 0 is the default.


verbosity (int) – Desired verbosity 0-10.


A boolean indicating if verbosity was succesfully set.


Checks whether the device supports Linux dma-buf.


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


True if the device supports DMA buffers.

API version 2.0