ImportError: cannot import name ‘container_abcs‘ from ‘torch._six‘
Cannot from name import container torch ImportError ._
2023-09-14 09:05:45 时间
问题描述
在使用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
相关文章
- The type java.lang.reflect.AnnotatedElement cannot be resolved. It is indirectly referenced from required .class files
- Cannot create an instance of OLE DB provider "OraOLEDB.Oracle" for linked server "xxxxxxx".
- WCF The service cannot be activated because it does not support ASP.NET compatibility
- IBase component cannot be created and deleted in the same second
- why I cannot get any search result from P8F
- 成功解决Exception “unhandled ImportError“cannot import name ‘imread‘ from ‘scipy.misc‘
- 成功解决ImportError: cannot import name ‘InvalidSchemeCombination‘ from ‘pip._internal.exceptions‘
- ImportError: cannot import name ‘Page‘ from ‘pyecharts‘
- 已解决ImportError: cannot import name ‘DecisionBoundaryDisplay‘ from ‘sklearn.inspection‘
- 已解决ImportError: cannot import name ‘Tab‘ from ‘pyecharts.charts‘
- 已解决ImportError: cannot import name ‘Imputer‘ from ‘sklearn.preprocessing
- Fatal Python error: Cannot recover from stack overflow 解决
- cannot import name 'UMAP' from 'umap'
- 【qt5 event loop | cannot import name ‘QtCore’ | Backend Qt5Agg is interactive backend】matplotlib无法响应
- ImportError: cannot import name ‘soft_unicode‘ from ‘markupsafe‘