当前位置:   article > 正文

torch与torchvision版本对应关系 & ImportError: cannot import name ‘QuantStub‘ from ‘torch.ao.quantization‘_torch1.10.0对应的torchvision

torch1.10.0对应的torchvision

torch与torchvision版本对应关系看下边的表格

兄弟们看看是不是报这个:

  File "xxxxxxxx/xxxxx/tools/train.py", line 10, in <module>
    from mmcv.runner import init_dist
  File "xxxxxxxx/.conda/envs/ga/lib/python3.7/site-packages/mmcv/runner/__init__.py", line 2, in <module>
    from .checkpoint import (_load_checkpoint, load_checkpoint, load_state_dict,
  File "xxxxxxxx/.conda/envs/ga/lib/python3.7/site-packages/mmcv/runner/checkpoint.py", line 11, in <module>
    import torchvision
  File "xxxxxxxx/.conda/envs/ga/lib/python3.7/site-packages/torchvision/__init__.py", line 7, in <module>
    from torchvision import models
  File "xxxxxxxx/.conda/envs/ga/lib/python3.7/site-packages/torchvision/models/__init__.py", line 18, in <module>
    from . import quantization
  File "xxxxxxxx/.conda/envs/ga/lib/python3.7/site-packages/torchvision/models/quantization/__init__.py", line 3, in <module>
    from .mobilenet import *
  File "xxxxxxxx/.conda/envs/ga/lib/python3.7/site-packages/torchvision/models/quantization/mobilenet.py", line 1, in <module>
    from .mobilenetv2 import *  # noqa: F401, F403
  File "xxxxxxxx/.conda/envs/ga/lib/python3.7/site-packages/torchvision/models/quantization/mobilenetv2.py", line 6, in <module>
    from torch.ao.quantization import QuantStub, DeQuantStub
ImportError: cannot import name 'QuantStub' from 'torch.ao.quantization'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

参考自:
https://forums.fast.ai/t/cannot-import-name-quantstub-from-torch-ao-quantization/94078/2

意思是可能 torchtorchvision 的版本不匹配

看下自己的版本

>>> import torch
>>> torch.__version__
'1.10.0+cu113'
  • 1
  • 2
  • 3

这样说明是在
https://download.pytorch.org/whl/torch_stable.html
下载的,如果没有 cu113 大概率pip或者conda下载的

  • 如果没有 cu113 就直接参考下边的表格,pip install torchvision==对应的版本 即可
torchtorchvisiontorchaudio
pytorch==1.12.0torchvision==0.13.0torchaudio==0.12.0
pytorch==1.11.0torchvision==0.12.0torchaudio==0.11.0
pytorch==1.10.1torchvision==0.11.2torchaudio==0.10.1
pytorch==1.10.0torchvision==0.11.0torchaudio==0.10.0
pytorch==1.9.1torchvision==0.10.1torchaudio==0.9.1
pytorch==1.9.0torchvision==0.10.0torchaudio==0.9.0
pytorch==1.8.1torchvision==0.9.1torchaudio==0.8.1
pytorch==1.8.0torchvision==0.9.0torchaudio==0.8.0
pytorch==1.7.1torchvision==0.8.2torchaudio==0.7.2
pytorch==1.7.0torchvision==0.8.0torchaudio==0.7.0
pytorch==1.6.0torchvision==0.7.0
pytorch==1.5.1torchvision==0.6.1
pytorch==1.5.0torchvision==0.6.0
pytorch==1.4.0torchvision==0.5.0
pytorch==1.2.0torchvision==0.4.0
pytorch==1.1.0torchvision==0.3.0

表格参考自:
https://pytorch.org/get-started/previous-versions/

比如我是 cuda11.2,那就找大于它但是最接近的版本,以及指定python版本,同时根据上述表格,找到torch1.10对应的torchvision版本0.11

在这里插入图片描述
下载这个 wheel 文件,pip 安装即可

如果不这样搞,直接 pip install torchvision==0.11 会报这个错:

Collecting torchvision==0.11
  Using cached torchvision-0.11.0-cp37-cp37m-manylinux1_x86_64.whl (23.3 MB)
Requirement already satisfied: numpy in /xxxxx/.conda/envs/ga/lib/python3.7/site-packages (from torchvision==0.11) (1.21.5)
ERROR: Could not find a version that satisfies the requirement torch==1.10.0+cu102 (from torchvision) (from versions: 1.0.0, 1.0.1, 1.0.1.post2, 1.1.0, 1.2.0, 1.3.0, 1.3.1, 1.4.0, 1.5.0, 1.5.1, 1.6.0, 1.7.0, 1.7.1, 1.8.0, 1.8.1, 1.9.0, 1.9.1, 1.10.0, 1.10.1, 1.10.2, 1.11.0, 1.12.0, 1.12.1)
ERROR: No matching distribution found for torch==1.10.0+cu102
  • 1
  • 2
  • 3
  • 4
  • 5
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/328415
推荐阅读
相关标签
  

闽ICP备14008679号