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)
相关推荐
لا معنى له7 分钟前
学习笔记:Transformer
人工智能·笔记·深度学习·学习·机器学习·transformer
人工智能培训7 分钟前
什么是基于大模型的智能体构建?
人工智能·深度学习·大模型·具身智能·智能体·智能体构建·大模型智能体
田姐姐tmner13 分钟前
Python 全面语法指南
开发语言·python
深度学习实战训练营18 分钟前
SegFormer:使用Transformer进行语义分割,简单而高效的设计-k学长深度学习专栏
人工智能·深度学习·transformer
大、男人18 分钟前
FastMCP高级特性之Composition
人工智能·fastmcp
CES_Asia19 分钟前
机器人“奥运会”燃动北京——CES Asia 2026全球机器人性能挑战赛与展览定档
大数据·人工智能·机器人
DKNG21 分钟前
【Windows Host】 hosts配置增加访问github流畅度
人工智能·git·github
white-persist22 分钟前
【攻防世界】reverse | simple-check-100 详细题解 WP
c语言·开发语言·汇编·数据结构·c++·python·算法
昨日之日200625 分钟前
Fun-ASR - 多语言多方言的高精度语音识别软件 支持50系显卡 一键整合包下载
人工智能·音视频·语音识别
王大傻092831 分钟前
Series的属性简介
python·pandas