split('@') 中的 @ 除了作为字符串分隔符之外还有什么作用?
What does the @ in split('@') do besides from being a string separator?
我正在使用 Coral 开发板来加速 AI 模型。
我不明白 '@'
是什么意思。
split
returns 使用指定 'separator' 的字符串中所有单词的列表。但是我的模型文件的名称没有'@'。
似乎正在为模型文件分配委托。
模型名称=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 {})
])
谢谢
string.split()
的参数只是一个分隔符。它没有做任何其他事情。如果分隔符没有出现在字符串中,那么单例列表会得到 returned:[string]
.
model_file, *device = model_file.split('@')
期望 model_file.split('@')
到 return 一个列表,并将该列表的第一个元素分配给 model_file
,并将所有后续元素分配给 device
(这就是 在这种情况下确实如此)。
如果在这种情况下,model_file.split('@')
将 return 一个只有一个元素的列表,那么 device
将是一个空列表 []
在该行执行后.
对投票表示歉意,我是 google-coral 团队的 Nam,投票来自 Whosebug 用户而不是我们。你确实有一个可靠的问题,我支持@Green Cloak Guy 的回答,但是为了进一步扩展这个问题:
在我们关于将多个 tpus 与 tflite 结合使用的文档中 API,您可以指定要在哪个设备上加载此模型:https://coral.ai/docs/edgetpu/multiple-edgetpu/#using-the-tensorflow-lite-python-api
基本上,如果你有 2 个 pcie 设备和 2 个 usb 设备,它将由 tflite 表示,如下所示:
pci:0
pci:1
usb:0
usb:1
我想这部分没有很好的文档记录,需要将@Green 关于 python 的回答和我们的文档放在一起。但是,当您 运行 演示时,您不仅可以提供模型路径,还可以附加您希望此模型 运行 在哪些设备上,例如:
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
我正在使用 Coral 开发板来加速 AI 模型。
我不明白 '@'
是什么意思。
split
returns 使用指定 'separator' 的字符串中所有单词的列表。但是我的模型文件的名称没有'@'。
似乎正在为模型文件分配委托。
模型名称=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 {})
])
谢谢
string.split()
的参数只是一个分隔符。它没有做任何其他事情。如果分隔符没有出现在字符串中,那么单例列表会得到 returned:[string]
.
model_file, *device = model_file.split('@')
期望 model_file.split('@')
到 return 一个列表,并将该列表的第一个元素分配给 model_file
,并将所有后续元素分配给 device
(这就是
如果在这种情况下,model_file.split('@')
将 return 一个只有一个元素的列表,那么 device
将是一个空列表 []
在该行执行后.
对投票表示歉意,我是 google-coral 团队的 Nam,投票来自 Whosebug 用户而不是我们。你确实有一个可靠的问题,我支持@Green Cloak Guy 的回答,但是为了进一步扩展这个问题:
在我们关于将多个 tpus 与 tflite 结合使用的文档中 API,您可以指定要在哪个设备上加载此模型:https://coral.ai/docs/edgetpu/multiple-edgetpu/#using-the-tensorflow-lite-python-api 基本上,如果你有 2 个 pcie 设备和 2 个 usb 设备,它将由 tflite 表示,如下所示:
pci:0
pci:1
usb:0
usb:1
我想这部分没有很好的文档记录,需要将@Green 关于 python 的回答和我们的文档放在一起。但是,当您 运行 演示时,您不仅可以提供模型路径,还可以附加您希望此模型 运行 在哪些设备上,例如:
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