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)
相关推荐
Cosolar几秒前
大模型量化技术全景深度解析:从FP16到INT4的完整演进与实战落地
人工智能·面试·架构
MATLAB代码顾问2 分钟前
哈里斯鹰优化算法(HHO)原理与Python实现
python·算法·机器学习
gz927cool3 分钟前
【系统架构】可观测性设计及其应用——面向智能体开发视角
人工智能·学习·ai·系统架构
2501_901200534 分钟前
如何用 Network 面板的性能节流模拟弱网环境下的加载
jvm·数据库·python
llilian_165 分钟前
如何甄选专业级失真度测量仪校准装置
人工智能·功能测试·单片机·嵌入式硬件·测试工具·51单片机
金融小师妹5 分钟前
基于AI宏观周期模型的黄金牛市研究:1979、2011与2026三轮行情的共性与结构分化
深度学习·机器学习·重构·逻辑回归·线性回归
kexnjdcncnxjs6 分钟前
Redis怎样优雅地关闭AOF_在运行期间动态将appendonly设置为no
jvm·数据库·python
K姐研究社7 分钟前
国产大模型Vibe Coding横评:DeepSeek V4和GLM-5.1实测对比
大数据·人工智能
风落无尘8 分钟前
第六章《从感知到认知》 完整学习资料
人工智能·python·卷积神经网络·循环神经网络
XD7429716369 分钟前
科技晚报|2026年5月8日:AI 开始争夺默认入口与治理层
人工智能·科技·开发者工具·科技晚报