mirror of
https://github.com/open-mmlab/mmengine.git
synced 2025-06-03 21:54:44 +08:00
[Docs] Replace MMCls with MMPretrain in docs (#1096)
* [Docs] Replace MMCls with MMPretrain in docs * fix format
This commit is contained in:
parent
c9ee331e43
commit
43165160e6
@ -1,27 +1,27 @@
|
||||
# Use modules from other libraries
|
||||
|
||||
Based on MMEngine's [Registry](registry.md) and [Config](config.md), users can build modules across libraries.
|
||||
For example, use [MMClassification](https://github.com/open-mmlab/mmclassification)'s backbones in [MMDetection](https://github.com/open-mmlab/mmdetection), or [MMDetection](https://github.com/open-mmlab/mmdetection)'s data transforms in [MMRotate](https://github.com/open-mmlab/mmrotate), or using [MMDetection](https://github.com/open-mmlab/mmdetection)'s detectors in [MMTracking](https://github.com/open-mmlab/mmtracking).
|
||||
For example, use [MMPretrain](https://github.com/open-mmlab/mmpretrain)'s backbones in [MMDetection](https://github.com/open-mmlab/mmdetection), or [MMDetection](https://github.com/open-mmlab/mmdetection)'s data transforms in [MMRotate](https://github.com/open-mmlab/mmrotate), or using [MMDetection](https://github.com/open-mmlab/mmdetection)'s detectors in [MMTracking](https://github.com/open-mmlab/mmtracking).
|
||||
|
||||
Modules registered in the same registry tree can be called across libraries by adding the **package name prefix** before the module's type in the config. Here are some common examples:
|
||||
|
||||
## Use backbone across libraries
|
||||
|
||||
Taking the example of using MMClassification's ConvNeXt in MMDetection:
|
||||
Taking the example of using MMPretrain's ConvNeXt in MMDetection:
|
||||
|
||||
Firstly, adding the `custom_imports` field to the config to register the backbones of MMClassification to the registry.
|
||||
Firstly, adding the `custom_imports` field to the config to register the backbones of MMPretrain to the registry.
|
||||
|
||||
Secondly, adding the package name of MMClassification `mmcls` to the `type` of the backbone as a prefix: `mmcls.ConvNeXt`
|
||||
Secondly, adding the package name of MMPretrain `mmpretrain` to the `type` of the backbone as a prefix: `mmpretrain.ConvNeXt`
|
||||
|
||||
```python
|
||||
# Use custom_imports to register mmcls models to the registry
|
||||
custom_imports = dict(imports=['mmcls.models'], allow_failed_imports=False)
|
||||
# Use custom_imports to register mmpretrain models to the registry
|
||||
custom_imports = dict(imports=['mmpretrain.models'], allow_failed_imports=False)
|
||||
|
||||
model = dict(
|
||||
type='MaskRCNN',
|
||||
data_preprocessor=dict(...),
|
||||
backbone=dict(
|
||||
type='mmcls.ConvNeXt', # Add mmcls prefix to enable cross-library mechanism
|
||||
type='mmpretrain.ConvNeXt', # Add mmpretrain prefix to enable cross-library mechanism
|
||||
arch='tiny',
|
||||
out_indices=[0, 1, 2, 3],
|
||||
drop_path_rate=0.4,
|
||||
|
@ -41,7 +41,7 @@ Usually, a data pipeline consists of the following parts:
|
||||
3. Data processing and augmentation, like [`RandomResize`](mmcv.transforms.RandomResize).
|
||||
4. Data formatting, we use different data transforms for different tasks. And the data transform for specified
|
||||
task is implemented in the corresponding repository. For example, the data formatting transform for image
|
||||
classification task is `PackClsInputs` and it's in MMClassification.
|
||||
classification task is `PackClsInputs` and it's in MMPretrain.
|
||||
|
||||
Here, taking the classification task as an example, we show a typical data pipeline in the figure below. For
|
||||
each sample, the basic information stored in the dataset is a dictionary as shown on the far left side of the
|
||||
|
@ -1,6 +1,6 @@
|
||||
# Registry
|
||||
|
||||
OpenMMLab supports a rich collection of algorithms and datasets, therefore, many modules with similar functionality are implemented. For example, the implementations of `ResNet` and `SE-ResNet` are based on the classes `ResNet` and `SEResNet`, respectively, which have similar functions and interfaces and belong to the model components of the algorithm library. To manage these functionally similar modules, MMEngine implements the [registry](mmengine.registry.Registry). Most of the algorithm libraries in OpenMMLab use `registry` to manage their modules, including [MMDetection](https://github.com/open-mmlab/mmdetection), [MMDetection3D](https://github.com/open-mmlab/mmdetection3d), [MMClassification](https://github.com/open-mmlab/mmclassification) and [MMEditing](https://github.com/open-mmlab/mmediting), etc.
|
||||
OpenMMLab supports a rich collection of algorithms and datasets, therefore, many modules with similar functionality are implemented. For example, the implementations of `ResNet` and `SE-ResNet` are based on the classes `ResNet` and `SEResNet`, respectively, which have similar functions and interfaces and belong to the model components of the algorithm library. To manage these functionally similar modules, MMEngine implements the [registry](mmengine.registry.Registry). Most of the algorithm libraries in OpenMMLab use `registry` to manage their modules, including [MMDetection](https://github.com/open-mmlab/mmdetection), [MMDetection3D](https://github.com/open-mmlab/mmdetection3d), [MMPretrain](https://github.com/open-mmlab/mmpretrain) and [MMEditing](https://github.com/open-mmlab/mmediting), etc.
|
||||
|
||||
## What is a registry
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
During the process of debugging code, sometimes it is necessary to train for several epochs, such as debugging the validation process or checking whether the checkpoint saving meets expectations. However, if the dataset is too large, it may take a long time to complete one epoch, in which case the length of the dataset can be set. Note that only datasets inherited from [BaseDataset](mmengine.dataset.BaseDataset) support this feature, and the usage of BaseDataset can be found in the [BaseDataset](../advanced_tutorials/basedataset.md).
|
||||
|
||||
Take MMClassification as an example (Refer to the [documentation](https://mmclassification.readthedocs.io/en/dev-1.x/get_started.html) for installing MMClassification).
|
||||
Take MMPretrain as an example (Refer to the [documentation](https://mmpretrain.readthedocs.io/en/latest/get_started.html) for installing MMPretrain).
|
||||
|
||||
Launch training
|
||||
|
||||
@ -20,7 +20,7 @@ Here is part of the training log, where `3125` represents the number of iteratio
|
||||
02/20 14:43:14 - mmengine - INFO - Epoch(train) [1][ 300/3125] lr: 1.0000e-01 eta: 3:46:27 time: 0.0146 data_time: 0.0003 memory: 214 loss: 1.9858
|
||||
```
|
||||
|
||||
Turn off the training and set `indices` as `5000` in the `dataset` field in [configs/base/datasets/cifar10_bs16.py](https://github.com/open-mmlab/mmclassification/blob/dev-1.x/configs/_base_/datasets/cifar10_bs16.py).
|
||||
Turn off the training and set `indices` as `5000` in the `dataset` field in [configs/base/datasets/cifar10_bs16.py](https://github.com/open-mmlab/mmpretrain/blob/main/configs/_base_/datasets/cifar100_bs16.py).
|
||||
|
||||
```python
|
||||
train_dataloader = dict(
|
||||
|
@ -186,7 +186,7 @@ runner = Runner(
|
||||
```
|
||||
|
||||
```{note}
|
||||
The above example makes extensive use of the registry mechanism and borrows the [Compose](mmengine.dataset.Compose) module from MMEngine. If you urge to use torchvision dataset in your config files, you can refer to it and make some slight modifications. However, we recommend you borrow datasets from downstream repos such as [MMDet](https://github.com/open-mmlab/mmdetection), [MMCls](https://github.com/open-mmlab/mmclassification), etc. This may give you a better experience.
|
||||
The above example makes extensive use of the registry mechanism and borrows the [Compose](mmengine.dataset.Compose) module from MMEngine. If you urge to use torchvision dataset in your config files, you can refer to it and make some slight modifications. However, we recommend you borrow datasets from downstream repos such as [MMDet](https://github.com/open-mmlab/mmdetection), [MMPretrain](https://github.com/open-mmlab/mmpretrain), etc. This may give you a better experience.
|
||||
```
|
||||
|
||||
### Customize your dataset
|
||||
|
@ -6,7 +6,7 @@ In model validation and testing, it is often necessary to make a quantitative ev
|
||||
|
||||
### Using a single evaluation metric
|
||||
|
||||
When training or testing a model based on MMEngine, users only need to specify the evaluation metrics for the validation and testing stages through the `val_evaluator` and `test_evaluator` fields in the configuration file. For example, when using [MMClassification](https://github.com/open-mmlab/mmclassification) to train a classification model, if the user wants to evaluate the top-1 and top-5 classification accuracy during the model validation stage, they can configure it as follows:
|
||||
When training or testing a model based on MMEngine, users only need to specify the evaluation metrics for the validation and testing stages through the `val_evaluator` and `test_evaluator` fields in the configuration file. For example, when using [MMPretrain](https://github.com/open-mmlab/mmpretrain) to train a classification model, if the user wants to evaluate the top-1 and top-5 classification accuracy during the model validation stage, they can configure it as follows:
|
||||
|
||||
```python
|
||||
# using classification accuracy evaluation metric
|
||||
|
@ -1,22 +1,22 @@
|
||||
# 跨库调用模块
|
||||
|
||||
通过使用 MMEngine 的[注册器(Registry)](registry.md)和[配置文件(Config)](config.md),用户可以实现跨软件包的模块构建。
|
||||
例如,在 [MMDetection](https://github.com/open-mmlab/mmdetection) 中使用 [MMClassification](https://github.com/open-mmlab/mmclassification) 的 Backbone,或者在 [MMRotate](https://github.com/open-mmlab/mmrotate) 中使用 [MMDetection](https://github.com/open-mmlab/mmdetection) 的 Transform,或者在 [MMTracking](https://github.com/open-mmlab/mmtracking) 中使用 [MMDetection](https://github.com/open-mmlab/mmdetection) 的 Detector。
|
||||
例如,在 [MMDetection](https://github.com/open-mmlab/mmdetection) 中使用 [MMPretrain](https://github.com/open-mmlab/mmpretrain) 的 Backbone,或者在 [MMRotate](https://github.com/open-mmlab/mmrotate) 中使用 [MMDetection](https://github.com/open-mmlab/mmdetection) 的 Transform,或者在 [MMTracking](https://github.com/open-mmlab/mmtracking) 中使用 [MMDetection](https://github.com/open-mmlab/mmdetection) 的 Detector。
|
||||
一般来说,同类模块都可以进行跨库调用,只需要在配置文件的模块类型前加上软件包名的前缀即可。下面举几个常见的例子:
|
||||
|
||||
## 跨库调用 Backbone:
|
||||
|
||||
以在 MMDetection 中调用 MMClassification 的 ConvNeXt 为例,首先需要在配置中加入 `custom_imports` 字段将 MMClassification 的 Backbone 添加进注册器,然后只需要在 Backbone 的配置中的 `type` 加上 MMClassification 的软件包名 `mmcls` 作为前缀,即 `mmcls.ConvNeXt` 即可:
|
||||
以在 MMDetection 中调用 MMPretrain 的 ConvNeXt 为例,首先需要在配置中加入 `custom_imports` 字段将 MMPretrain 的 Backbone 添加进注册器,然后只需要在 Backbone 的配置中的 `type` 加上 MMPretrain 的软件包名 `mmpretrain` 作为前缀,即 `mmpretrain.ConvNeXt` 即可:
|
||||
|
||||
```python
|
||||
# 使用 custom_imports 将 mmcls 的 models 添加进注册器
|
||||
custom_imports = dict(imports=['mmcls.models'], allow_failed_imports=False)
|
||||
# 使用 custom_imports 将 mmpretrain 的 models 添加进注册器
|
||||
custom_imports = dict(imports=['mmpretrain.models'], allow_failed_imports=False)
|
||||
|
||||
model = dict(
|
||||
type='MaskRCNN',
|
||||
data_preprocessor=dict(...),
|
||||
backbone=dict(
|
||||
type='mmcls.ConvNeXt', # 添加 mmcls 前缀完成跨库调用
|
||||
type='mmpretrain.ConvNeXt', # 添加 mmpretrain 前缀完成跨库调用
|
||||
arch='tiny',
|
||||
out_indices=[0, 1, 2, 3],
|
||||
drop_path_rate=0.4,
|
||||
|
@ -27,10 +27,10 @@ for img, data_sample in dataloader:
|
||||
抽象数据接口实现了基本的增/删/改/查功能,同时支持不同设备之间的迁移,支持类字典和张量的操作,可以充分满足算法库对于这些数据的使用要求。
|
||||
基于 MMEngine 的算法库可以继承这套抽象数据接口并实现自己的抽象数据接口来适应不同算法中数据的特点与实际需要,在保持统一接口的同时提高了算法模块的拓展性。
|
||||
|
||||
在实际实现过程中,算法库中的各个组件所具备的数据接口,一般为如下两个种:
|
||||
在实际实现过程中,算法库中的各个组件所具备的数据接口,一般为以下两种:
|
||||
|
||||
- 一个训练或测试样本(例如一张图像)的所有的标注信息和预测信息的集合,例如数据集的输出、模型以及可视化器的输入一般为单个训练或测试样本的所有信息。MMEngine将其定义为数据样本(DataSample)
|
||||
- 单一类型的预测或标注,一般是算法模型中某个子模块的输出, 例如二阶段检测中RPN的输出、语义分割模型的输出、关键点分支的输出, GAN中生成器的输出等。MMengine将其定义为数据元素(XXXData)
|
||||
- 一个训练或测试样本(例如一张图像)的所有的标注信息和预测信息的集合,例如数据集的输出、模型以及可视化器的输入一般为单个训练或测试样本的所有信息。MMEngine 将其定义为数据样本(DataSample)
|
||||
- 单一类型的预测或标注,一般是算法模型中某个子模块的输出, 例如二阶段检测中RPN的输出、语义分割模型的输出、关键点分支的输出,GAN中生成器的输出等。MMEngine 将其定义为数据元素(XXXData)
|
||||
|
||||
下边首先介绍一下数据样本与数据元素的基类 [BaseDataElement](mmengine.structures.BaseDataElement)。
|
||||
|
||||
@ -42,8 +42,7 @@ for img, data_sample in dataloader:
|
||||
|
||||
- 增/删/改/查 `data` 中不同字段的数据
|
||||
- 将 `data` 迁移至目标设备
|
||||
- 支持像访问字典/张量一样访问 data 内的数据
|
||||
以充分满足算法库对于这些数据的使用要求。
|
||||
- 支持像访问字典/张量一样访问 data 内的数据以充分满足算法库对于这些数据的使用要求。
|
||||
|
||||
### 1. 数据元素的创建
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
# 注册器(Registry)
|
||||
|
||||
OpenMMLab 的算法库支持了丰富的算法和数据集,因此实现了很多功能相近的模块。例如 ResNet 和 SE-ResNet 的算法实现分别基于 `ResNet` 和 `SEResNet` 类,这些类有相似的功能和接口,都属于算法库中的模型组件。为了管理这些功能相似的模块,MMEngine 实现了 [注册器](mmengine.registry.Registry)。OpenMMLab 大多数算法库均使用注册器来管理它们的代码模块,包括 [MMDetection](https://github.com/open-mmlab/mmdetection), [MMDetection3D](https://github.com/open-mmlab/mmdetection3d),[MMClassification](https://github.com/open-mmlab/mmclassification) 和 [MMEditing](https://github.com/open-mmlab/mmediting) 等。
|
||||
OpenMMLab 的算法库支持了丰富的算法和数据集,因此实现了很多功能相近的模块。例如 ResNet 和 SE-ResNet 的算法实现分别基于 `ResNet` 和 `SEResNet` 类,这些类有相似的功能和接口,都属于算法库中的模型组件。为了管理这些功能相似的模块,MMEngine 实现了 [注册器](mmengine.registry.Registry)。OpenMMLab 大多数算法库均使用注册器来管理它们的代码模块,包括 [MMDetection](https://github.com/open-mmlab/mmdetection), [MMDetection3D](https://github.com/open-mmlab/mmdetection3d),[MMPretrain](https://github.com/open-mmlab/mmpretrain) 和 [MMEditing](https://github.com/open-mmlab/mmediting) 等。
|
||||
|
||||
## 什么是注册器
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
在调试代码的过程中,有时需要训练几个 epoch,例如调试验证过程或者权重的保存是否符合期望。然而如果数据集太大,需要花费较长时间才能训完一个 epoch,这种情况下可以设置数据集的长度。注意,只有继承自 [BaseDataset](mmengine.dataset.BaseDataset) 的 Dataset 才支持这个功能,`BaseDataset` 的用法可阅读 [数据集基类(BASEDATASET)](../advanced_tutorials/basedataset.md)。
|
||||
|
||||
以 `MMClassification` 为例(参考[文档](https://mmclassification.readthedocs.io/zh_CN/dev-1.x/get_started.html#id2)安装 MMClassification)。
|
||||
以 `MMPretrain` 为例(参考[文档](https://mmpretrain.readthedocs.io/zh_CN/latest/get_started.html)安装 MMPretrain)。
|
||||
|
||||
启动训练命令
|
||||
|
||||
@ -20,7 +20,7 @@ python tools/train.py configs/resnet/resnet18_8xb16_cifar10.py
|
||||
02/20 14:43:14 - mmengine - INFO - Epoch(train) [1][ 300/3125] lr: 1.0000e-01 eta: 3:46:27 time: 0.0146 data_time: 0.0003 memory: 214 loss: 1.9858
|
||||
```
|
||||
|
||||
关掉训练,然后修改 [configs/_base_/datasets/cifar10_bs16.py](https://github.com/open-mmlab/mmclassification/blob/dev-1.x/configs/_base_/datasets/cifar10_bs16.py) 中的 `dataset` 字段,设置 `indices=5000`。
|
||||
关掉训练,然后修改 [configs/_base_/datasets/cifar10_bs16.py](https://github.com/open-mmlab/mmpretrain/blob/main/configs/_base_/datasets/cifar100_bs16.py) 中的 `dataset` 字段,设置 `indices=5000`。
|
||||
|
||||
```python
|
||||
train_dataloader = dict(
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
在模型验证和模型测试中,通常需要对模型精度做定量评测。在 MMEngine 中实现了评测指标(Metric)和评测器(Evaluator)来完成这一功能。
|
||||
|
||||
- **评测指标** 用于根据测试数据和模型预测结果,完成特定模型精度指标的计算。在 OpenMMLab 各算法库中提供了对应任务的常用评测指标,如 [MMClassification](https://github.com/open-mmlab/mmclassification) 中提供了[Accuracy](https://mmpretrain.readthedocs.io/en/latest/api/generated/mmpretrain.evaluation.Accuracy.html#mmpretrain.evaluation.Accuracy) 用于计算分类模型的 Top-k 分类正确率;[MMDetection](https://github.com/open-mmlab/mmdetection) 中提供了 [COCOMetric](https://github.com/open-mmlab/mmdetection/blob/main/mmdet/evaluation/metrics/coco_metric.py) 用于计算目标检测模型的 AP,AR 等评测指标。评测指标与数据集解耦,如 COCOMetric 也可用于 COCO 以外的目标检测数据集上。
|
||||
- **评测指标** 用于根据测试数据和模型预测结果,完成特定模型精度指标的计算。在 OpenMMLab 各算法库中提供了对应任务的常用评测指标,如 [MMPretrain](https://github.com/open-mmlab/mmpretrain) 中提供了[Accuracy](https://mmpretrain.readthedocs.io/en/latest/api/generated/mmpretrain.evaluation.Accuracy.html#mmpretrain.evaluation.Accuracy) 用于计算分类模型的 Top-k 分类正确率;[MMDetection](https://github.com/open-mmlab/mmdetection) 中提供了 [COCOMetric](https://github.com/open-mmlab/mmdetection/blob/main/mmdet/evaluation/metrics/coco_metric.py) 用于计算目标检测模型的 AP,AR 等评测指标。评测指标与数据集解耦,如 COCOMetric 也可用于 COCO 以外的目标检测数据集上。
|
||||
|
||||
- **评测器** 是评测指标的上层模块,通常包含一个或多个评测指标。评测器的作用是在模型评测时完成必要的数据格式转换,并调用评测指标计算模型精度。评测器通常由[执行器](../tutorials/runner.md)或测试脚本构建,分别用于在线评测和离线评测。
|
||||
|
||||
@ -83,6 +83,6 @@ class BaseMetric(metaclass=ABCMeta):
|
||||
|
||||
## 增加自定义评测指标
|
||||
|
||||
在 OpenMMLab 的各个算法库中,已经实现了对应方向的常用评测指标。如 MMDetection 中提供了 COCO 评测指标,MMClassification 中提供了 Accuracy、F1Score 等评测指标等。
|
||||
在 OpenMMLab 的各个算法库中,已经实现了对应方向的常用评测指标。如 MMDetection 中提供了 COCO 评测指标,MMPretrain 中提供了 Accuracy、F1Score 等评测指标等。
|
||||
|
||||
用户也可以增加自定义的评测指标。具体方法可以参考[教程文档](../tutorials/evaluation.md#自定义评测指标)中给出的示例。
|
||||
|
@ -184,7 +184,7 @@ runner = Runner(
|
||||
```
|
||||
|
||||
```{note}
|
||||
上述例子中大量使用了[注册机制](../advanced_tutorials/registry.md),并且用到了 MMEngine 中的 [Compose](mmengine.dataset.Compose)。如果你急需在配置文件中使用 `torchvision` 数据集,你可以参考上述代码并略作修改。但我们更加推荐你有需要时在下游库(如 [MMDet](https://github.com/open-mmlab/mmdetection) 和 [MMCls](https://github.com/open-mmlab/mmclassification) 等)中寻找对应的数据集实现,从而获得更好的使用体验。
|
||||
上述例子中大量使用了[注册机制](../advanced_tutorials/registry.md),并且用到了 MMEngine 中的 [Compose](mmengine.dataset.Compose)。如果你急需在配置文件中使用 `torchvision` 数据集,你可以参考上述代码并略作修改。但我们更加推荐你有需要时在下游库(如 [MMDet](https://github.com/open-mmlab/mmdetection) 和 [MMPretrain](https://github.com/open-mmlab/mmpretrain) 等)中寻找对应的数据集实现,从而获得更好的使用体验。
|
||||
```
|
||||
|
||||
### 自定义数据集
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
### 使用单个评测指标
|
||||
|
||||
在基于 MMEngine 进行模型训练或测试时,用户只需要在配置文件中通过 `val_evaluator` 和 `test_evaluator` 2 个字段分别指定模型验证和测试阶段的评测指标即可。例如,用户在使用 [MMClassification](https://github.com/open-mmlab/mmclassification) 训练分类模型时,希望在模型验证阶段评测 top-1 和 top-5 分类正确率,可以按以下方式配置:
|
||||
在基于 MMEngine 进行模型训练或测试时,用户只需要在配置文件中通过 `val_evaluator` 和 `test_evaluator` 2 个字段分别指定模型验证和测试阶段的评测指标即可。例如,用户在使用 [MMPretrain](https://github.com/open-mmlab/mmpretrain) 训练分类模型时,希望在模型验证阶段评测 top-1 和 top-5 分类正确率,可以按以下方式配置:
|
||||
|
||||
```python
|
||||
val_evaluator = dict(type='Accuracy', top_k=(1, 5)) # 使用分类正确率评测指标
|
||||
|
@ -819,7 +819,7 @@ class Runner:
|
||||
def wrap_model(
|
||||
self, model_wrapper_cfg: Optional[Dict],
|
||||
model: nn.Module) -> Union[DistributedDataParallel, nn.Module]:
|
||||
"""Wrap the model to :obj:``MMDistributedDataParallel`` or other custom
|
||||
"""Wrap the model to :obj:`MMDistributedDataParallel` or other custom
|
||||
distributed data-parallel module wrappers.
|
||||
|
||||
An example of ``model_wrapper_cfg``::
|
||||
|
Loading…
x
Reference in New Issue
Block a user