mmsegmentation 自定义模型报错:KeyError: ‘EncoderDecoder is not in the model registry

mmsegmentation 自定义模型报错:KeyError: 'EncoderDecoder is not in the model registry'

在使用 `mmsegmentation` 自定义模型时,可能会遇到以下错误:

复制代码
KeyError: 'EncoderDecoder is not in the model registry. Please check whether the value of EncoderDecoder is correct or it was registered as expected. More details can be found at https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#import-the-custom-module'

这通常是由于模型内部初始化问题引起的。

解决方法

在配置文件中添加以下内容:

```python

custom_imports = dict(

imports=['mmseg.models.backbones.rdt_fastvit'],

allow_failed_imports=False

)

修改后的配置文件示例:

复制代码
# model settings
norm_cfg = dict(type='SyncBN', requires_grad=True)
data_preprocessor = dict(
    type='SegDataPreProcessor',
    mean=[123.675, 116.28, 103.53],
    std=[58.395, 57.12, 57.375],
    bgr_to_rgb=True,
    pad_val=0,
    seg_pad_val=255
)
custom_imports = dict(
    imports=['mmseg.models.backbones.rdt_fastvit'],
    allow_failed_imports=False
)
model = dict(
    type='EncoderDecoder',
    data_preprocessor=data_preprocessor,
    backbone=dict(
        type='RDT_FastViT',
        model_name='rdt_sa12_s',
        pretrained=False,
        checkpoint_path='/path/rdt_fastvit_sa12.pth.tar',
        num_classes=1000,
        in_chans=3,
        drop_rate=0.1,
        global_pool='avg',
        retina_size=512,
        patch_number=4,
        use_residual=True,
        use_retina_field=False
    ),
    neck=dict(
        type='FPN',
        in_channels=[64, 128, 256, 512],
        out_channels=256,
        num_outs=4
    ),
    decode_head=dict(
        type='FPNHead',
        in_channels=[256, 256, 256, 256],
        in_index=[0, 1, 2, 3],
        feature_strides=[4, 8, 16, 32],
        channels=128,
        dropout_ratio=0.1,
        num_classes=19,
        norm_cfg=norm_cfg,
        align_corners=False,
        loss_decode=dict(
            type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0)
    ),
    train_cfg=dict(),
    test_cfg=dict(mode='whole')
)

添加后,再次运行会显示详细的出错位置,例如:

复制代码
ImportError: cannot import name 'PatchEmbedCifar' from 'timm.layers.patch_embed' (/root/anaconda3/envs/mmseg/lib/python3.9/site-packages/timm/layers/patch_embed.py)
相关推荐
weixin_421922693 分钟前
使用Scikit-learn进行机器学习模型评估
jvm·数据库·python
NAGNIP3 分钟前
一文搞懂深度学习中的损失函数设计!
人工智能·算法
Liu628885 分钟前
如何为开源Python项目做贡献?
jvm·数据库·python
千桐科技5 分钟前
大模型幻觉难解?2026深度解析:知识图谱如何成为LLM落地的“刚需”与高薪新赛道
人工智能·大模型·llm·知识图谱·大模型幻觉·qknow·行业深度ai应用
mygugu6 分钟前
详细分析swanlab集成mmengine底层实现机制--源码分析
python·深度学习·可视化
Hello.Reader6 分钟前
词语没有位置感?用“音乐节拍“给 Transformer 装上时钟——Positional Encoding 图解
人工智能·深度学习·transformer
我叫果冻8 分钟前
ai-assist:基于 LangChain4j 的 RAG 智能助手,本地化部署更安全
人工智能·安全
Monday学长12 分钟前
2026年全维度AI论文写作工具测评:基于实测数据与用户真实反馈
人工智能
烟花巷子15 分钟前
使用Kivy开发跨平台的移动应用
jvm·数据库·python