torch.nn.modules.module.ModuleAttributeError: ‘Hardswish‘ object has no attribute ‘inplace‘

直接下载最新版的 yolov5 Docker镜像(2020年11月9日,v3.1版本)

1
2
REPOSITORY                   TAG                 IMAGE ID            CREATED             SIZE
yolov5                       latest              af9258862d62        8 days ago          13GB

进入容器后显示 tourch 版本

1
2
3
4
5
6
7
8
~$ docker run -it yolov5

=============
== PyTorch ==
=============

NVIDIA Release 20.10 (build 16972326)
PyTorch Version 1.7.0a0+7036e91

执行 detect,下载 yolov5s.pt

1
2
3
4
5
6
7
8
root@812eb89664fe:/usr/src/app# python detect.py
Namespace(agnostic_nms=False, augment=False, classes=None, conf_thres=0.25, device='', img_size=640, iou_thres=0.45, save_conf=False, save_dir='inference/output', save_txt=False, source='inference/images', update=False, view_img=False, weights='yolov5s.pt')
/opt/conda/lib/python3.6/site-packages/torch/cuda/__init__.py:52: UserWarning: CUDA initialization: Found no NVIDIA driver on your system. Please check that you have an NVIDIA GPU and installed a driver from http://www.nvidia.com/Download/index.aspx (Triggered internally at  ../c10/cuda/CUDAFunctions.cpp:100.)
  return torch._C._cuda_getDeviceCount() > 0
Using CPU

Downloading https://github.com/ultralytics/yolov5/releases/download/v3.0/yolov5s.pt to yolov5s.pt...
100%|██████████████████████████████████████████████████████████████████████| 14.5M/14.5M [00:18

然后报错了:
torch.nn.modules.module.ModuleAttributeError: ‘Hardswish’ object has no attribute 'inplace’
查看 pip list 安装包

torch 1.7.0a0+7036e91
torchtext 0.8.0a0
torchvision 0.8.0a0

分别把 torch 版本降到 1.6.0 、torchvision 版本降到 0.7.0

torch 1.6.0
torchtext 0.8.0a0
torchvision 0.7.0

执行检测,成功~

1
2
3
4
5
6
7
8
9
10
root@812eb89664fe:/usr/src/app# python detect.py
Namespace(agnostic_nms=False, augment=False, classes=None, conf_thres=0.25, device='', img_size=640, iou_thres=0.45, save_conf=False, save_dir='inference/output', save_txt=False, source='inference/images', update=False, view_img=False, weights='yolov5s.pt')
Using CPU

Fusing layers...
Model Summary: 140 layers, 7.45958e+06 parameters, 0 gradients
image 1/2 /usr/src/app/inference/images/bus.jpg: 640x480 4 persons, 1 buss, 1 skateboards, Done. (0.224s)
image 2/2 /usr/src/app/inference/images/zidane.jpg: 384x640 2 persons, 2 ties, Done. (0.125s)
Results saved to inference/output
Done. (0.430s)