YOLOv5报错:AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘ 的解决方案

YOLOv5报错:AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor' 的解决方案

错误代码:

File "E:/PycharmProjects/yolo-flask-html/detect.py", line 182, in 
    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

你可能感兴趣的:(YOLOV5,Python,pytorch,深度学习,python)