系列文章目录
mmpretrain-MAE
前言
通过模型预训练提升模型收敛速度
首先提示一点:
mmlab类函数不能重复注册;这个问题出现在我在添加新的数据类时,直接复制了原有的数据类,忘记修改类名称导致的报错
一、mae主干网络
首先:classMAEViT(VisionTransformer)
MAEViT继承于ViT
但在实现MAE类时没有继承ViT基类的in_channels参数,所以在修改参数文件时,直接添加in_channel会报“channels"不匹配的错误:
代码如下:
#主干网络中指定了输入图像大
backbone=dict(type='MAEViT',arch='b',in_channels=4,patch_size=16,mask_ratio=0.75)。
二、修改主干网络继承参数
在__init__()与super().init()分别添加in_channels:int=3,in_channels=in_channels,
代码如下:
def__init__(self,
arch:Union[str,dict]='b',
img_size:int=224,
patch_size:int=16,
in_channels:int=3,
out_indices:Union[Sequence,int]=-1,
drop_rate:float=0,
drop_path_rate:float=0,
norm_cfg:dict=dict(type='LN',eps=1e-6),
final_norm:bool=True,
out_type:str='raw',
interpolate_mode:str='bicubic',
patch_cfg:dict=dict(),
layer_cfgs:dict=dict(),
mask_ratio:float=0.75,
init_cfg:Optional[Union[List[dict],dict]]=None)->None:
super().__init__(
arch=arch,
img_size=img_size,
patch_size=patch_size,
in_channels=in_channels,
out_indices=out_indices,
drop_rate=drop_rate,
drop_path_rate=drop_path_rate,
norm_cfg=norm_cfg,
final_norm=final_norm,
out_type=out_type,
with_cls_token=True,
interpolate_mode=interpolate_mode,
patch_cfg=patch_cfg,
layer_cfgs=layer_cfgs,
init_cfg=init_cfg)
2.修改neck与head
mae在使用vit进行编码与恢复时需要传递通道参数,以确保恢复原来的图像。
在参数配置文件中neck修改in_chans=4,
neck=dict(
type='MAEPretrainDecoder',
patch_size=16,
#in_chans=3,
in_chans=4,
embed_dim=768,
decoder_embed_dim=512,
decoder_depth=8,
decoder_num_heads=16,
mlp_ratio=4.,
),
head修改in_channels=4,
head=dict(
type='MAEPretrainHead',
norm_pix=True,
patch_size=16,
in_channels=4,
loss=dict(type='PixelReconstructionLoss',criterion='L2')),
总结
遥感多通道影像在应用mmlab进行模型训练时,主要面对的修改参数就是通道数。
本文介绍了如何在MMPretrain-MAE框架下对MAE主干网络和neck/head进行修改,以适应遥感多通道影像的模型训练,重点在于处理通道数的继承和调整。
1万+

被折叠的 条评论
为什么被折叠?



