lenLRX / Atlas_ACL_E2E_Demo

188 stars 38 forks source link

AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor' #50

Closed MichaelToLearn closed 1 year ago

MichaelToLearn commented 1 year ago

按照 https://github.com/lenLRX/Atlas_ACL_E2E_Demo/blob/master/yolov5_model_cvt.md 这个教程转换,使用的是虚拟环境,结果报错:

(venv) ➜  yolov5 git:(v6.0) python export.py --include onnx --weights yolov5s.pt --img 640 --batch 1 --opset=11
/home/HwHiAiUser/username/models/yolov5/yolov5_for_e2e_demo/yolov5/venv/lib/python3.7/site-packages/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension:
  warn(f"Failed to load image Python extension: {e}")
export: data=data/coco128.yaml, weights=yolov5s.pt, imgsz=[640], batch_size=1, device=cpu, half=False, inplace=False, train=False, optimize=False, int8=False, dynamic=False, simplify=False, opset=11, topk_per_class=100, topk_all=100, iou_thres=0.45, conf_thres=0.25, include=['onnx']
YOLOv5 🚀 v6.0-0-g956be8e torch 1.13.1 CPU

Downloading https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5s.pt to yolov5s.pt...
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████| 14.1M/14.1M [00:01<00:00, 7.85MB/s]

Fusing layers...
Model Summary: 213 layers, 7225885 parameters, 0 gradients
Traceback (most recent call last):
  File "export.py", line 364, in <module>
    main(opt)
  File "export.py", line 359, in main
    run(**vars(opt))
  File "/home/HwHiAiUser/username/models/yolov5/yolov5_for_e2e_demo/yolov5/venv/lib/python3.7/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "export.py", line 299, in run
    y = model(im)  # dry runs
  File "/home/HwHiAiUser/username/models/yolov5/yolov5_for_e2e_demo/yolov5/venv/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/HwHiAiUser/username/models/yolov5/yolov5_for_e2e_demo/yolov5/models/yolo.py", line 126, in forward
    return self._forward_once(x, profile, visualize)  # single-scale inference, train
  File "/home/HwHiAiUser/username/models/yolov5/yolov5_for_e2e_demo/yolov5/models/yolo.py", line 149, in _forward_once
    x = m(x)  # run
  File "/home/HwHiAiUser/username/models/yolov5/yolov5_for_e2e_demo/yolov5/venv/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/HwHiAiUser/username/models/yolov5/yolov5_for_e2e_demo/yolov5/venv/lib/python3.7/site-packages/torch/nn/modules/upsampling.py", line 157, in forward
    recompute_scale_factor=self.recompute_scale_factor)
  File "/home/HwHiAiUser/username/models/yolov5/yolov5_for_e2e_demo/yolov5/venv/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1270, in __getattr__
    type(self).__name__, name))
AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor
lenLRX commented 1 year ago

两种解决方式: 降级pytorch 版本: pip install torchvision==0.10.1 pip install torch==1.9.1

或者改pytorch代码 https://zhuanlan.zhihu.com/p/545926241

MichaelToLearn commented 1 year ago

没有这两个版本呢

(venv) ➜  yolov5 pip install torchvision==0.10.1
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
ERROR: Could not find a version that satisfies the requirement torchvision==0.10.1 (from versions: 0.1.6, 0.1.7, 0.1.8, 0.1.9, 0.2.0, 0.2.1, 0.2.2, 0.2.2.post2, 0.2.2.post3, 0.9.1, 0.10.0, 0.11.1, 0.11.2, 0.11.3, 0.12.0, 0.13.0, 0.13.1, 0.14.0, 0.14.1)
ERROR: No matching distribution found for torchvision==0.10.1
(venv) ➜  yolov5 pip install torch==1.9.1
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
ERROR: Could not find a version that satisfies the requirement torch==1.9.1 (from versions: 1.8.0, 1.8.1, 1.9.0, 1.10.0, 1.10.1, 1.10.2, 1.11.0, 1.12.0, 1.12.1, 1.13.0, 1.13.1)
ERROR: No matching distribution found for torch==1.9.1
MichaelToLearn commented 1 year ago

试了试这两个版本:

pip install torch==1.9.0
pip install torchvision==0.10.0

结果是可以转换出来 onxx 的。