-1

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

user2864740
  • 60,010
  • 15
  • 145
  • 220
Aizzaac
  • 3,146
  • 8
  • 29
  • 61
  • do you have an example of the value of model_file? – njzk2 Aug 27 '20 at 21:02
  • 6
    That — “being a string separator” — is _all_ it does. How it affects code depends on the input string and expected output. If the model_file value does not contain a @ then the result of the split will be a _single string_. – user2864740 Aug 27 '20 at 21:03
  • 1
    @user2864740 a list with a single string, to be precise – DeepSpace Aug 27 '20 at 21:08
  • @njzk2 I do not know how to "open" it. It is a file that will be read by the TPU to classify images. It has what the algorithm has learnt. – Aizzaac Aug 27 '20 at 21:09

2 Answers2

2

The argument to string.split() is just a separator. It doesn't do anything else. If the separator doesn't appear in the string, then a singleton list gets returned: [string].

model_file, *device = model_file.split('@')

expects for model_file.split('@') to return a list, and assigns the first element of that list to model_file, and all subsequent elements to device (that's what the list-unpacking operator * does in this context).

If, as in this case, model_file.split('@') would return a list with only one element, then device would be an empty list [] after this line executes.

Green Cloak Guy
  • 23,793
  • 4
  • 33
  • 53
2

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
Nam Vu
  • 1,727
  • 1
  • 11
  • 24