mirror of https://github.com/open-mmlab/mmyolo.git
[Docs] Add examples of how to use the backbone from other repos in `how_to.md` and update `article.md` (#207)
* Update article.md * Update article.md * Update how_to.md * Update how_to.md * Refine zh_CN how_to.md * Update EN how_to.md * Refine comments in how_to.md * Adjust the position of notespull/249/head
parent
42bb4fd14a
commit
38173ccc5c
|
@ -1,8 +1,8 @@
|
|||
This tutorial collects answers to any `How to xxx with MMYOLO`. Feel free to update this doc if you meet new questions about `How to` and find the answers!
|
||||
|
||||
# Add plugins to the BackBone network
|
||||
# Add plugins to the Backbone network
|
||||
|
||||
MMYOLO supports adding plug-ins such as none_local and dropout after different stages of BackBone. Users can directly manage plug-ins by modifying the plugins parameter of backbone in config. For example, add GeneralizedAttention plug-ins for `YOLOv5`. The configuration files are as follows:
|
||||
MMYOLO supports adding plugins such as none_local and dropout after different stages of Backbone. Users can directly manage plugins by modifying the plugins parameter of backbone in config. For example, add GeneralizedAttention plugins for `YOLOv5`. The configuration files are as follows:
|
||||
|
||||
```python
|
||||
_base_ = './yolov5_s-v61_syncbn_8xb16-300e_coco.py'
|
||||
|
@ -60,3 +60,212 @@ model = dict(
|
|||
bbox_head=dict(head_module=dict(in_channels=[512,512,512])) # The out_channels is controlled by widen_factor,so the YOLOv5HeadModuled in_channels * widen_factor equals to the last neck's out_channels
|
||||
)
|
||||
```
|
||||
|
||||
## Use backbone network implemented in other OpenMMLab repositories
|
||||
|
||||
The model registry in MMYOLO, MMDetection, MMClassification, and MMSegmentation all inherit from the root registry in MMEngine in the OpenMMLab 2.0 system, allowing these repositories to directly use modules already implemented by each other. Therefore, in MMYOLO, users can use backbone networks from MMDetection and MMClassification without reimplementation.
|
||||
|
||||
```{note}
|
||||
1. When using other backbone networks, you need to ensure that the output channels of the backbone network match the input channels of the neck network.
|
||||
2. The configuration files given below only ensure that the training will work correctly, and their training performance may not be optimal. Because some backbones require specific learning rates, optimizers, and other hyperparameters. Related contents will be added in the "Training Tips" section later.
|
||||
```
|
||||
|
||||
### Use backbone network implemented in MMDetection
|
||||
|
||||
1. Suppose you want to use `ResNet-50` as the backbone network of `YOLOv5`, the example config is as the following:
|
||||
|
||||
```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=dict(type='Pretrained', checkpoint='torchvision://resnet50')),
|
||||
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))
|
||||
)
|
||||
```
|
||||
|
||||
2. Suppose you want to use `SwinTransformer-Tiny` as the backbone network of `YOLOv5`, the example config is as the following:
|
||||
|
||||
```python
|
||||
_base_ = './yolov5_s-v61_syncbn_8xb16-300e_coco.py'
|
||||
|
||||
deepen_factor = _base_.deepen_factor
|
||||
widen_factor = 1.0
|
||||
channels = [192, 384, 768]
|
||||
checkpoint_file = 'https://github.com/SwinTransformer/storage/releases/download/v1.0.0/swin_tiny_patch4_window7_224.pth' # noqa
|
||||
|
||||
model = dict(
|
||||
backbone=dict(
|
||||
_delete_=True, # Delete the backbone field in _base_
|
||||
type='mmdet.SwinTransformer', # Using SwinTransformer from mmdet
|
||||
embed_dims=96,
|
||||
depths=[2, 2, 6, 2],
|
||||
num_heads=[3, 6, 12, 24],
|
||||
window_size=7,
|
||||
mlp_ratio=4,
|
||||
qkv_bias=True,
|
||||
qk_scale=None,
|
||||
drop_rate=0.,
|
||||
attn_drop_rate=0.,
|
||||
drop_path_rate=0.2,
|
||||
patch_norm=True,
|
||||
out_indices=(1, 2, 3),
|
||||
with_cp=False,
|
||||
convert_weights=True,
|
||||
init_cfg=dict(type='Pretrained', checkpoint=checkpoint_file)),
|
||||
neck=dict(
|
||||
type='YOLOv5PAFPN',
|
||||
deepen_factor=deepen_factor,
|
||||
widen_factor=widen_factor,
|
||||
in_channels=channels, # Note: The 3 channels of SwinTransformer-Tiny output are [192, 384, 768], 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))
|
||||
)
|
||||
```
|
||||
|
||||
### Use backbone network implemented in MMClassification
|
||||
|
||||
1. Suppose you want to use `ConvNeXt-Tiny` as the backbone network of `YOLOv5`, the example config is as the following:
|
||||
|
||||
```python
|
||||
_base_ = './yolov5_s-v61_syncbn_8xb16-300e_coco.py'
|
||||
|
||||
# please run the command, mim install "mmcls>=1.0.0rc2", to install mmcls
|
||||
# import mmcls.models to trigger register_module in mmcls
|
||||
custom_imports = dict(imports=['mmcls.models'], allow_failed_imports=False)
|
||||
checkpoint_file = 'https://download.openmmlab.com/mmclassification/v0/convnext/downstream/convnext-tiny_3rdparty_32xb128-noema_in1k_20220301-795e9634.pth' # noqa
|
||||
deepen_factor = _base_.deepen_factor
|
||||
widen_factor = 1.0
|
||||
channels = [192, 384, 768]
|
||||
|
||||
model = dict(
|
||||
backbone=dict(
|
||||
_delete_=True, # Delete the backbone field in _base_
|
||||
type='mmcls.ConvNeXt', # Using ConvNeXt from mmcls
|
||||
arch='tiny',
|
||||
out_indices=(1, 2, 3),
|
||||
drop_path_rate=0.4,
|
||||
layer_scale_init_value=1.0,
|
||||
gap_before_final_norm=False,
|
||||
init_cfg=dict(
|
||||
type='Pretrained', checkpoint=checkpoint_file,
|
||||
prefix='backbone.')), # The pre-trained weights of backbone network in MMCls have prefix='backbone.'. The prefix in the keys will be removed so that these weights can be normally loaded.
|
||||
neck=dict(
|
||||
type='YOLOv5PAFPN',
|
||||
deepen_factor=deepen_factor,
|
||||
widen_factor=widen_factor,
|
||||
in_channels=channels, # Note: The 3 channels of ConvNeXt-Tiny output are [192, 384, 768], 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))
|
||||
)
|
||||
```
|
||||
|
||||
2. Suppose you want to use `MobileNetV3-small` as the backbone network of `YOLOv5`, the example config is as the following:
|
||||
|
||||
```python
|
||||
_base_ = './yolov5_s-v61_syncbn_8xb16-300e_coco.py'
|
||||
|
||||
# please run the command, mim install "mmcls>=1.0.0rc2", to install mmcls
|
||||
# import mmcls.models to trigger register_module in mmcls
|
||||
custom_imports = dict(imports=['mmcls.models'], allow_failed_imports=False)
|
||||
checkpoint_file = 'https://download.openmmlab.com/mmclassification/v0/mobilenet_v3/convert/mobilenet_v3_small-8427ecf0.pth' # noqa
|
||||
deepen_factor = _base_.deepen_factor
|
||||
widen_factor = 1.0
|
||||
channels = [24, 48, 96]
|
||||
|
||||
model = dict(
|
||||
backbone=dict(
|
||||
_delete_=True, # Delete the backbone field in _base_
|
||||
type='mmcls.MobileNetV3', # Using MobileNetV3 from mmcls
|
||||
arch='small',
|
||||
out_indices=(3, 8, 11), # Modify out_indices
|
||||
init_cfg=dict(
|
||||
type='Pretrained',
|
||||
checkpoint=checkpoint_file,
|
||||
prefix='backbone.')), # The pre-trained weights of backbone network in MMCls have prefix='backbone.'. The prefix in the keys will be removed so that these weights can be normally loaded.
|
||||
neck=dict(
|
||||
type='YOLOv5PAFPN',
|
||||
deepen_factor=deepen_factor,
|
||||
widen_factor=widen_factor,
|
||||
in_channels=channels, # Note: The 3 channels of MobileNetV3 output are [24, 48, 96], 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))
|
||||
)
|
||||
```
|
||||
|
||||
### Use backbone network in `timm` through MMClassification
|
||||
|
||||
MMClassification also provides a wrapper for the Py**T**orch **Im**age **M**odels (`timm`) backbone network, users can directly use the backbone network in `timm` through MMClassification. Suppose you want to use `EfficientNet-B1` as the backbone network of `YOLOv5`, the example config is as the following:
|
||||
|
||||
```python
|
||||
_base_ = './yolov5_s-v61_syncbn_8xb16-300e_coco.py'
|
||||
|
||||
# please run the command, mim install "mmcls>=1.0.0rc2", to install mmcls
|
||||
# and the command, pip install timm, to install timm
|
||||
# import mmcls.models to trigger register_module in mmcls
|
||||
custom_imports = dict(imports=['mmcls.models'], allow_failed_imports=False)
|
||||
|
||||
deepen_factor = _base_.deepen_factor
|
||||
widen_factor = 1.0
|
||||
channels = [40, 112, 320]
|
||||
|
||||
model = dict(
|
||||
backbone=dict(
|
||||
_delete_=True, # Delete the backbone field in _base_
|
||||
type='mmcls.TIMMBackbone', # Using timm from mmcls
|
||||
model_name='efficientnet_b1', # Using efficientnet_b1 in timm
|
||||
features_only=True,
|
||||
pretrained=True,
|
||||
out_indices=(2, 3, 4)),
|
||||
neck=dict(
|
||||
type='YOLOv5PAFPN',
|
||||
deepen_factor=deepen_factor,
|
||||
widen_factor=widen_factor,
|
||||
in_channels=channels, # Note: The 3 channels of EfficientNet-B1 output are [40, 112, 320], 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))
|
||||
)
|
||||
```
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
# How to xxx
|
||||
|
||||
本教程收集了任何如何使用 MMYOLO 进行 xxx 的答案。 如果您遇到有关`如何做`的问题及答案,请随时更新此文档!
|
||||
|
||||
## 给骨干网络增加插件
|
||||
## 给主干网络增加插件
|
||||
|
||||
MMYOLO 支持在 BackBone 的不同 Stage 后增加如 `none_local`、`dropblock` 等插件,用户可以直接通过修改 config 文件中 `backbone` 的 `plugins` 参数来实现对插件的管理。例如为 `YOLOv5` 增加 `GeneralizedAttention` 插件,其配置文件如下:
|
||||
MMYOLO 支持在 Backbone 的不同 Stage 后增加如 `none_local`、`dropblock` 等插件,用户可以直接通过修改 config 文件中 `backbone` 的 `plugins` 参数来实现对插件的管理。例如为 `YOLOv5` 增加 `GeneralizedAttention` 插件,其配置文件如下:
|
||||
|
||||
```python
|
||||
_base_ = './yolov5_s-v61_syncbn_8xb16-300e_coco.py'
|
||||
|
@ -25,7 +27,7 @@ model = dict(
|
|||
|
||||
## 应用多个 Neck
|
||||
|
||||
如果你想堆叠多个 Neck,可以直接在配置文件中的 Neck 参数,MMYOLO 支持以 `List` 形式拼接多个 Neck 配置,你需要保证的是上一个 Neck 的输出通道与下一个 Neck 的输入通道相匹配。如需要调整通道,可以插入 `mmdet.ChannelMapper` 模块用来对齐多个 Neck 之间的通道数量。具体配置如下:
|
||||
如果你想堆叠多个 Neck,可以直接在配置文件中的 Neck 参数,MMYOLO 支持以 `List` 形式拼接多个 Neck 配置,你需要保证上一个 Neck 的输出通道与下一个 Neck 的输入通道相匹配。如需要调整通道,可以插入 `mmdet.ChannelMapper` 模块用来对齐多个 Neck 之间的通道数量。具体配置如下:
|
||||
|
||||
```python
|
||||
_base_ = './yolov5_s-v61_syncbn_8xb16-300e_coco.py'
|
||||
|
@ -60,3 +62,212 @@ model = dict(
|
|||
bbox_head=dict(head_module=dict(in_channels=[512,512,512])) # 因为 out_channels 由 widen_factor 控制,YOLOv5HeadModuled 的 in_channels * widen_factor 才会等于最后一个 neck 的 out_channels
|
||||
)
|
||||
```
|
||||
|
||||
## 跨库使用主干网络
|
||||
|
||||
OpenMMLab 2.0 体系中 MMYOLO、MMDetection、MMClassification、MMSegmentation 中的模型注册表都继承自 MMEngine 中的根注册表,允许这些 OpenMMLab 开源库直接使用彼此已经实现的模块。 因此用户可以在 MMYOLO 中使用来自 MMDetection、MMClassification 的主干网络,而无需重新实现。
|
||||
|
||||
```{note}
|
||||
1. 使用其他主干网络时,你需要保证主干网络的输出通道与 Neck 的输入通道相匹配。
|
||||
2. 下面给出的配置文件,仅能确保训练可以正确运行,直接训练性能可能不是最优的。因为某些 backbone 需要配套特定的学习率、优化器等超参数。后续会在“训练技巧章节”补充训练调优相关内容。
|
||||
```
|
||||
|
||||
### 使用在 MMDetection 中实现的主干网络
|
||||
|
||||
1. 假设想将 `ResNet-50` 作为 `YOLOv5` 的主干网络,则配置文件如下:
|
||||
|
||||
```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=dict(type='Pretrained', checkpoint='torchvision://resnet50')),
|
||||
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))
|
||||
)
|
||||
```
|
||||
|
||||
2. 假设想将 `SwinTransformer-Tiny` 作为 `YOLOv5` 的主干网络,则配置文件如下:
|
||||
|
||||
```python
|
||||
_base_ = './yolov5_s-v61_syncbn_8xb16-300e_coco.py'
|
||||
|
||||
deepen_factor = _base_.deepen_factor
|
||||
widen_factor = 1.0
|
||||
channels = [192, 384, 768]
|
||||
checkpoint_file = 'https://github.com/SwinTransformer/storage/releases/download/v1.0.0/swin_tiny_patch4_window7_224.pth' # noqa
|
||||
|
||||
model = dict(
|
||||
backbone=dict(
|
||||
_delete_=True, # 将 _base_ 中关于 backbone 的字段删除
|
||||
type='mmdet.SwinTransformer', # 使用 mmdet 中的 SwinTransformer
|
||||
embed_dims=96,
|
||||
depths=[2, 2, 6, 2],
|
||||
num_heads=[3, 6, 12, 24],
|
||||
window_size=7,
|
||||
mlp_ratio=4,
|
||||
qkv_bias=True,
|
||||
qk_scale=None,
|
||||
drop_rate=0.,
|
||||
attn_drop_rate=0.,
|
||||
drop_path_rate=0.2,
|
||||
patch_norm=True,
|
||||
out_indices=(1, 2, 3),
|
||||
with_cp=False,
|
||||
convert_weights=True,
|
||||
init_cfg=dict(type='Pretrained', checkpoint=checkpoint_file)),
|
||||
neck=dict(
|
||||
type='YOLOv5PAFPN',
|
||||
deepen_factor=deepen_factor,
|
||||
widen_factor=widen_factor,
|
||||
in_channels=channels, # 注意:SwinTransformer-Tiny 输出的3个通道是 [192, 384, 768],和原先的 yolov5-s neck 不匹配,需要更改
|
||||
out_channels=channels),
|
||||
bbox_head=dict(
|
||||
type='YOLOv5Head',
|
||||
head_module=dict(
|
||||
type='YOLOv5HeadModule',
|
||||
in_channels=channels, # head 部分输入通道也要做相应更改
|
||||
widen_factor=widen_factor))
|
||||
)
|
||||
```
|
||||
|
||||
### 使用在 MMClassification 中实现的主干网络
|
||||
|
||||
1. 假设想将 `ConvNeXt-Tiny` 作为 `YOLOv5` 的主干网络,则配置文件如下:
|
||||
|
||||
```python
|
||||
_base_ = './yolov5_s-v61_syncbn_8xb16-300e_coco.py'
|
||||
|
||||
# 请先使用命令: mim install "mmcls>=1.0.0rc2",安装 mmcls
|
||||
# 导入 mmcls.models 使得可以调用 mmcls 中注册的模块
|
||||
custom_imports = dict(imports=['mmcls.models'], allow_failed_imports=False)
|
||||
checkpoint_file = 'https://download.openmmlab.com/mmclassification/v0/convnext/downstream/convnext-tiny_3rdparty_32xb128-noema_in1k_20220301-795e9634.pth' # noqa
|
||||
deepen_factor = _base_.deepen_factor
|
||||
widen_factor = 1.0
|
||||
channels = [192, 384, 768]
|
||||
|
||||
model = dict(
|
||||
backbone=dict(
|
||||
_delete_=True, # 将 _base_ 中关于 backbone 的字段删除
|
||||
type='mmcls.ConvNeXt', # 使用 mmcls 中的 ConvNeXt
|
||||
arch='tiny',
|
||||
out_indices=(1, 2, 3),
|
||||
drop_path_rate=0.4,
|
||||
layer_scale_init_value=1.0,
|
||||
gap_before_final_norm=False,
|
||||
init_cfg=dict(
|
||||
type='Pretrained', checkpoint=checkpoint_file,
|
||||
prefix='backbone.')), # MMCls 中主干网络的预训练权重含义 prefix='backbone.',为了正常加载权重,需要把这个 prefix 去掉。
|
||||
neck=dict(
|
||||
type='YOLOv5PAFPN',
|
||||
deepen_factor=deepen_factor,
|
||||
widen_factor=widen_factor,
|
||||
in_channels=channels, # 注意:ConvNeXt-Tiny 输出的3个通道是 [192, 384, 768],和原先的 yolov5-s neck 不匹配,需要更改
|
||||
out_channels=channels),
|
||||
bbox_head=dict(
|
||||
type='YOLOv5Head',
|
||||
head_module=dict(
|
||||
type='YOLOv5HeadModule',
|
||||
in_channels=channels, # head 部分输入通道也要做相应更改
|
||||
widen_factor=widen_factor))
|
||||
)
|
||||
```
|
||||
|
||||
2. 假设想将 `MobileNetV3-small` 作为 `YOLOv5` 的主干网络,则配置文件如下:
|
||||
|
||||
```python
|
||||
_base_ = './yolov5_s-v61_syncbn_8xb16-300e_coco.py'
|
||||
|
||||
# 请先使用命令: mim install "mmcls>=1.0.0rc2",安装 mmcls
|
||||
# 导入 mmcls.models 使得可以调用 mmcls 中注册的模块
|
||||
custom_imports = dict(imports=['mmcls.models'], allow_failed_imports=False)
|
||||
checkpoint_file = 'https://download.openmmlab.com/mmclassification/v0/mobilenet_v3/convert/mobilenet_v3_small-8427ecf0.pth' # noqa
|
||||
deepen_factor = _base_.deepen_factor
|
||||
widen_factor = 1.0
|
||||
channels = [24, 48, 96]
|
||||
|
||||
model = dict(
|
||||
backbone=dict(
|
||||
_delete_=True, # 将 _base_ 中关于 backbone 的字段删除
|
||||
type='mmcls.MobileNetV3', # 使用 mmcls 中的 MobileNetV3
|
||||
arch='small',
|
||||
out_indices=(3, 8, 11), # 修改 out_indices
|
||||
init_cfg=dict(
|
||||
type='Pretrained',
|
||||
checkpoint=checkpoint_file,
|
||||
prefix='backbone.')), # MMCls 中主干网络的预训练权重含义 prefix='backbone.',为了正常加载权重,需要把这个 prefix 去掉。
|
||||
neck=dict(
|
||||
type='YOLOv5PAFPN',
|
||||
deepen_factor=deepen_factor,
|
||||
widen_factor=widen_factor,
|
||||
in_channels=channels, # 注意:MobileNetV3-small 输出的3个通道是 [24, 48, 96],和原先的 yolov5-s neck 不匹配,需要更改
|
||||
out_channels=channels),
|
||||
bbox_head=dict(
|
||||
type='YOLOv5Head',
|
||||
head_module=dict(
|
||||
type='YOLOv5HeadModule',
|
||||
in_channels=channels, # head 部分输入通道也要做相应更改
|
||||
widen_factor=widen_factor))
|
||||
)
|
||||
```
|
||||
|
||||
### 通过 MMClassification 使用 `timm` 中实现的主干网络
|
||||
|
||||
由于 MMClassification 提供了 Py**T**orch **Im**age **M**odels (`timm`) 主干网络的封装,用户也可以通过 MMClassification 直接使用 `timm` 中的主干网络。假设想将 `EfficientNet-B1`作为 `YOLOv5` 的主干网络,则配置文件如下:
|
||||
|
||||
```python
|
||||
_base_ = './yolov5_s-v61_syncbn_8xb16-300e_coco.py'
|
||||
|
||||
# 请先使用命令: mim install "mmcls>=1.0.0rc2",安装 mmcls
|
||||
# 以及: pip install timm,安装 timm
|
||||
# 导入 mmcls.models 使得可以调用 mmcls 中注册的模块
|
||||
custom_imports = dict(imports=['mmcls.models'], allow_failed_imports=False)
|
||||
|
||||
deepen_factor = _base_.deepen_factor
|
||||
widen_factor = 1.0
|
||||
channels = [40, 112, 320]
|
||||
|
||||
model = dict(
|
||||
backbone=dict(
|
||||
_delete_=True, # 将 _base_ 中关于 backbone 的字段删除
|
||||
type='mmcls.TIMMBackbone', # 使用 mmcls 中的 timm 主干网络
|
||||
model_name='efficientnet_b1', # 使用 TIMM 中的 efficientnet_b1
|
||||
features_only=True,
|
||||
pretrained=True,
|
||||
out_indices=(2, 3, 4)),
|
||||
neck=dict(
|
||||
type='YOLOv5PAFPN',
|
||||
deepen_factor=deepen_factor,
|
||||
widen_factor=widen_factor,
|
||||
in_channels=channels, # 注意:EfficientNet-B1 输出的3个通道是 [40, 112, 320],和原先的 yolov5-s neck 不匹配,需要更改
|
||||
out_channels=channels),
|
||||
bbox_head=dict(
|
||||
type='YOLOv5Head',
|
||||
head_module=dict(
|
||||
type='YOLOv5HeadModule',
|
||||
in_channels=channels, # head 部分输入通道也要做相应更改
|
||||
widen_factor=widen_factor))
|
||||
)
|
||||
```
|
||||
|
|
|
@ -15,15 +15,15 @@
|
|||
|
||||
#### 工具类
|
||||
|
||||
| | 内容 | 视频 | 课程中的代码 |
|
||||
| :---: | :----------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
|
||||
| 第1讲 | 特征图可视化 | [](https://www.bilibili.com/video/BV188411s7o8/?vd_source=9273693df40f7c1d40751c4a4489848f) | [特征图可视化.ipynb](https://github.com/open-mmlab/OpenMMLabCourse/blob/main/codes/MMYOLO_tutorials/%5B%E5%B7%A5%E5%85%B7%E7%B1%BB%E7%AC%AC%E4%B8%80%E6%9C%9F%5D%E7%89%B9%E5%BE%81%E5%9B%BE%E5%8F%AF%E8%A7%86%E5%8C%96.ipynb) |
|
||||
| | 内容 | 视频 | 课程中的代码 |
|
||||
| :---: | :----------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
|
||||
| 第1讲 | 特征图可视化 | [](https://www.bilibili.com/video/BV188411s7o8) [](https://www.bilibili.com/video/BV188411s7o8) | [特征图可视化.ipynb](https://github.com/open-mmlab/OpenMMLabCourse/blob/main/codes/MMYOLO_tutorials/%5B%E5%B7%A5%E5%85%B7%E7%B1%BB%E7%AC%AC%E4%B8%80%E6%9C%9F%5D%E7%89%B9%E5%BE%81%E5%9B%BE%E5%8F%AF%E8%A7%86%E5%8C%96.ipynb) |
|
||||
|
||||
#### 基础类
|
||||
|
||||
| | 内容 | 视频 | 课程中的代码/文档 |
|
||||
| :---: | :--------: | :---------------------------------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------: |
|
||||
| 第1讲 | 配置全解读 | [](https://www.bilibili.com/video/BV1214y157ck) | [配置全解读文档](https://zhuanlan.zhihu.com/p/577715188) |
|
||||
| | 内容 | 视频 | 课程中的代码/文档 |
|
||||
| :---: | :--------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------: |
|
||||
| 第1讲 | 配置全解读 | [](https://www.bilibili.com/video/BV1214y157ck) [](https://www.bilibili.com/video/BV1214y157ck) | [配置全解读文档](https://zhuanlan.zhihu.com/p/577715188) |
|
||||
|
||||
#### 实用类
|
||||
|
||||
|
@ -31,9 +31,9 @@
|
|||
|
||||
#### 演示类
|
||||
|
||||
| | 内容 | 视频 |
|
||||
| :---: | :----------: | :---------------------------------------------------------------------------------------------------------------------------------------------------: |
|
||||
| 第1期 | 特征图可视化 | [](https://www.bilibili.com/video/BV1214y157ck) |
|
||||
| | 内容 | 视频 |
|
||||
| :---: | :----------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
|
||||
| 第1期 | 特征图可视化 | [](https://www.bilibili.com/video/BV1je4y1478R/) [](https://www.bilibili.com/video/BV1je4y1478R/) |
|
||||
|
||||
## MMEngine 解读文章和资源
|
||||
|
||||
|
|
Loading…
Reference in New Issue