KeyError Traceback (most recent call last)
/tmp/ipykernel_55387/1196496390.py in <cell line: 3>()
8 elif infer_mode == 'video':
9 video_path = 'racing.mp4'
---> 10 infer_video(video_path, model, labels_dict, cfg)
/tmp/ipykernel_55387/2968311708.py in infer_video(video_path, model, labels_dict, cfg)
96 break
97 # 对视频帧进行推理
---> 98 image_pred = infer_frame_with_vis(img_frame, model, labels_dict, cfg, bgr2rgb=True)
99 image_widget.value = img2bytes(image_pred)
100
/tmp/ipykernel_55387/2968311708.py in infer_frame_with_vis(image, model, labels_dict, cfg, bgr2rgb)
75 scale_coords(cfg['input_shape'], pred_all[:, :4], image.shape, ratio_pad=(scale_ratio, pad_size))
76 # 图片预测结果可视化
---> 77 img_vis = draw_bbox(pred_all, image, (0, 255, 0), 2, labels_dict)
78 return img_vis
79
/tmp/ipykernel_55387/2968311708.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: 4554
KeyError Traceback (most recent call last) /tmp/ipykernel_55387/1196496390.py in <cell line: 3>() 8 elif infer_mode == 'video': 9 video_path = 'racing.mp4' ---> 10 infer_video(video_path, model, labels_dict, cfg) /tmp/ipykernel_55387/2968311708.py in infer_video(video_path, model, labels_dict, cfg) 96 break 97 # 对视频帧进行推理 ---> 98 image_pred = infer_frame_with_vis(img_frame, model, labels_dict, cfg, bgr2rgb=True) 99 image_widget.value = img2bytes(image_pred) 100 /tmp/ipykernel_55387/2968311708.py in infer_frame_with_vis(image, model, labels_dict, cfg, bgr2rgb) 75 scale_coords(cfg['input_shape'], pred_all[:, :4], image.shape, ratio_pad=(scale_ratio, pad_size)) 76 # 图片预测结果可视化 ---> 77 img_vis = draw_bbox(pred_all, image, (0, 255, 0), 2, labels_dict) 78 return img_vis 79 /tmp/ipykernel_55387/2968311708.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: 4554我yolov8原模型使用yolov8m训练的,然后类别是三类bicycle motorcycle和person