问题描述
使用timm时
from timm.models.vision_transformer import Block
遇到报错:
"xxx/lib/python3.7/site-packages/torchvision/models/maxvit.py", line 3, in <module>
from typing import Any, Callable, List, Optional, OrderedDict, Sequence, Tuple
ImportError: cannot import name 'OrderedDict' from 'typing' (xxx/lib/python3.7/typing.py)
解决方案
思路:在Python 3.7及更高版本中,OrderedDict已经作为标准库中的collections模块的一部分,无需再从typing_extensions导入。
因此具体解决方案是:
1. 进入到报错文件,定位第3行
文件xxx/lib/python3.7/site-packages/torchvision/models/maxvit.py
第3行:
from typing import Any, Callable, List, Optional, OrderedDict, Sequence, Tuple
2. 使用标准库 collections 中的 OrderedDict 类
改为如下两行
from typing import Any, Callable, List, Optional, Sequence, Tuple
from collections import OrderedDict
标签:OrderedDict,name,lib,ImportError,py,Callable,typing,import
From: https://blog.csdn.net/qq_43558894/article/details/137118021