YOLOv5報錯:AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor' 的解決方案
阿新 • • 發佈:2022-03-17
YOLOv5報錯:AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor' 的解決方案
錯誤程式碼:
File "E:/PycharmProjects/yolo-flask-html/detect.py", line 182, in <module> detect() File "E:/PycharmProjects/yolo-flask-html/detect.py", line 61, in detect model(torch.zeros(1, 3, imgsz, imgsz).to(device).type_as(next(model.parameters()))) # run once File "E:\Anaconda3\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 1110, in _call_impl return forward_call(*input, **kwargs) File "E:\PycharmProjects\yolo-flask-html\models\yolo.py", line 123, in forward return self.forward_once(x, profile) # single-scale inference, train File "E:\PycharmProjects\yolo-flask-html\models\yolo.py", line 139, in forward_once x = m(x) # run File "E:\Anaconda3\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 1110, in _call_impl return forward_call(*input, **kwargs) File "E:\Anaconda3\envs\pytorch\lib\site-packages\torch\nn\modules\upsampling.py", line 154, in forward recompute_scale_factor=self.recompute_scale_factor) File "E:\Anaconda3\envs\pytorch\lib\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'
解決方案:
降低PyTorch的版本到1.9.0,PyTorch的歷史版本Previous PyTorch Versions | PyTorch
# CUDA 10.2 conda install pytorch==1.9.0 torchvision==0.10.0 torchaudio==0.9.0 cudatoolkit=10.2 -c pytorch # CUDA 11.3 conda install pytorch==1.9.0 torchvision==0.10.0 torchaudio==0.9.0 cudatoolkit=11.3 -c pytorch -c conda-forge # CPU Only conda install pytorch==1.9.0 torchvision==0.10.0 torchaudio==0.9.0 cpuonly -c pytorch