导入错误:无法从“torch.ao.quantization”导入名称“QuantStub”

问题描述 投票:0回答:3

导入错误:无法从“torch.ao.quantization”导入名称“QuantStub”。我正在调用 histocartography python 包中的函数

/vol/ideadata/oc69ubiw/conda/pathoexplainer/lib/python3.10/site-packages/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension: /vol/ideadata/oc69ubiw/conda/pathoexplainer/lib/python3.10/site-packages/torchvision/image.so: undefined symbol: _ZN3c106detail19maybe_wrap_dim_slowEllb
warn(f"Failed to load image Python extension: {e}")
Traceback (most recent call last):
 File "/vol/ideadata/oc69ubiw/Explainer_GNN/patho-quant-explainer/core/generate_cell_graphs.py", line 14, in <module>
from histocartography.preprocessing import (
 File "/vol/ideadata/oc69ubiw/conda/pathoexplainer/lib/python3.10/site-packages/histocartography/preprocessing/__init__.py", line 2, in <module>
from .feature_extraction import HandcraftedFeatureExtractor
 File "/vol/ideadata/oc69ubiw/conda/pathoexplainer/lib/python3.10/site-packages/histocartography/preprocessing/feature_extraction.py", line 13, in <module>
import torchvision
 File "/vol/ideadata/oc69ubiw/conda/pathoexplainer/lib/python3.10/site-packages/torchvision/__init__.py", line 7, in <module>
from torchvision import models
 File "/vol/ideadata/oc69ubiw/conda/pathoexplainer/lib/python3.10/site-packages/torchvision/models/__init__.py", line 18, in <module>
from . import quantization
 File "/vol/ideadata/oc69ubiw/conda/pathoexplainer/lib/python3.10/site-packages/torchvision/models/quantization/__init__.py", line 3, in <module>
from .mobilenet import *
 File "/vol/ideadata/oc69ubiw/conda/pathoexplainer/lib/python3.10/site-packages/torchvision/models/quantization/mobilenet.py", line 1, in <module>
from .mobilenetv2 import *  # noqa: F401, F403
 File "/vol/ideadata/oc69ubiw/conda/pathoexplainer/lib/python3.10/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' (/vol/ideadata/oc69ubiw/conda/pathoexplainer/lib/python3.10/site-packages/torch/ao/quantization/__init__.py)
importerror
3个回答
2
投票

我也有同样的错误。 重新安装/更新 PyTorch 修复了该问题。似乎得到了https://discuss.pytorch.org/t/cannot-import-name-quantstub-from-torch-ao-quantization/158979/2的支持。 Jerry 张提到“...我们正在弃用

torch.quantization
命名空间,而
torch.ao.quantization
是推荐的”。


1
投票

2023年4月:我的系统和conda环境配置是

CUDA 11.4
Python 3.9.13
。只需更新
pytorch
torchvision
版本

pip install --upgrade torch torchvision

0
投票

升级成功,上面评论的答案解决了问题。

pip install --升级torch torchvision

© www.soinside.com 2019 - 2024. All rights reserved.