yolov5 编译问题:
python3 detect.py --source 0
出现:
detect: weights=yolov5s.pt, source=0, data=data/coco128.yaml, imgsz=[640, 640], conf_thres=0.25, iou_thres=0.45, max_det=1000, device=, view_img=False, save_txt=False, save_conf=False, save_crop=False, nosave=False, classes=None, agnostic_nms=False, augment=False, visualize=False, update=False, project=runs/detect, name=exp, exist_ok=False, line_thickness=3, hide_labels=False, hide_conf=False, half=False, dnn=False
YOLOv5 v6.0-266-g07221f1 torch 1.11.0+cu102 CUDA:0 (NVIDIA GeForce RTX 2060, 5935MiB)
Fusing layers...
Model Summary: 213 layers, 7225885 parameters, 0 gradients
1/1: 0... Success (inf frames 640x480 at 30.00 FPS)
Traceback (most recent call last):
File "detect.py", line 257, in
main(opt)
File "detect.py", line 252, in main
run(**vars(opt))
File "/home/xxx/.local/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "detect.py", line 113, in run
model.warmup(imgsz=(1 if pt else bs, 3, *imgsz), half=half) # warmup
File "/home/xxx/yolov5/models/common.py", line 459, in warmup
self.forward(im) # warmup
File "/home/xxx/yolov5/models/common.py", line 399, in forward
y = self.model(im) if self.jit else self.model(im, augment=augment, visualize=visualize)
File "/home/xxx/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
return forward_call(*input, **kwargs)
File "/home/xxx/yolov5/models/yolo.py", line 126, in forward
return self._forward_once(x, profile, visualize) # single-scale inference, train
File "/home/xxx/yolov5/models/yolo.py", line 149, in _forward_once
x = m(x) # run
File "/home/xxx/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
return forward_call(*input, **kwargs)
File "/home/xxx/.local/lib/python3.8/site-packages/torch/nn/modules/upsampling.py", line 154, in forward
recompute_scale_factor=self.recompute_scale_factor)
File "/home/xxx/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1185, in __getattr__
raise AttributeError("'{}' object has no attribute '{}'".format(
AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor'
解决方案:
...\torch\nn\modules\upsampling.py #torch文件
修改:
def forward(self, input: Tensor) -> Tensor:
return F.interpolate(input, self.size, self.scale_factor, self.mode, self.align_corners,
recompute_scale_factor=self.recompute_scale_factor
)
结果:
def forward(self, input: Tensor) -> Tensor:
return F.interpolate(input, self.size, self.scale_factor, self.mode, self.align_corners,
#recompute_scale_factor=self.recompute_scale_factor
)
原因:
torch高版本特性问题
也可以安装低版本torch解决