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几秒前
大模型多轮对话自动上下文压缩
人工智能·后端·面试
Rsun045511 分钟前
Spring AI + RAG + 向量库 10 道模拟面试
人工智能·spring·面试
C蔡博士3 分钟前
最近点对问题(Closest Pair of Points)
java·python·算法
APIshop4 分钟前
Java调用亚马逊商品详情API接口完全指南
java·开发语言·python
未来之窗软件服务11 分钟前
vosk-ASR angular调用[AI人工智能(五十二)]—东方仙盟
人工智能·语音识别·vosk·仙盟创梦ide·东方仙盟
tangdou36909865514 分钟前
手把手图文并茂2分钟教会你Windows安装OpenClaw大龙虾AI助手 | OpenClaw AI Assistant Setup Guide
人工智能
V搜xhliang024620 分钟前
手术机器人导航软件
大数据·人工智能·机器学习·自然语言处理·机器人
SmartBrain21 分钟前
基于 Spring AI 构建多智能体协作系统(高级版)
java·人工智能·spring
Fairy要carry23 分钟前
面试-Prefill 和 Decode
人工智能
YaraMemo25 分钟前
向量求导规则
人工智能·机器学习·矩阵·信号处理