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)
相关推荐
轻口味几秒前
【每日学点HarmonyOS Next知识】对话框与导航冲突、富文本、字体大小、列表刷新、Scroll包裹文本
pytorch·深度学习·harmonyos·harmonyos next
AAA小肥杨6 分钟前
2025人工智能AI新突破:PINN内嵌物理神经网络火了
人工智能·深度学习·神经网络·ai·大模型部署
王国强200928 分钟前
现代循环神经网络4-双向循环神经网络
深度学习
m0_7482522328 分钟前
Python 入门教程(2)搭建环境 2.4、VSCode配置Node.js运行环境
vscode·python·node.js
梓羽玩Python42 分钟前
太牛了!OWL:Manus 最强开源复现,开源框架GAIA基准测试中排第一!
人工智能·python
2301_764441331 小时前
python实现的生态模拟系统
开发语言·python·pygame
m0_748241701 小时前
Python毕业设计选题:基于django+vue的智能租房系统的设计与实现
python·django·课程设计
m0_748244961 小时前
Python毕业设计选题:基于Python的社区爱心养老管理系统设计与实现_django
python·django·课程设计
莓事哒1 小时前
静态网页的爬虫(以电影天堂为例)
爬虫·python
HerrFu1 小时前
可狱可囚的爬虫系列课程 18:成都在售新房数据爬虫(lxml 模块)实战
爬虫·python