Search code examples
pythongoogle-coral

What does the @ in split('@') do besides from being a string separator?


I am using the Coral dev board to accelerate AI models. I do not understand what does the '@' mean.

split returns a list of all the words in a string using an specified 'separator'. But the name of my model file does not have an '@'.

It seems it is assigning a delegate to the model file.

The name of the model = mobilenet_v2_1.0_224_quant_edgetpu.tflite

import argparse
import time

from PIL import Image

import classify
import tflite_runtime.interpreter as tflite
import platform

EDGETPU_SHARED_LIB = {
  'Linux': 'libedgetpu.so.1',
  'Darwin': 'libedgetpu.1.dylib',
  'Windows': 'edgetpu.dll'
}[platform.system()]

def make_interpreter(model_file):
  model_file, *device = model_file.split('@')
  return tflite.Interpreter(
      model_path=model_file,
      experimental_delegates=[
          tflite.load_delegate(EDGETPU_SHARED_LIB,
                               {'device': device[0]} if device else {})
      ])

Thank you


Solution

  • Apologies for the downvotes, I'm Nam from google-coral team here, the downvotes are from stackoverflow users and not us. You do have a solid question, and I second @Green Cloak Guy's answer, however to further expand this:

    In our documentation for using multiple tpus with the tflite API, you can specify which device you want to load this model on: https://coral.ai/docs/edgetpu/multiple-edgetpu/#using-the-tensorflow-lite-python-api Basically, if you have 2 pcie devices and 2 usb devices, it'll be represented by tflite like this:

    pci:0
    pci:1
    usb:0
    usb:1
    

    I guess this part is not well documented and requires putting @Green's answer regarding python and our documentation together. However, when you run the demo, instead of just giving the model path, you can also appends which devices you want this model to be ran on, for instance:

    python3 classify_image.py \
      --model models/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite@pci:0 \
      --labels models/inat_bird_labels.txt \
      --input images/parrot.jpg