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)
相关推荐
月光船幽幽10 分钟前
带刺反馈引擎:唤醒深层意图
人工智能·python
weixin_4462608516 分钟前
什么样的智能体数据才算优质?——基于ACE视角的大语言模型智能体数据生成研究
人工智能·语言模型·自然语言处理
我是大AI34 分钟前
RAG架构下的品牌可见性革命:GEO监测技术解析与搜极星实践
人工智能·架构
大模型码小白35 分钟前
AI 提示词专栏:使用系统指令(System Prompt)实现全局约束
java·大数据·运维·开发语言·人工智能·python·prompt
土星云SaturnCloud36 分钟前
超轻量 OCR 实战:PP-OCR 边缘部署实践
服务器·人工智能·ai·ocr·边缘计算
烂蜻蜓1 小时前
Flask入门教程(八):视图函数详解——请求处理与响应的核心
后端·python·flask
AI人工智能+1 小时前
通用表格识别技术:突破传统OCR只能提取零散文本、却读不懂表格行列结构与合并单元格的局限性
深度学习·ocr·表格识别
河南凹凸环境艺术设计1 小时前
民宿酒店设计实力公司
大数据·人工智能·python
Hotchip_MEMS1 小时前
从“手工作坊”到“全自动贴装”:MEMS如何重塑雾化器制造流程
人工智能·笔记·物联网·电脑·制造