We introduce some modifications in MMClassification 1.x, and some of them are BC-breading. To migrate your projects from MMClassification 0.x smoothly, please read this tutorial.
## New dependencies
MMClassification 1.x depends on some new packages, you can prepare a new clean environment and install again
according to the [install tutorial](./get_started.md). Or install the below packages manually.
1. [MMEngine](https://github.com/open-mmlab/mmengine): MMEngine is the core the OpenMMLab 2.0 architecture,
and we splited many compentents unrelated to computer vision from MMCV to MMEngine.
2. [MMCV](https://github.com/open-mmlab/mmcv): The computer vision package of OpenMMLab. This is not a new
dependency, but you need to upgrade it to above `2.0.0rc0` version.
3. [rich](https://github.com/Textualize/rich): A terminal formatting package, and we use it to beautify some
outputs in the terminal.
## Configuration files
In MMClassification 1.x, we refactored the structure of configuration files, and the original files are not usable.
<!-- TODO: migration tool -->
In this section, we will introduce all changes of the configuration files. And we assume you already have
ideas of the [config files](./user_guides/config.md).
### Model settings
No changes in `model.backbone`, `model.neck` and `model.head` fields.
Changes in **`model.train_cfg`**:
-`BatchMixup` is renamed to [`Mixup`](Mixup).
-`BatchCutMix` is renamed to [`CutMix`](CutMix).
-`BatchResizeMix` is renamed to [`ResizeMix`](ResizeMix).
- The `prob` argument is removed from all augments settings, and you can use the `probs` field in `train_cfg` to
specify probabilities of every augemnts. If no `probs` field, randomly choose one by the same probability.
- The original formatting transforms **`ToTensor`**、**`ImageToTensor`**、**`Collect`** are combined as [`PackClsInputs`](PackClsInputs).
- We don't recommend to do **`Normalize`** in the dataset pipeline. Please remove it from pipelines and set it in the `data_preprocessor` field.
- The argument `flip_prob` in [**`RandomFlip`**](RandomFlip) is renamed to `flip`.
- The argument `size` in [**`RandomCrop`**](RandomCrop) is renamed to `crop_size`.
- The argument `size` in [**`RandomResizedCrop`**](RandomResizedCrop) is renamed to `scale`.
- The argument `size` in [**`Resize`**](Resize) is renamed to `scale`. And `Resize` won't support size like `(256, -1)`, please use [`ResizeEdge`](ResizeEdge) to replace it.
- The argument `policies` in [**`AutoAugment`**](AutoAugment) and [**`RandAugment`**](RandAugment) supports using string to specify preset policies. `AutoAugment` supports "imagenet" and `RandAugment` supports "timm_increasing".
- **`RandomResizedCrop`** and **`CenterCrop`** won't supports `efficientnet_style`, and please use [`EfficientnNetRandomCrop`](EfficientnNetRandomCrop) and [`EfficientNetCenterCrop`](EfficientNetCenterCrop) to replace them.
```{note}
We move some work of data transforms to the data preprocessor, like normalization, see [the documentation](mmcls.models.utils.data_preprocessor) for
- The **`evaluation`** field is splited to `val_evaluator` and `test_evaluator`. And it won't supports `interval` and `save_best` arguments.
The `interval` is moved to `train_cfg.val_interval`, see [the schedule settings](./user_guides/config.md#schedule-settings) and the `save_best`
is moved to `default_hooks.checkpoint.save_best`, see [the runtime settings](./user_guides/config.md#runtime-settings).
- The 'accuracy' metric is renamed to [`Accuracy`](mmcls.evaluation.Accuracy).
- The 'precision','recall','f1-score' and 'support' are combined as [`SingleLabelMetric`](mmcls.evaluation.SingleLabelMetric), and use `items` argument to specify to calculate which metric.
- The 'mAP' is renamed to [`AveragePrecision`](mmcls.evaluation.AveragePrecision).
- The 'CP', 'CR', 'CF1', 'OP', 'OR', 'OF1' are combined as [`MultiLabelMetric`](mmcls.evaluation.MultiLabelMetric), and use `items` and `average` arguments to specify to calculate which metric.
Changes in **`workflow`**: `workflow` related functionalities are removed.
New field **`visualizer`**: The visualizer is a new design in OpenMMLab 2.0 architecture. We use a
visualizer instance in the runner to handle results & log visualization and save to different backends.
See the [MMEngine tutorial](TODO) for more details.
```python
visualizer = dict(
type='ClsVisualizer',
vis_backends=[
dict(type='LocalVisBackend'),
# Uncomment the below line to save the log and visualization results to TensorBoard.
# dict(type='TensorboardVisBackend')
]
)
```
New field **`default_scope`**: The start point to search module for all registries. The `default_scope` in MMClassification is `mmcls`. See [the registry tutorial](TODO) for more details.
## Packages
### `mmcls.apis`
The documentation can be found [here](mmcls.apis).
| `evaluation` | Removed, use the metrics in [`mmcls.evaluation`](mmcls.evaluation). |
| `hook` | Moved to [`mmcls.engine.hooks`](mmcls.engine.hooks) |
| `optimizers` | Moved to [`mmcls.engine.optimizers`](mmcls.engine.optimizers) |
| `utils` | Removed, the distributed environment related functions can be found in the [`mmengine.dist`](mmengine.dist) package. |
| `visualization` | Removed, the related functionalities are implemented in [`mmengine.visualization.Visualizer`](mmengine.visualization.Visualizer). |
The `MMClsWandbHook` in `hooks` package is waiting for implementation.
The `CosineAnnealingCooldownLrUpdaterHook` in `hooks` package is removed, and we support this functionality by
the combination of parameter schedulers, see [the tutorial](./advanced_guides/schedule.md).
### `mmcls.datasets`
The documentation can be found [here](mmcls.datasets).
| `LoadImageFromFile` | Removed, use [`mmcv.transforms.LoadImageFromFile`](mmcv.transforms.LoadImageFromFile). |
| `RandomFlip` | Removed, use [`mmcv.transforms.RandomFlip`](mmcv.transforms.RandomFlip). The argument `flip_prob` is renamed to `prob`. |
| `RandomCrop` | The argument `size` is renamed to `crop_size`. |
| `RandomResizedCrop` | The argument `size` is renamed to `scale`. The argument `scale` is renamed to `crop_ratio_range`. Won't support `efficientnet_style`, use [`EfficientNetRandomCrop`](EfficientNetRandomCrop). |
| `CenterCrop` | Removed, use [`mmcv.transforms.CenterCrop`](mmcv.transforms.CenterCrop). Won't support `efficientnet_style`, use [`EfficientNetCenterCrop`](EfficientNetCenterCrop). |
| `Resize` | Removed, use [`mmcv.transforms.Resize`](mmcv.transforms.Resize). The argument `size` is renamed to `scale`. Won't support size like `(256, -1)`, use [`ResizeEdge`](ResizeEdge). |
| `AutoAugment`&`RandomAugment` | The argument `policies` supports using string to specify preset policies. |
| `Compose` | Removed, use [`mmcv.transforms.Compose`](mmcv.transforms.Compose). |
### `mmcls.models`
The documentation can be found [here](mmcls.models). The interface of all **backbones**, **necks** and **losses** didn't change.
| `forward` | Now only accepts three arguments: `inputs`, `data_samples` and `mode`. See [the documentation](ImageClassifier.forward) for more details. |
| `forward_train` | Replaced by `loss`. |
| `simple_test` | Replaced by `predict`. |
| `train_step` | The `optimizer` argument is replaced by `optim_wrapper` and it accepts [`OptimWrapper`](mmengine.optim.OptimWrapper). |
| `val_step` | The original `val_step` is the same as `train_step`, now it calls `predict`. |
| `test_step` | New method, and it's the same as `val_step`. |