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)
相关推荐
Surprisec2 分钟前
如何用 TypeScript 写一个最小可运行的 CLI Agent
前端·人工智能·typescript
狐言乱雨4 分钟前
深入理解KV Cache:大模型推理加速的核心技术
python
还是叫明5 分钟前
指针式仪表读数(机器视觉、OpenCV)
人工智能·opencv·计算机视觉
智塑未来8 分钟前
六家 GEO 系统服务商实测横向测评,按企业发展周期筛选 TOP 推荐厂商
人工智能
蓝狐社11 分钟前
AI资本周期的转折点:从通用模型崇拜到垂直价值捕获
人工智能
Good kid.11 分钟前
开源一套 Vue3 多模态 AI 控制台前端:游乐场、工作室与 API 文档页
前端·人工智能·开源
【建模先锋】13 分钟前
创新升级!从 Conditional DCGAN 到 Conditional WGAN-GP:小样本故障诊断生成增强再进阶
深度学习·生成对抗网络·信号处理·故障诊断·小样本·轴承故障诊断·样本生成
清欢渡hb13 分钟前
一人 AI 软件公司 · Claude Code 插件架构设计
人工智能·ai编程·claude·一人公司
七夜zippoe14 分钟前
OpenClaw Nodes 设备管理深度解析:AI Agent的跨设备协作能力
人工智能·ai·agent·openclaw·nodes
GIOTTO情16 分钟前
智能媒介投放技术迭代:从人工规则调控到AI全域动态调度的架构演进
人工智能·架构