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'
参考自:
https://forums.fast.ai/t/cannot-import-name-quantstub-from-torch-ao-quantization/94078/2
意思是可能 torch
和 torchvision
的版本不匹配
看下自己的版本
>>> import torch
>>> torch.__version__
'1.10.0+cu113'
这样说明是在
https://download.pytorch.org/whl/torch_stable.html
下载的,如果没有 cu113
大概率pip或者conda下载的
cu113
就直接参考下边的表格,pip install torchvision==对应的版本
即可torch | torchvision | torchaudio |
---|---|---|
pytorch==1.12.0 | torchvision==0.13.0 | torchaudio==0.12.0 |
pytorch==1.11.0 | torchvision==0.12.0 | torchaudio==0.11.0 |
pytorch==1.10.1 | torchvision==0.11.2 | torchaudio==0.10.1 |
pytorch==1.10.0 | torchvision==0.11.0 | torchaudio==0.10.0 |
pytorch==1.9.1 | torchvision==0.10.1 | torchaudio==0.9.1 |
pytorch==1.9.0 | torchvision==0.10.0 | torchaudio==0.9.0 |
pytorch==1.8.1 | torchvision==0.9.1 | torchaudio==0.8.1 |
pytorch==1.8.0 | torchvision==0.9.0 | torchaudio==0.8.0 |
pytorch==1.7.1 | torchvision==0.8.2 | torchaudio==0.7.2 |
pytorch==1.7.0 | torchvision==0.8.0 | torchaudio==0.7.0 |
pytorch==1.6.0 | torchvision==0.7.0 | |
pytorch==1.5.1 | torchvision==0.6.1 | |
pytorch==1.5.0 | torchvision==0.6.0 | |
pytorch==1.4.0 | torchvision==0.5.0 | |
pytorch==1.2.0 | torchvision==0.4.0 | |
pytorch==1.1.0 | torchvision==0.3.0 |
表格参考自:
https://pytorch.org/get-started/previous-versions/
cu113
之类指定 cuda 版本的,那只能从这个网站下载了比如我是 cuda11.2,那就找大于它但是最接近的版本,以及指定python版本,同时根据上述表格,找到torch1.10
对应的torchvision版本0.11
如果不这样搞,直接 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