diff --git a/docs/en/advanced_guides/how_to.md b/docs/en/advanced_guides/how_to.md index 4ac5bd5d..95129914 100644 --- a/docs/en/advanced_guides/how_to.md +++ b/docs/en/advanced_guides/how_to.md @@ -312,6 +312,45 @@ model = dict( ) ``` +#### Don't used pre-training weights + +When we replace the backbone network, the model initialization is trained by default loading the pre-training weight of the backbone network. Instead of using the pre-training weights of the backbone network, if you want to train the time model from scratch, +You can set `init_cfg` in 'backbone' to 'None'. In this case, the backbone network will be initialized with the default initialization method, instead of using the trained pre-training weight. + +```python +_base_ = './yolov5_s-v61_syncbn_8xb16-300e_coco.py' + +deepen_factor = _base_.deepen_factor +widen_factor = 1.0 +channels = [512, 1024, 2048] + +model = dict( + backbone=dict( + _delete_=True, # Delete the backbone field in _base_ + type='mmdet.ResNet', # Using ResNet from mmdet + depth=50, + num_stages=4, + out_indices=(1, 2, 3), + frozen_stages=1, + norm_cfg=dict(type='BN', requires_grad=True), + norm_eval=True, + style='pytorch', + init_cfg=None # If init_cfg is set to None, backbone will not be initialized with pre-trained weights + ), + neck=dict( + type='YOLOv5PAFPN', + widen_factor=widen_factor, + in_channels=channels, # Note: The 3 channels of ResNet-50 output are [512, 1024, 2048], which do not match the original yolov5-s neck and need to be changed. + out_channels=channels), + bbox_head=dict( + type='YOLOv5Head', + head_module=dict( + type='YOLOv5HeadModule', + in_channels=channels, # input channels of head need to be changed accordingly + widen_factor=widen_factor)) +) +``` + ## Output prediction results If you want to save the prediction results as a specific file for offline evaluation, MMYOLO currently supports both json and pkl formats. diff --git a/docs/zh_cn/advanced_guides/how_to.md b/docs/zh_cn/advanced_guides/how_to.md index 280f701b..dbeca23f 100644 --- a/docs/zh_cn/advanced_guides/how_to.md +++ b/docs/zh_cn/advanced_guides/how_to.md @@ -315,6 +315,46 @@ model = dict( ) ``` +#### 不使用预训练权重 + +通常情况下,骨干网络初始化都是优先选择预训练权重。如果你不想使用预训练权重,而是想从头开始训练时模型时, +我们可以将 `backbone` 中的 `init_cfg` 设置为 `None`,此时骨干网络将会以默认的初始化方法进行初始化, +而不会使用训练好的预训练权重进行初始。以下是以 `YOLOv5` 使用 resnet 作为主干网络为例子,其余算法也是同样的处理: + +```python +_base_ = './yolov5_s-v61_syncbn_8xb16-300e_coco.py' + +deepen_factor = _base_.deepen_factor +widen_factor = 1.0 +channels = [512, 1024, 2048] + +model = dict( + backbone=dict( + _delete_=True, # 将 _base_ 中关于 backbone 的字段删除 + type='mmdet.ResNet', # 使用 mmdet 中的 ResNet + depth=50, + num_stages=4, + out_indices=(1, 2, 3), + frozen_stages=1, + norm_cfg=dict(type='BN', requires_grad=True), + norm_eval=True, + style='pytorch', + init_cfg=None # init_cfg 设置为 None,则 backbone 将不会使用预训练好的权重进行初始化了 + ), + neck=dict( + type='YOLOv5PAFPN', + widen_factor=widen_factor, + in_channels=channels, # 注意:ResNet-50 输出的 3 个通道是 [512, 1024, 2048],和原先的 yolov5-s neck 不匹配,需要更改 + out_channels=channels), + bbox_head=dict( + type='YOLOv5Head', + head_module=dict( + type='YOLOv5HeadModule', + in_channels=channels, # head 部分输入通道也要做相应更改 + widen_factor=widen_factor)) +) +``` + ## 输出预测结果 如果想将预测结果保存为特定的文件,用于离线评估,目前 MMYOLO 支持 json 和 pkl 两种格式。