python - 升级到 PyTorch 1.9 时的潜在错误 ImportError : cannot import name 'int_classes' from 'torch._six'

标签 python import deep-learning pytorch six

我安装了 PyTorch 使用

$ pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html
I get this error:
(proxy) [jalal@goku proxynca_pp]$ CUDA_VISIBLE_DEVICES=0,1 python train.py --dataset cub  --config config/cub.json --mode train --apex --seed 0
Traceback (most recent call last):
  File "train.py", line 3, in <module>
    import dataset
  File "/scratch3/research/code/fashion/proxynca_pp/dataset/__init__.py", line 6, in <module>
    from . import utils
  File "/scratch3/research/code/fashion/proxynca_pp/dataset/utils.py", line 8, in <module>
    from torch._six import int_classes as _int_classes
ImportError: cannot import name 'int_classes' from 'torch._six' (/scratch3/venv/proxy/lib/python3.8/site-packages/torch/_six.py)

代码来自this GitHub repo 。 我应该更改代码中的哪些内容才能使其正常工作?

(proxy) [jalal@goku proxynca_pp]$ pip freeze
h5py==3.4.0
numpy==1.21.2
Pillow==8.3.2
scipy==1.7.1
torch==1.9.0+cu111
torchaudio==0.9.0
torchvision==0.10.0+cu111
tqdm==4.62.2
typing-extensions==3.10.0.2

最佳答案

最简单的解决方案是仅设置 int_classes = int,而不是从 _six 导入它。

关于python - 升级到 PyTorch 1.9 时的潜在错误 ImportError : cannot import name 'int_classes' from 'torch._six' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69170518/

相关文章:

python - 带有图像的 numpy vstack

java - 导入 Java 或其他语言,根据给定数据生成流程图

MySQL 加载数据 infile ("NULL"CSV 中日期时间的字符串)

python-3.x - Keras Inception-V3 模型预测还很遥远

python - Python 中的 Jupyter Lab 中不显示 Plotly 表?

python - 在 Python 中打印浮点值(Mapbox 地理坐标)

python - PIL 值错误 : Images do not match

python - Python 导入时出错

python - 使用 Keras 的卷积神经网络中始终进行相同二元类预测的原因和可能的解决方案是什么?

neural-network - 终端输出重定向不适用于 Caffe