From f452e242a7b9038aaf87ed16f05c784e7c02950f Mon Sep 17 00:00:00 2001 From: mzr1996 Date: Sun, 9 Oct 2022 08:14:06 +0800 Subject: [PATCH 1/2] [Docs] Fix `mmcv-full` in docs. --- docker/Dockerfile | 2 +- docker/serve/Dockerfile | 2 +- docs/zh_CN/get_started.md | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index dea9f30b1a0..2f0b204dbc9 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -14,7 +14,7 @@ RUN apt-get update && apt-get install -y ffmpeg libsm6 libxext6 git ninja-build # Install MMCV RUN pip install openmim -RUN mim install mmengine "mmcv-full>=2.0rc0" +RUN mim install mmengine "mmcv>=2.0rc0" # Install MMClassification RUN conda clean --all diff --git a/docker/serve/Dockerfile b/docker/serve/Dockerfile index dbfba3adcb9..a418cb13b8d 100644 --- a/docker/serve/Dockerfile +++ b/docker/serve/Dockerfile @@ -27,7 +27,7 @@ RUN pip install torchserve torch-model-archiver ARG PYTORCH ARG CUDA RUN pip install mmengine -RUN ["/bin/bash", "-c", "pip install mmcv-full==${MMCV} -f https://download.openmmlab.com/mmcv/dist/cu${CUDA//./}/torch${PYTORCH}/index.html"] +RUN ["/bin/bash", "-c", "pip install mmcv==${MMCV} -f https://download.openmmlab.com/mmcv/dist/cu${CUDA//./}/torch${PYTORCH}/index.html"] RUN pip install mmcls==${MMCLS} RUN useradd -m model-server \ diff --git a/docs/zh_CN/get_started.md b/docs/zh_CN/get_started.md index 5a48da9d6d1..942d51d28bb 100644 --- a/docs/zh_CN/get_started.md +++ b/docs/zh_CN/get_started.md @@ -47,7 +47,7 @@ conda install pytorch torchvision cpuonly -c pytorch ```shell pip install -U openmim -mim install mmengine "mmcv-full>=2.0rc0" +mim install mmengine "mmcv>=2.0rc0" ``` **第 2 步** 安装 MMClassification @@ -145,10 +145,10 @@ MMCV 包含 C++ 和 CUDA 扩展,因此其对 PyTorch 的依赖比较复杂。M 要使用 pip 而不是 MIM 来安装 MMCV,请遵照 [MMCV 安装指南](https://mmcv.readthedocs.io/zh_CN/latest/get_started/installation.html)。 它需要你用指定 url 的形式手动指定对应的 PyTorch 和 CUDA 版本。 -举个例子,如下命令将会安装基于 PyTorch 1.10.x 和 CUDA 11.3 编译的 mmcv-full。 +举个例子,如下命令将会安装基于 PyTorch 1.10.x 和 CUDA 11.3 编译的 mmcv。 ```shell -pip install "mmcv-full>=2.0rc0" -f https://download.openmmlab.com/mmcv/dist/cu113/torch1.10/index.html +pip install "mmcv>=2.0rc0" -f https://download.openmmlab.com/mmcv/dist/cu113/torch1.10/index.html ``` ### 在 CPU 环境中安装 @@ -166,7 +166,7 @@ MMClassification 中几乎所有的模型都不会依赖这些算子。 ```shell !pip3 install openmim -!mim install mmengine "mmcv-full>=2.0rc0" +!mim install mmengine "mmcv>=2.0rc0" ``` **第 2 步** 从源码安装 MMClassification From 2153a16dc5759e7cf05672224b5cd8825c06cf79 Mon Sep 17 00:00:00 2001 From: mzr1996 Date: Mon, 10 Oct 2022 11:17:48 +0800 Subject: [PATCH 2/2] [Docs] Fix some docstrings. --- docs/en/api/data_process.rst | 1 + mmcls/datasets/transforms/__init__.py | 10 ++--- mmcls/datasets/transforms/auto_augment.py | 50 ++++++++++++----------- mmcls/models/backbones/twins.py | 38 ++++++++--------- 4 files changed, 51 insertions(+), 48 deletions(-) diff --git a/docs/en/api/data_process.rst b/docs/en/api/data_process.rst index 421b52b1be9..0b1bb0830e0 100644 --- a/docs/en/api/data_process.rst +++ b/docs/en/api/data_process.rst @@ -122,6 +122,7 @@ And you can also configure a group of policies manually by selecting from the be Solarize SolarizeAdd Translate + BaseAugTransform Formatting ^^^^^^^^^^ diff --git a/mmcls/datasets/transforms/__init__.py b/mmcls/datasets/transforms/__init__.py index 8d3ed3a3afa..8ea8db3d78f 100644 --- a/mmcls/datasets/transforms/__init__.py +++ b/mmcls/datasets/transforms/__init__.py @@ -1,8 +1,8 @@ # Copyright (c) OpenMMLab. All rights reserved. -from .auto_augment import (AutoAugment, AutoContrast, Brightness, - ColorTransform, Contrast, Cutout, Equalize, Invert, - Posterize, RandAugment, Rotate, Sharpness, Shear, - Solarize, SolarizeAdd, Translate) +from .auto_augment import (AutoAugment, AutoContrast, BaseAugTransform, + Brightness, ColorTransform, Contrast, Cutout, + Equalize, Invert, Posterize, RandAugment, Rotate, + Sharpness, Shear, Solarize, SolarizeAdd, Translate) from .formatting import Collect, PackClsInputs, ToNumpy, ToPIL, Transpose from .processing import (Albumentations, ColorJitter, EfficientNetCenterCrop, EfficientNetRandomCrop, Lighting, RandomCrop, @@ -15,5 +15,5 @@ 'Contrast', 'Brightness', 'Sharpness', 'AutoAugment', 'SolarizeAdd', 'Cutout', 'RandAugment', 'Lighting', 'ColorJitter', 'RandomErasing', 'PackClsInputs', 'Albumentations', 'EfficientNetRandomCrop', - 'EfficientNetCenterCrop', 'ResizeEdge' + 'EfficientNetCenterCrop', 'ResizeEdge', 'BaseAugTransform' ] diff --git a/mmcls/datasets/transforms/auto_augment.py b/mmcls/datasets/transforms/auto_augment.py index c8e3f53d6c9..e289c216e2e 100644 --- a/mmcls/datasets/transforms/auto_augment.py +++ b/mmcls/datasets/transforms/auto_augment.py @@ -362,7 +362,7 @@ class Shear(BaseAugTransform): Args: magnitude (int | float | None): The magnitude used for shear. If None, - generate from ``magnitude_range``, see :class:`AugTransform`. + generate from ``magnitude_range``, see :class:`BaseAugTransform`. Defaults to None. pad_val (int, Sequence[int]): Pixel pad_val value for constant fill. If a sequence of length 3, it is used to pad_val R, G, B channels @@ -375,7 +375,7 @@ class Shear(BaseAugTransform): negative, which should be in range [0,1]. Defaults to 0.5. interpolation (str): Interpolation method. Options are 'nearest', 'bilinear', 'bicubic', 'area', 'lanczos'. Defaults to 'bicubic'. - **kwargs: Other keyword arguments of :class:`AugTransform`. + **kwargs: Other keyword arguments of :class:`BaseAugTransform`. """ def __init__(self, @@ -444,7 +444,7 @@ class Translate(BaseAugTransform): that the offset is calculated by magnitude * size in the corresponding direction. With a magnitude of 1, the whole image will be moved out of the range. If None, generate from - ``magnitude_range``, see :class:`AugTransform`. + ``magnitude_range``, see :class:`BaseAugTransform`. pad_val (int, Sequence[int]): Pixel pad_val value for constant fill. If a sequence of length 3, it is used to pad_val R, G, B channels respectively. Defaults to 128. @@ -456,7 +456,7 @@ class Translate(BaseAugTransform): negative, which should be in range [0,1]. Defaults to 0.5. interpolation (str): Interpolation method. Options are 'nearest', 'bilinear', 'bicubic', 'area', 'lanczos'. Defaults to 'nearest'. - **kwargs: Other keyword arguments of :class:`AugTransform`. + **kwargs: Other keyword arguments of :class:`BaseAugTransform`. """ def __init__(self, @@ -528,7 +528,8 @@ class Rotate(BaseAugTransform): Args: angle (float, optional): The angle used for rotate. Positive values stand for clockwise rotation. If None, generate from - ``magnitude_range``, see :class:`AugTransform`. Defaults to None. + ``magnitude_range``, see :class:`BaseAugTransform`. + Defaults to None. center (tuple[float], optional): Center point (w, h) of the rotation in the source image. If None, the center of the image will be used. Defaults to None. @@ -542,7 +543,7 @@ class Rotate(BaseAugTransform): negative, which should be in range [0,1]. Defaults to 0.5. interpolation (str): Interpolation method. Options are 'nearest', 'bilinear', 'bicubic', 'area', 'lanczos'. Defaults to 'nearest'. - **kwargs: Other keyword arguments of :class:`AugTransform`. + **kwargs: Other keyword arguments of :class:`BaseAugTransform`. """ def __init__(self, @@ -610,7 +611,7 @@ class AutoContrast(BaseAugTransform): Args: prob (float): The probability for performing auto contrast therefore should be in range [0, 1]. Defaults to 0.5. - **kwargs: Other keyword arguments of :class:`AugTransform`. + **kwargs: Other keyword arguments of :class:`BaseAugTransform`. """ def __init__(self, prob: float = 0.5, **kwargs): @@ -640,7 +641,7 @@ class Invert(BaseAugTransform): Args: prob (float): The probability for performing invert therefore should be in range [0, 1]. Defaults to 0.5. - **kwargs: Other keyword arguments of :class:`AugTransform`. + **kwargs: Other keyword arguments of :class:`BaseAugTransform`. """ def __init__(self, prob: float = 0.5, **kwargs): @@ -670,7 +671,7 @@ class Equalize(BaseAugTransform): Args: prob (float): The probability for performing equalize therefore should be in range [0, 1]. Defaults to 0.5. - **kwargs: Other keyword arguments of :class:`AugTransform`. + **kwargs: Other keyword arguments of :class:`BaseAugTransform`. """ def __init__(self, prob: float = 0.5, **kwargs): @@ -700,10 +701,10 @@ class Solarize(BaseAugTransform): Args: thr (int | float | None): The threshold above which the pixels value will be inverted. If None, generate from ``magnitude_range``, - see :class:`AugTransform`. Defaults to None. + see :class:`BaseAugTransform`. Defaults to None. prob (float): The probability for solarizing therefore should be in range [0, 1]. Defaults to 0.5. - **kwargs: Other keyword arguments of :class:`AugTransform`. + **kwargs: Other keyword arguments of :class:`BaseAugTransform`. """ def __init__(self, @@ -746,12 +747,12 @@ class SolarizeAdd(BaseAugTransform): Args: magnitude (int | float | None): The value to be added to pixels below the thr. If None, generate from ``magnitude_range``, see - :class:`AugTransform`. Defaults to None. + :class:`BaseAugTransform`. Defaults to None. thr (int | float): The threshold below which the pixels value will be adjusted. prob (float): The probability for solarizing therefore should be in range [0, 1]. Defaults to 0.5. - **kwargs: Other keyword arguments of :class:`AugTransform`. + **kwargs: Other keyword arguments of :class:`BaseAugTransform`. """ def __init__(self, @@ -801,10 +802,11 @@ class Posterize(BaseAugTransform): Args: bits (int, optional): Number of bits for each pixel in the output img, which should be less or equal to 8. If None, generate from - ``magnitude_range``, see :class:`AugTransform`. Defaults to None. + ``magnitude_range``, see :class:`BaseAugTransform`. + Defaults to None. prob (float): The probability for posterizing therefore should be in range [0, 1]. Defaults to 0.5. - **kwargs: Other keyword arguments of :class:`AugTransform`. + **kwargs: Other keyword arguments of :class:`BaseAugTransform`. """ def __init__(self, @@ -855,7 +857,7 @@ class Contrast(BaseAugTransform): contrast. A positive magnitude would enhance the contrast and a negative magnitude would make the image grayer. A magnitude=0 gives the origin img. If None, generate from ``magnitude_range``, - see :class:`AugTransform`. Defaults to None. + see :class:`BaseAugTransform`. Defaults to None. prob (float): The probability for performing contrast adjusting therefore should be in range [0, 1]. Defaults to 0.5. random_negative_prob (float): The probability that turns the magnitude @@ -908,12 +910,12 @@ class ColorTransform(BaseAugTransform): A positive magnitude would enhance the color and a negative magnitude would make the image grayer. A magnitude=0 gives the origin img. If None, generate from ``magnitude_range``, see - :class:`AugTransform`. Defaults to None. + :class:`BaseAugTransform`. Defaults to None. prob (float): The probability for performing ColorTransform therefore should be in range [0, 1]. Defaults to 0.5. random_negative_prob (float): The probability that turns the magnitude negative, which should be in range [0,1]. Defaults to 0.5. - **kwargs: Other keyword arguments of :class:`AugTransform`. + **kwargs: Other keyword arguments of :class:`BaseAugTransform`. """ def __init__(self, @@ -962,12 +964,12 @@ class Brightness(BaseAugTransform): brightness. A positive magnitude would enhance the brightness and a negative magnitude would make the image darker. A magnitude=0 gives the origin img. If None, generate from ``magnitude_range``, see - :class:`AugTransform`. Defaults to None. + :class:`BaseAugTransform`. Defaults to None. prob (float): The probability for performing brightness adjusting therefore should be in range [0, 1]. Defaults to 0.5. random_negative_prob (float): The probability that turns the magnitude negative, which should be in range [0,1]. Defaults to 0.5. - **kwargs: Other keyword arguments of :class:`AugTransform`. + **kwargs: Other keyword arguments of :class:`BaseAugTransform`. """ def __init__(self, @@ -1016,12 +1018,12 @@ class Sharpness(BaseAugTransform): sharpness. A positive magnitude would enhance the sharpness and a negative magnitude would make the image bulr. A magnitude=0 gives the origin img. If None, generate from ``magnitude_range``, see - :class:`AugTransform`. Defaults to None. + :class:`BaseAugTransform`. Defaults to None. prob (float): The probability for performing sharpness adjusting therefore should be in range [0, 1]. Defaults to 0.5. random_negative_prob (float): The probability that turns the magnitude negative, which should be in range [0,1]. Defaults to 0.5. - **kwargs: Other keyword arguments of :class:`AugTransform`. + **kwargs: Other keyword arguments of :class:`BaseAugTransform`. """ def __init__(self, @@ -1069,13 +1071,13 @@ class Cutout(BaseAugTransform): shape (int | tuple(int) | None): Expected cutout shape (h, w). If given as a single value, the value will be used for both h and w. If None, generate from ``magnitude_range``, see - :class:`AugTransform`. Defaults to None. + :class:`BaseAugTransform`. Defaults to None. pad_val (int, Sequence[int]): Pixel pad_val value for constant fill. If it is a sequence, it must have the same length with the image channels. Defaults to 128. prob (float): The probability for performing cutout therefore should be in range [0, 1]. Defaults to 0.5. - **kwargs: Other keyword arguments of :class:`AugTransform`. + **kwargs: Other keyword arguments of :class:`BaseAugTransform`. """ def __init__(self, diff --git a/mmcls/models/backbones/twins.py b/mmcls/models/backbones/twins.py index de797643167..7c9b784d94f 100644 --- a/mmcls/models/backbones/twins.py +++ b/mmcls/models/backbones/twins.py @@ -367,21 +367,21 @@ class PCPVT(BaseModule): - strides (List[int]): The strides in each stage. - mlp_ratios (List[int]): The ratios of mlp in each stage. - sr_ratios (List[int]): The ratios of GSA-encoder layers in each - stage. + stage. - in_channels (int): Number of input channels. Default: 3. + in_channels (int): Number of input channels. Defaults to 3. out_indices (tuple[int]): Output from which stages. - Default: (3, ). - qkv_bias (bool): Enable bias for qkv if True. Default: False. + Defaults to ``(3, )``. + qkv_bias (bool): Enable bias for qkv if True. Defaults to False. drop_rate (float): Probability of an element to be zeroed. - Default 0. + Defaults to 0. attn_drop_rate (float): The drop out rate for attention layer. - Default 0.0 - drop_path_rate (float): Stochastic depth rate. Default 0.0 + Defaults to 0.0 + drop_path_rate (float): Stochastic depth rate. Defaults to 0.0. norm_cfg (dict): Config dict for normalization layer. - Default: dict(type='LN') + Defaults to ``dict(type='LN')``. norm_after_stage(bool, List[bool]): Add extra norm after each stage. - Default False. + Defaults to False. init_cfg (dict, optional): The Config for initialization. Defaults to None. @@ -613,22 +613,22 @@ class SVT(PCPVT): - strides (List[int]): The strides in each stage. - mlp_ratios (List[int]): The ratios of mlp in each stage. - sr_ratios (List[int]): The ratios of GSA-encoder layers in each - stage. + stage. - windiow_sizes (List[int]): The window sizes in LSA-encoder layers - in each stage. + in each stage. - in_channels (int): Number of input channels. Default: 3. + in_channels (int): Number of input channels. Defaults to 3. out_indices (tuple[int]): Output from which stages. - Default: (3, ). - qkv_bias (bool): Enable bias for qkv if True. Default: False. - drop_rate (float): Dropout rate. Default 0. + Defaults to (3, ). + qkv_bias (bool): Enable bias for qkv if True. Defaults to False. + drop_rate (float): Dropout rate. Defaults to 0. attn_drop_rate (float): Dropout ratio of attention weight. - Default 0.0 - drop_path_rate (float): Stochastic depth rate. Default 0.2. + Defaults to 0.0 + drop_path_rate (float): Stochastic depth rate. Defaults to 0.2. norm_cfg (dict): Config dict for normalization layer. - Default: dict(type='LN') + Defaults to ``dict(type='LN')``. norm_after_stage(bool, List[bool]): Add extra norm after each stage. - Default False. + Defaults to False. init_cfg (dict, optional): The Config for initialization. Defaults to None.