关于升级pytorch1.9后出现cannot import name ‘container_abcs‘ from ‘torch._six‘错误的解决方法

因为1.8版本之后container_abcs就已经被移除了。

cannot import name 'container_abcs' from 'torch._six'

在使用一些开源代码的时候,可能会遇到该错误。

解决方法也很简单我们只需要给它换一个就行。

TORCH_MAJOR = int(torch.__version__.split('.')[0])
TORCH_MINOR = int(torch.__version__.split('.')[1])
if TORCH_MAJOR == 1 and TORCH_MINOR < 8:
    from torch._six import container_abcs
else:
    import collections.abc as container_abcs

一个超级好用的调试APP, 前往应用市场

猜你喜欢

转载自blog.csdn.net/qq_19313495/article/details/120361059