python 3.11 运行 timm 0.6.12无法import

python3.11 安装了 timm 0.6.12 后,在import timm时报错:

ValueError: mutable default <class 'timm.models.maxxvit.MaxxVitConvCfg'> for field conv_cfg is not allowed: use default_factory

在hugging face官方的issue中给出了解决方案:

https://github.com/huggingface/pytorch-image-models/issues/1530

做一次文件修改即可:

打开安装路径中的timm

[你的timm路径]/models/maxxvit.py

首先在line 42添加 field,即从原本的

from dataclasses import dataclass, replace

改为

from dataclasses import dataclass, replace, field

然后修改lines 232、233,从原本的

conv_cfg: MaxxVitConvCfg = MaxxVitConvCfg()
transformer_cfg: MaxxVitTransformerCfg = MaxxVitTransformerCfg()

改为

conv_cfg: MaxxVitConvCfg = field(default_factory=MaxxVitConvCfg)
transformer_cfg: MaxxVitTransformerCfg = field(default_factory=MaxxVitTransformerCfg)

即可

相关推荐
人才程序员23 天前
【PySide6快速入门】QFileDialog 文件选择对话框
c语言·c++·qt·microsoft·pyside6·python3.11
人才程序员24 天前
【PySide6快速入门】ui文件的使用
c语言·开发语言·前端·qt·ui·python3.11·界面
hshpy25 天前
start using Python 3.11 after installation
windows·python·python3.11
卜及中1 个月前
【Pytest】基础到高级功能的理解使用
开发语言·python·学习·pytest·python3.11
卜及中1 个月前
【Sanic 框架 / 1】深入学习:从入门到进阶
python·学习·web3·python3.11
mixboot1 个月前
macOS 安装 python3.11
macos·python3.11
vvw&2 个月前
如何在 Ubuntu 22.04 上安装 JupyterLab 环境教程
linux·运维·服务器·ubuntu·jupyter·开源·python3.11
Guofu_Liao3 个月前
大语言模型---Llama不同系列的权重参数文件提取;Llama-7B权重文件提取;Llama-8B权重文件提取;主要代码功能解析
人工智能·语言模型·自然语言处理·chatgpt·aigc·llama·python3.11
刘悦的技术博客3 个月前
MagicQuill,AI动态图像元素修改,AI绘图,需要40G的本地硬盘空间,12G显存可玩,Win11本地部署
ai·aigc·python3.11
follycat3 个月前
ISCTF2024
java·网络·数据库·学习·网络安全·python3.11