因为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 == 0:
import collections.abc as container_abcs
else:
from torch._six import container_abcs
换成这样:
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
但我并没有找到这段代码。
下面直接开门见山,给出亲测有效的方法:
点击报错前往位置,将
from torch._six import container_abcs
改为
import collections.abc as container_abcs
问题解决。