我正在尝试使用 Google Goral Edge TPU USB 设备评估 Raspberry Pi 的性能,而没有它对视频文件的图像分类任务。我已经设法使用 Edge TPU USB 设备评估了性能。但是,当我尝试运行 tensorflow lite 代码来运行推理时,它会出现一个错误,告诉我需要插入设备:
ValueError: Failed to load delegate from libedgetpu.so.1
我具体做的是使用珊瑚设备对视频进行推理,并保存视频中的每一帧以对硬件进行基准测试。
import argparse
import time
import cv2
import numpy as np
from pycoral.adapters import classify, common
from pycoral.utils.dataset import read_label_file
from pycoral.utils.edgetpu import make_interpreter
from utils import visualization as visual
WINDOW_NAME = "Edge TPU Image classification"
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--model", help="File path of Tflite model.", required=True)
parser.add_argument("--label", help="File path of label file.", required=True)
parser.add_argument("--top_k", help="keep top k candidates.", default=2, type=int)
parser.add_argument("--threshold", help="Score threshold.", default=0.0, type=float)
parser.add_argument("--width", help="Resolution width.", default=640, type=int)
parser.add_argument("--height", help="Resolution height.", default=480, type=int)
parser.add_argument("--videopath", help="File path of Videofile.", default="")
args = parser.parse_args()
# Initialize window.
cv2.namedWindow(WINDOW_NAME)
cv2.moveWindow(WINDOW_NAME, 100, 200)
# Initialize engine and load labels.
count = 0
interpreter = make_interpreter(args.model)
interpreter.allocate_tensors()
labels = read_label_file(args.label) if args.label else None
elapsed_list = []
cap = cv2.VideoCapture('/home/pi/coral-usb/pycoral/test_data/video.mkv)
while cap.isOpened():
_, frame = cap.read()
im = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
cv2.imwrite("/home/pi/Desktop/frames/frame_%d.jpeg" % count, frame)
print('gravou o frame_%d'% count, frame)
cv2.imshow('Frame', frame)
cap_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
cap_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
# Run inference.
start = time.perf_counter()
_, scale = common.set_resized_input(
interpreter, (cap_width, cap_height), lambda size: cv2.resize(im, size)
)
interpreter.invoke()
# Check result.
results = classify.get_classes(interpreter, args.top_k, args.threshold)
elapsed_ms = (time.perf_counter() - start) * 1000
if results:
for i in range(len(results)):
label = "{0} ({1:.2f})".format(labels[results[i][0]], results[i][1])
pos = 60 + (i * 30)
visual.draw_caption(frame, (10, pos), label)
# display
cv2.imshow(WINDOW_NAME, frame)
if cv2.waitKey(10) & 0xFF == ord("q"):
break
此代码用于使用珊瑚设备运行推理。我想知道如何在没有珊瑚的情况下做同样的事情?我想测试使用我的模型有和没有边缘 tpu usb 设备之间的差异。
最后,我尝试使用 tensorflow lite从这个链接进行图像分类。但是,我收到以下错误:
RuntimeError: Encountered unresolved custom op: edgetpu-custom-op.Node number 0 (edgetpu-custom-op) 准备失败。