2022-04-15 20:19:20 +08:00
.. role :: hidden
:class: hidden-section
2022-08-29 15:35:10 +08:00
Data Process
=================
2022-04-15 20:19:20 +08:00
2022-08-29 15:35:10 +08:00
In MMClassification, the data process and the dataset is decomposed. The
2022-04-15 20:19:20 +08:00
datasets only define how to get samples' basic information from the file
2022-08-29 15:35:10 +08:00
system. These basic information includes the ground-truth label and raw
images data / the paths of images.The data process includes data transforms,
data preprocessors and batch augmentations.
2022-04-15 20:19:20 +08:00
2023-03-02 13:29:07 +08:00
- :mod: `Data Transforms <mmpretrain.datasets.transforms>` : Transforms includes loading, preprocessing, formatting and etc.
- :mod: `Data Preprocessors <mmpretrain.models.utils.data_preprocessor>` : Processes includes collate, normalization, stacking, channel fliping and etc.
2022-08-29 15:35:10 +08:00
2023-03-02 13:29:07 +08:00
- :mod: `Batch Augmentations <mmpretrain.models.utils.batch_augments>` : Batch augmentation involves multiple samples, such as Mixup and CutMix.
2022-08-30 18:45:58 +08:00
2023-03-02 13:29:07 +08:00
.. module :: mmpretrain.datasets.transforms
2022-08-29 15:35:10 +08:00
Data Transforms
--------------------
To prepare the inputs data, we need to do some transforms on these basic
information. These transforms includes loading, preprocessing and
formatting. And a series of data transforms makes up a data pipeline.
2022-04-15 20:19:20 +08:00
Therefore, you can find the a `` pipeline `` argument in the configs of dataset,
for example:
.. code :: python
train_pipeline = [
dict(type='LoadImageFromFile'),
2022-08-29 15:35:10 +08:00
dict(type='RandomResizedCrop', scale=224),
dict(type='RandomFlip', prob=0.5, direction='horizontal'),
2023-03-03 15:01:11 +08:00
dict(type='PackInputs'),
2022-04-15 20:19:20 +08:00
]
2022-08-29 15:35:10 +08:00
train_dataloader = dict(
....
dataset=dict(
pipeline=train_pipeline,
....),
....
2022-04-15 20:19:20 +08:00
)
2022-08-31 23:57:51 +08:00
Every item of a pipeline list is one of the following data transforms class. And if you want to add a custom data transformation class, the tutorial :doc: `Custom Data Pipelines </advanced_guides/pipeline>` will help you.
2022-04-15 20:19:20 +08:00
2022-08-29 15:35:10 +08:00
.. contents ::
:depth: 1
2022-04-15 20:19:20 +08:00
:local:
:backlinks: top
2023-03-03 15:01:11 +08:00
Loading and Formatting
^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autosummary ::
:toctree: generated
:nosignatures:
:template: data_transform.rst
LoadImageFromFile
PackInputs
ToNumpy
ToPIL
Transpose
Collect
2022-08-29 15:35:10 +08:00
Processing and Augmentation
^^^^^^^^^^^^^^^^^^^^^^^^^^^
2022-04-15 20:19:20 +08:00
2022-08-29 15:35:10 +08:00
.. autosummary ::
:toctree: generated
:nosignatures:
2023-02-08 14:30:12 +08:00
:template: data_transform.rst
2022-04-15 20:19:20 +08:00
2022-08-29 15:35:10 +08:00
Albumentations
2023-03-03 15:01:11 +08:00
CenterCrop
2022-08-29 15:35:10 +08:00
ColorJitter
EfficientNetCenterCrop
EfficientNetRandomCrop
Lighting
2023-03-03 15:01:11 +08:00
Normalize
2022-08-29 15:35:10 +08:00
RandomCrop
RandomErasing
2023-03-03 15:01:11 +08:00
RandomFlip
RandomGrayscale
RandomResize
2022-08-29 15:35:10 +08:00
RandomResizedCrop
2023-03-03 15:01:11 +08:00
Resize
2022-08-29 15:35:10 +08:00
ResizeEdge
2022-04-15 20:19:20 +08:00
2022-08-29 15:35:10 +08:00
Composed Augmentation
"""""""""""""""""""""
Composed augmentation is a kind of methods which compose a series of data
augmentation transforms, such as `` AutoAugment `` and `` RandAugment `` .
2022-04-15 20:19:20 +08:00
2022-08-29 15:35:10 +08:00
.. autosummary ::
:toctree: generated
:nosignatures:
2023-02-08 14:30:12 +08:00
:template: data_transform.rst
2022-04-15 20:19:20 +08:00
2022-08-29 15:35:10 +08:00
AutoAugment
RandAugment
2022-04-15 20:19:20 +08:00
2023-03-03 15:01:11 +08:00
The above transforms is composed from a group of policies from the below random
transforms:
2022-04-15 20:19:20 +08:00
.. autosummary ::
:toctree: generated
:nosignatures:
2023-02-08 14:30:12 +08:00
:template: data_transform.rst
2022-04-15 20:19:20 +08:00
AutoContrast
Brightness
ColorTransform
Contrast
Cutout
Equalize
2023-03-03 15:01:11 +08:00
GaussianBlur
2022-04-15 20:19:20 +08:00
Invert
Posterize
Rotate
Sharpness
Shear
Solarize
SolarizeAdd
Translate
2022-10-10 11:17:48 +08:00
BaseAugTransform
2022-04-15 20:19:20 +08:00
2023-03-03 15:01:11 +08:00
MMCV transforms
^^^^^^^^^^^^^^^
We also provides many transforms in MMCV. You can use them directly in the config files. Here are some frequently used transforms, and the whole transforms list can be found in :external+mmcv:doc: `api/transforms` .
Transform Wrapper
^^^^^^^^^^^^^^^^^
2022-08-29 15:35:10 +08:00
.. autosummary ::
:toctree: generated
:nosignatures:
2023-02-08 14:30:12 +08:00
:template: data_transform.rst
2022-08-29 15:35:10 +08:00
2023-03-03 15:01:11 +08:00
MultiView
2022-04-15 20:19:20 +08:00
2023-03-02 13:29:07 +08:00
.. module :: mmpretrain.models.utils.data_preprocessor
2022-04-15 20:19:20 +08:00
2022-08-29 15:35:10 +08:00
Data Preprocessors
------------------
2022-04-15 20:19:20 +08:00
2022-08-29 15:35:10 +08:00
The data preprocessor is also a component to process the data before feeding data to the neural network.
Comparing with the data transforms, the data preprocessor is a module of the classifier,
and it takes a batch of data to process, which means it can use GPU and batch to accelebrate the processing.
The default data preprocessor in MMClassification could do the pre-processing like following:
1. Move data to the target device.
2. Pad inputs to the maximum size of current batch.
3. Stack inputs to a batch.
4. Convert inputs from bgr to rgb if the shape of input is (3, H, W).
5. Normalize image with defined std and mean.
6. Do batch augmentations like Mixup and CutMix during training.
You can configure the data preprocessor by the `` data_preprocessor `` field or `` model.data_preprocessor `` field in the config file. Typical usages are as below:
.. code-block :: python
data_preprocessor = dict(
# RGB format normalization parameters
mean=[123.675, 116.28, 103.53],
std=[58.395, 57.12, 57.375],
to_rgb=True, # convert image from BGR to RGB
)
Or define in `` model.data_preprocessor `` as following:
.. code-block :: python
model = dict(
backbone = ...,
neck = ...,
head = ...,
data_preprocessor = dict(
mean=[123.675, 116.28, 103.53],
std=[58.395, 57.12, 57.375],
to_rgb=True)
train_cfg=...,
)
Note that the `` model.data_preprocessor `` has higher priority than `` data_preprocessor `` .
.. autosummary ::
:toctree: generated
:nosignatures:
2022-08-30 18:45:58 +08:00
ClsDataPreprocessor
2022-08-29 15:35:10 +08:00
2023-03-02 13:29:07 +08:00
.. module :: mmpretrain.models.utils.batch_augments
2022-08-29 15:35:10 +08:00
Batch Augmentations
^^^^^^^^^^^^^^^^^^^^
The batch augmentation is a component of data preprocessors. It involves multiple samples and mix them in some way, such as Mixup and CutMix.
These augmentations are usually only used during training, therefore, we use the `` model.train_cfg `` field to configure them in config files.
.. code-block :: python
model = dict(
backbone=...,
neck=...,
head=...,
train_cfg=dict(augments=[
2022-10-17 17:08:18 +08:00
dict(type='Mixup', alpha=0.8),
dict(type='CutMix', alpha=1.0),
2022-08-29 15:35:10 +08:00
]),
)
2022-11-02 10:59:59 +08:00
You can also specify the probabilities of every batch augmentation by the `` probs `` field.
2022-08-29 15:35:10 +08:00
.. code-block :: python
model = dict(
backbone=...,
neck=...,
head=...,
train_cfg=dict(augments=[
2022-10-17 17:08:18 +08:00
dict(type='Mixup', alpha=0.8),
dict(type='CutMix', alpha=1.0),
2022-08-29 15:35:10 +08:00
], probs=[0.3, 0.7])
)
Here is a list of batch augmentations can be used in MMClassification.
.. autosummary ::
:toctree: generated
:nosignatures:
2023-02-08 14:30:12 +08:00
:template: callable.rst
2022-04-15 20:19:20 +08:00
2022-08-29 15:35:10 +08:00
Mixup
CutMix
ResizeMix