ImportError: cannot import name ‘container_abcs‘ from ‘torch._six‘
Posted AI浩
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ImportError: cannot import name ‘container_abcs‘ from ‘torch._six‘相关的知识,希望对你有一定的参考价值。
问题描述
在使用apex的过程中,出现了如下问题:
File "/home/shuyuan/yolov5-master/./fast_reid/fastreid/engine/train_loop.py", line 14, in <module>
from apex import amp
File "/home/shuyuan/anaconda3/envs/shuyuan/lib/python3.8/site-packages/apex/__init__.py", line 7, in <module>
from . import amp
File "/home/shuyuan/anaconda3/envs/shuyuan/lib/python3.8/site-packages/apex/amp/__init__.py", line 1, in <module>
from .amp import init, half_function, float_function, promote_function,\\
File "/home/shuyuan/anaconda3/envs/shuyuan/lib/python3.8/site-packages/apex/amp/amp.py", line 1, in <module>
from . import compat, rnn_compat, utils, wrap
File "/home/shuyuan/anaconda3/envs/shuyuan/lib/python3.8/site-packages/apex/amp/rnn_compat.py", line 1, in <module>
from . import utils, wrap
File "/home/shuyuan/anaconda3/envs/shuyuan/lib/python3.8/site-packages/apex/amp/wrap.py", line 3, in <module>
from ._amp_state import _amp_state
File "/home/shuyuan/anaconda3/envs/shuyuan/lib/python3.8/site-packages/apex/amp/_amp_state.py", line 14, in <module>
from torch._six import container_abcs
ImportError: cannot import name 'container_abcs' from 'torch._six' (/home/shuyuan/anaconda3/envs/shuyuan/lib/python3.8/site-packages/torch/_six.py)
解决方法
找到问题所在的文件,将这部分的代码用下面的代码替换
if TORCH_MAJOR == 1 and TORCH_MINOR < 8:
from torch._six import container_abcs
else:
import collections.abc as container_abcs
以上是关于ImportError: cannot import name ‘container_abcs‘ from ‘torch._six‘的主要内容,如果未能解决你的问题,请参考以下文章
解决 ImportError: cannot import name pywrap_tensorflow
ImportError: cannot import name webdriver
ImportError: cannot import name patterns
window环境下ImportError: cannot import name 'Bar' from 'pyecharts'