我的需求:复现convnext网络模型(convnext+upernet),部署到自己的框架代码中,用于语义分割任务(vaihingen数据集)。
前提:根据mmsegmentation框架中的手册安装mmseg、mmcv等库。
- 进入convnext源码网站:https://github.com/facebookresearch/ConvNeXt
- 进入
semantic_segmantation/
文件下 - convnext代码在
backbone/convnext.py
中,
其中需要修改的地方:
(1)我的代码中from mmcv_custom import load_checkpoint
总是报错mmcv_custom
模块找不到,因此将此段代码注释掉,换成from mmcv.runner import _load_checkpoint
,这里是参考了mmsegmentation中poolformer代码的处理方法。
(2)修改代码中使用了load_checkpoint
的部分(在ConvNeXt类中)
def init_weights(self, pretrained=None):
"""Initialize the weights in backbone.
Args:
pretrained (str, optional): Path to pre-trained weights.
Defaults to None.
"""
def _init_weights(m):
if isinstance(m, nn.Linear):
trunc_normal_(m.weight, std=.02)
if isinstance(m, nn.Linear) and m.bias is