Shortcuts

Albumentations

class mmcls.datasets.transforms.Albumentations(transforms, keymap=None)[source]

Wrapper to use augmentation from albumentations library.

Required Keys:

  • img

Modified Keys:

  • img

  • img_shape

Adds custom transformations from albumentations library. More details can be found in Albumentations. An example of transforms is as followed:

[
    dict(
        type='ShiftScaleRotate',
        shift_limit=0.0625,
        scale_limit=0.0,
        rotate_limit=0,
        interpolation=1,
        p=0.5),
    dict(
        type='RandomBrightnessContrast',
        brightness_limit=[0.1, 0.3],
        contrast_limit=[0.1, 0.3],
        p=0.2),
    dict(type='ChannelShuffle', p=0.1),
    dict(
        type='OneOf',
        transforms=[
            dict(type='Blur', blur_limit=3, p=1.0),
            dict(type='MedianBlur', blur_limit=3, p=1.0)
        ],
        p=0.1),
]
Parameters
  • transforms (List[Dict]) – List of albumentations transform configs.

  • keymap (Optional[Dict]) – Mapping of mmcls to albumentations fields, in format {‘input key’:’albumentation-style key’}. Defaults to None.

Example

>>> import mmcv
>>> from mmcls.datasets import Albumentations
>>> transforms = [
...     dict(
...         type='ShiftScaleRotate',
...         shift_limit=0.0625,
...         scale_limit=0.0,
...         rotate_limit=0,
...         interpolation=1,
...         p=0.5),
...     dict(
...         type='RandomBrightnessContrast',
...         brightness_limit=[0.1, 0.3],
...         contrast_limit=[0.1, 0.3],
...         p=0.2),
...     dict(type='ChannelShuffle', p=0.1),
...     dict(
...         type='OneOf',
...         transforms=[
...             dict(type='Blur', blur_limit=3, p=1.0),
...             dict(type='MedianBlur', blur_limit=3, p=1.0)
...         ],
...         p=0.1),
... ]
>>> albu = Albumentations(transforms)
>>> data = {'img': mmcv.imread('./demo/demo.JPEG')}
>>> data = albu(data)
>>> print(data['img'].shape)
(375, 500, 3)
albu_builder(cfg)[source]

Import a module from albumentations.

It inherits some of build_from_cfg() logic. :param cfg: Config dict. It should at least contain the key “type”. :type cfg: dict

Returns

The constructed object.

Return type

obj

static mapper(d, keymap)[source]

Dictionary mapper.

Renames keys according to keymap provided. :param d: old dict :type d: dict :param keymap: {‘old_key’:’new_key’} :type keymap: dict

Returns

new dict.

Return type

dict

transform(results)[source]

Transform function to perform albumentations transforms.

Parameters

results (dict) – Result dict from loading pipeline.

Returns

Transformed results, ‘img’ and ‘img_shape’ keys are

updated in result dict.

Return type

dict

Read the Docs v: 1.x
Versions
master
latest
1.x
dev-1.x
Downloads
html
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.