KeyError Traceback (most recent call last)
/tmp/ipykernel_214092/255244600.py in <cell line: 3>()
3 if infer_mode == 'image':
4 img_path = '2022-08-24 211605.jpg'
----> 5 infer_image(img_path, model, labels_dict, cfg)
6 elif infer_mode == 'camera':
7 infer_camera(model, labels_dict, cfg)
/tmp/ipykernel_214092/3987123467.py in infer_image(img_path, model, class_names, cfg)
60 scale_coords(cfg['input_shape'], pred_all[:, :4], image.shape, ratio_pad=(scale_ratio, pad_size))
61 # 图片预测结果可视化
---> 62 draw_prediction(pred_all, image, class_names)
63
64
/tmp/ipykernel_214092/3987123467.py in draw_prediction(pred, image, labels)
39 """在图片上画出预测框并进行可视化展示"""
40 imgbox = widgets.Image(format='jpg', height=720, width=1280)
---> 41 img_dw = draw_bbox(pred, image, (0, 255, 0), 2, labels)
42 imgbox.value = cv2.imencode('.jpg', img_dw)[1].tobytes()
43 display(imgbox)
/tmp/ipykernel_214092/3987123467.py in draw_bbox(bbox, img0, color, wt, names)
17 img0 = cv2.rectangle(img0, (int(bbox[idx][0]), int(bbox[idx][1])), (int(bbox[idx][2]), int(bbox[idx][3])),
18 color, wt)
---> 19 img0 = cv2.putText(img0, str(idx) + ' ' + names[int(class_id)], (int(bbox[idx][0]), int(bbox[idx][1] + 16)),
20 cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 1)
21 img0 = cv2.putText(img0, '{:.4f}'.format(bbox[idx][4]), (int(bbox[idx][0]), int(bbox[idx][1] + 32)),
KeyError: 8046
cfg = {
'conf_thres': 0.4, # 模型置信度阈值,阈值越低,得到的预测框越多
'iou_thres': 0.5, # IOU阈值,高于这个阈值的重叠预测框会被过滤掉
'input_shape': [640, 640], # 模型输入尺寸
}
其他都是板子自带的代码
model_path = 'yolo_trans.om'
label_path = 'data.txt'
# 初始化推理模型
model = InferSession(0, model_path)
labels_dict = get_labels_from_txt(label_path)
KeyError Traceback (most recent call last) /tmp/ipykernel_214092/255244600.py in <cell line: 3>() 3 if infer_mode == 'image': 4 img_path = '2022-08-24 211605.jpg' ----> 5 infer_image(img_path, model, labels_dict, cfg) 6 elif infer_mode == 'camera': 7 infer_camera(model, labels_dict, cfg) /tmp/ipykernel_214092/3987123467.py in infer_image(img_path, model, class_names, cfg) 60 scale_coords(cfg['input_shape'], pred_all[:, :4], image.shape, ratio_pad=(scale_ratio, pad_size)) 61 # 图片预测结果可视化 ---> 62 draw_prediction(pred_all, image, class_names) 63 64 /tmp/ipykernel_214092/3987123467.py in draw_prediction(pred, image, labels) 39 """在图片上画出预测框并进行可视化展示""" 40 imgbox = widgets.Image(format='jpg', height=720, width=1280) ---> 41 img_dw = draw_bbox(pred, image, (0, 255, 0), 2, labels) 42 imgbox.value = cv2.imencode('.jpg', img_dw)[1].tobytes() 43 display(imgbox) /tmp/ipykernel_214092/3987123467.py in draw_bbox(bbox, img0, color, wt, names) 17 img0 = cv2.rectangle(img0, (int(bbox[idx][0]), int(bbox[idx][1])), (int(bbox[idx][2]), int(bbox[idx][3])), 18 color, wt) ---> 19 img0 = cv2.putText(img0, str(idx) + ' ' + names[int(class_id)], (int(bbox[idx][0]), int(bbox[idx][1] + 16)), 20 cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 1) 21 img0 = cv2.putText(img0, '{:.4f}'.format(bbox[idx][4]), (int(bbox[idx][0]), int(bbox[idx][1] + 32)), KeyError: 8046cfg = {
'conf_thres': 0.4, # 模型置信度阈值,阈值越低,得到的预测框越多
'iou_thres': 0.5, # IOU阈值,高于这个阈值的重叠预测框会被过滤掉
'input_shape': [640, 640], # 模型输入尺寸
}
其他都是板子自带的代码
model_path = 'yolo_trans.om'
label_path = 'data.txt'
# 初始化推理模型
model = InferSession(0, model_path)
labels_dict = get_labels_from_txt(label_path)