使用jetson agx xavier测试训练yolo5.6,得到权重文件pt模型使用USB摄像头测试报错
python3 detect.py --weights runs/train/exp16/weights/best.pt --source 0
Matplotlib created a temporary config/cache directory at /tmp/matplotlib-q3eugw7s because the default path (/home/nvidia/.cache/matplotlib) is not a writable directory; it is highly recommended to set the MPLCONFIGDIR environment variable to a writable directory, in particular to speed up the import of Matplotlib and to better support multiprocessing.
Namespace(agnostic_nms=False, augment=False, classes=None, conf_thres=0.25, device='', exist_ok=False, img_size=640, iou_thres=0.45, name='exp', nosave=False, project='runs/detect', save_conf=False, save_txt=False, source='0', update=False, view_img=False, weights=['runs/train/exp16/weights/best.pt'])
YOLOv5 🚀 v5.0-0-gf5b8f7d5 torch 1.9.0 CUDA:0 (Xavier, 31928.53515625MB)Fusing layers...
/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py:718: UserWarning: Named tensors and all their associated APIs are an experimental feature and subject to change. Please do not use them for anything important until they are released as stable. (Triggered internally at /media/nvidia/NVME/pytorch/pytorch-v1.9.0/c10/core/TensorImpl.h:1156.)
return torch.max_pool2d(input, kernel_size, stride, padding, dilation, ceil_mode)
Model Summary: 392 layers, 47025981 parameters, 0 gradients, 115.3 GFLOPS
Xlib: extension "RANDR" missing on display "localhost:10.0".
1/1: 0... Traceback (most recent call last):
File "detect.py", line 178, in <module>
detect()
File "detect.py", line 51, in detect
dataset = LoadStreams(source, img_size=imgsz, stride=stride)
File "/home/nvidia/yolov5/utils/datasets.py", line 279, in __init__
if 'youtube.com/' in url or 'youtu.be/' in url: # if source is YouTube video
TypeError: argument of type 'int' is not iterable
279 if 'youtube.com/' in str(url) or 'youtu.be/' in str(url): # if source is YouTube video
将219行改成如上即可
参考过另外一个方法对我这个没生效,你不介意的话可以看下(2条消息) 【目标检测】YOLOv5 5.0调用摄像头报错的处理_Cul_accino的博客-CSDN博客_yolo检测调用摄像头fps
然后,为了显示实时FPS,需要修改以下两个文件:
utils/datasets.py
337 # return self.sources, img, img0, None
338 return self.sources, img, img0, self.fps
detect.py
# Stream results
119 if view_img: #实时显示当前FPS 1000 /
120 cv2.putText(im0,"YOLOV5 FPS: {0}".format(float('%.3f' % (1 / (t2 - t1)))),(100,50),cv2.FONT_HERSHEY_SIMPLEX,1.5,(30,144,255),3)
121 cv2.imshow(str(p), im0)
122 cv2.waitKey(1) # 1 millisecond
123
124 # Save results (image with detections)
125 if save_img:
126 if dataset.mode == 'image':
127 cv2.imwrite(save_path, im0)
128 else: # 'video' or 'stream'
129 if vid_path != save_path: # new video
130 vid_path = save_path
131 if isinstance(vid_writer, cv2.VideoWriter):
132 vid_writer.release() # release previous video writer
133 #if vid_cap:# video
134 if not vid_cap: #video加个not取反
135 fps = vid_cap.get(cv2.CAP_PROP_FPS)
136 w = int(vid_cap.get(cv2.CAP_PROP_FRAME_WIDTH))
137 h = int(vid_cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
138 else: # stream
139 fps, w, h = 30, im0.shape[1], im0.shape[0]
140 save_path += '.mp4'
141 vid_writer = cv2.VideoWriter(save_path, cv2.VideoWriter_fourcc(*'mp4v'), fps, (w, h))
142 vid_writer.write(im0)
下一篇试下加速