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)
相关推荐
钱栈up1 小时前
两台机器、一个 AI 记忆库:101 秒把 137 个文件对齐
爬虫·python·数据分析
钱栈up1 小时前
外网通、QQ 登不上:一条 workbuddy 脚本塞进去的路由三天没还回来
爬虫·python·数据分析
七夜zippoe9 小时前
SoduWork 源码解读:从源码启动到验收签字的运行追踪
人工智能·ai·源码解读·soduwork
星栈9 小时前
我用 n8n 给自己搭了套 AI 流水线,先从干掉每天的复制粘贴开始
人工智能
意念回复10 小时前
Transformer 系列(三):Block 的两大子层——多头注意力(含 GQA)与 FFN(含 SwiGLU)
人工智能·深度学习·transformer
枫叶丹410 小时前
AI文本水印:生成机制、统计检测与误报
人工智能·机器学习·chatgpt·agent·codex
Cosolar10 小时前
让 Agent 别猜:一条禁止手写 SQL 的红线,撑起 23 万次可信取数
人工智能·llm·agent
AI创界者10 小时前
Python 进阶实战(七十三章):Python AI/LLM 应用工程化、流式响应与调用韧性实战
人工智能·python·aigc
楚山之石12 小时前
【Lancet】BRAID 随机试验:乳腺致密女性补充成像,abbreviated MRI 与 CEM 检出更多早期癌(首轮中期结果)
人工智能·科技·学习·mri·医学影像
小宋102114 小时前
Chrome 的 AI 功能在后台偷跑流量:把端侧模型做成可版本化的分发制品,用下载资格门控、差分更新与「下载未使用率」验收
大数据·人工智能·chrome