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)
相关推荐
m0_73730258几秒前
OpenClaw:从对话到执行,开启行动型 AI 智能体新时代
人工智能
X54先生(人文科技)4 分钟前
《元创力》纪实录·卷宗2.2署名权、龙标悖论与社会人格的剥夺
人工智能·开源·ai写作·零知识证明
matrixmind87 分钟前
HTTPX:Python 下一代 HTTP 客户端
python·其他·http·httpx
上海全爱科技9 分钟前
80℃高温+多路4K解码实测报告-全爱科技后羿智盒QA500A2-B
人工智能
abcy07121310 分钟前
python Statsmodels实例详解
人工智能
sunshine88511 分钟前
ISO 27001与PCI-DSS认证:财务数据安全如何反哺业财一体化落地?
大数据·人工智能
怪兽学LLM14 分钟前
LeetCode 21 合并两个有序链表:彻底理解虚拟头节点(Dummy)套路
python·leetcode·链表
金融RPA机器人丨实在智能15 分钟前
跨境库存Agent测评:开源产品无法动态备货?实在Agent以ISSUT技术重塑跨境电商供需链
人工智能·ai·开源
XLYcmy15 分钟前
一个基于 Python 的轻量级 LLM(大语言模型)API 客户端程序:从API交互到LLM应用架构
服务器·python·ai·llm·prompt·agent·token
程序员佳佳16 分钟前
四个月长期实测:自建 Milvus、FAISS、原生向量 API 和向量引擎中转方案,到底怎么选?
人工智能·windows·python·gpt·milvus·faiss