提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
提示:以下是本篇文章正文内容,下面案例可供参考
将resnest.py和resnet.py粘贴至开源代码(基于旧版mmdetection开发)
在新版mmdetection (v2.10)找到resnest.py(mmdet/models/backbones/resnest.py)
先直接粘贴至开源代码中(mmdet/models/backbones/resnest.py)
由于resnest.py依赖resnest.py中的一些package和函数,因此也需要将resnet.py替换掉。方法同上
在mmdet/models/backbones/init.py添加resnest
from .resnet import ResNet
from .resnext import ResNeXt
from .ssd_vgg import SSDVGG
from .hrnet import HRNet
from .resnest import ResNeSt
__all__ = ['ResNet','ResNeSt','ResNeXt', 'SSDVGG', 'HRNet']
1.ResLayer
resnest.py 导入了ResLayer
因此 需要将新版中的res_layer.py(mmdet/models/utils/res_layer.py)粘贴到对应位置。并修改对应的init(mmdet/models/utils/init.py),即将ResLayer导入
from .conv_ws import conv_ws_2d, ConvWS2d
from .conv_module import build_conv_layer, ConvModule
from .norm import build_norm_layer
from .scale import Scale
from .res_layer import ResLayer, SimplifiedBasicBlock
from .weight_init import (xavier_init, normal_init, uniform_init, kaiming_init,
bias_init_with_prob)
__all__ = [
'ResLayer','conv_ws_2d', 'ConvWS2d', 'build_conv_layer', 'ConvModule',
'build_norm_layer', 'xavier_init', 'normal_init', 'uniform_init',
'kaiming_init', 'bias_init_with_prob', 'Scale','SimplifiedBasicBlock'
]
resnest.py调用了resnet.py中的ResNetV1d,旧版的resnet没有该函数,因此需要将新版中的resnet.py拿过来。这就需要对新版的resnet.py进行适配。
需适配的内容如下:
4.1ResLayer
from ..utils import ResLayer
在上步已经实现适配
4.2get_root_logger
from mmdet.utils import get_root_logger
将新版mmdetection的logger.py拿过来放在对应位置(mmdet/utils/logger.py)
并修改init(mmdet/utils/init.py)
rom .flops_counter import get_model_complexity_info
from .registry import Registry, build_from_cfg
from .logger import get_root_logger
__all__ = ['get_root_logger','Registry', 'build_from_cfg', 'get_model_complexity_info']
# def get_root_logger():
# return None
4.3build_plugin_layer
from mmcv.cnn import (build_conv_layer, build_norm_layer, build_plugin_layer,
constant_init, kaiming_init)
在anaconda虚拟环境中找到mmcv,并下载一个最新版本的mmcv。
将新版mmcv(1.2.7)中的plugin.py粘贴至旧版mmcv(0.5.9)对应位置(mmcv/cnn/bricks/plugin.py),并修改init(mmcv/cnn/bricks/init.py)
该处使用的url网络请求的数据。
# pretrained='torchvision://resnest101',
# pretrained='modelzoo://resnet50',
# pretrained='open-mmlab://resnest101',
pretrained='https://download.openmmlab.com/pretrain/third_party/resnest101_d2-f3b931b2.pth',
# backbone=dict(
# type='ResNeSt',
# depth=50,
# num_stages=4,
# out_indices=(0, 1, 2, 3),
# frozen_stages=1,
# style='pytorch'),
backbone=dict(
type='ResNeSt',
depth=101,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
norm_cfg=dict(type='BN', requires_grad=True),
norm_eval=False,
style='pytorch',
stem_channels=128,
radix=2,
reduction_factor=4,
avg_down_stride=True),