Python 在边缘TPU上运行MNIST示例时发生ValueError
我尝试使用MNIST数据集在Coral DevBoard上使用我的第一个神经网络。我已通过以下步骤完成此操作:Python 在边缘TPU上运行MNIST示例时发生ValueError,python,python-3.x,tensorflow,mnist,google-coral,Python,Python 3.x,Tensorflow,Mnist,Google Coral,我尝试使用MNIST数据集在Coral DevBoard上使用我的第一个神经网络。我已通过以下步骤完成此操作: 我使用来自的指南生成量化模型 然后,我使用edgetpu_编译器(版本15.0.340273435)为我的edge tpu生成模型: 我在开发板上复制模型并生成Labels.txt: 我从中复制了示例脚本 从MNIST数据集中下载图像 使用以下命令运行脚本: 我发现了错误 Traceback (most recent call last): File "
- 我使用来自的指南生成量化模型
- 然后,我使用
(版本edgetpu_编译器
)为我的edge tpu生成模型:15.0.340273435
- 我在开发板上复制模型并生成
:Labels.txt
- 我从中复制了示例脚本
- 从MNIST数据集中下载图像
- 使用以下命令运行脚本:
Traceback (most recent call last):
File "Classify.py", line 43, in <module>
main()
File "Classify.py", line 25, in main
size = common.input_size(interpreter)
File "/usr/lib/python3/dist-packages/pycoral/adapters/common.py", line 52, in input_size
_, height, width, _ = input_details(interpreter, 'shape')
ValueError: not enough values to unpack (expected 4, got 3)
回溯(最近一次呼叫最后一次):
文件“Classify.py”,第43行,在
main()
文件“Classify.py”,第25行,在main中
大小=通用。输入大小(解释器)
文件“/usr/lib/python3/dist packages/pycoral/adapters/common.py”,第52行,输入大小
_,高度,宽度,u=输入_详细信息(解释器,“形状”)
ValueError:没有足够的值来解包(预期值为4,实际值为3)
这个错误是什么意思?我如何修复它?看起来Coral希望您的模型输入有4个维度
[批次、高度、宽度、通道]
,而您的模型输入只有3个维度。因此我认为我必须修改模型的训练?解释器需要返回4个值,但您的模型只返回3个值。
0 0
...
9 9
import time
import argparse
from PIL import Image
from pycoral.adapters import classify
from pycoral.adapters import common
from pycoral.utils.dataset import read_label_file
from pycoral.utils.edgetpu import make_interpreter
def main():
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("-m", "--model", required = True, help = "File path of .tflite file.")
parser.add_argument("-i", "--input", required = True, help = "Image to be classified.")
parser.add_argument("-l", "--labels", help = "File path of labels file.")
parser.add_argument("-k", "--top_k", type = int, default = 1, help = "Max number of classification results")
parser.add_argument("-t", "--threshold", type = float, default = 0.0, help = "Classification score threshold")
parser.add_argument("-c", "--count", type = int, default = 5, help = "Number of times to run inference")
args = parser.parse_args()
labels = read_label_file(args.labels) if args.labels else {}
interpreter = make_interpreter(*args.model.split("@"))
interpreter.allocate_tensors()
size = common.input_size(interpreter)
image = Image.open(args.input).convert("RGB").resize(size, Image.ANTIALIAS)
common.set_input(interpreter, image)
print("----INFERENCE TIME----")
print("Note: The first inference on Edge TPU is slow because it includes", "loading the model into Edge TPU memory.")
for _ in range(args.count):
start = time.perf_counter()
interpreter.invoke()
inference_time = time.perf_counter() - start
classes = classify.get_classes(interpreter, args.top_k, args.threshold)
print("%.1fms" % (inference_time * 1000))
print("-------RESULTS--------")
for c in classes:
print("%s: %.5f" % (labels.get(c.id, c.id), c.score))
if(__name__ == "__main__"):
main()
python3 Classify.py --model mnist_model_quant_edgetpu.tflite --labels Labels.txt --input img_1.jpg
Traceback (most recent call last):
File "Classify.py", line 43, in <module>
main()
File "Classify.py", line 25, in main
size = common.input_size(interpreter)
File "/usr/lib/python3/dist-packages/pycoral/adapters/common.py", line 52, in input_size
_, height, width, _ = input_details(interpreter, 'shape')
ValueError: not enough values to unpack (expected 4, got 3)