Shortcuts

Albumentations

class mmcls.datasets.transforms.Albumentations(transforms, keymap=None)[源代码]

使用 Albumentations 库进行数据变换的封装类

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),
]
参数
  • 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.

示例

>>> 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)[源代码]

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

返回

The constructed object.

返回类型

obj

static mapper(d, keymap)[源代码]

Dictionary mapper.

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

返回

new dict.

返回类型

dict

transform(results)[源代码]

Transform function to perform albumentations transforms.

参数

results (dict) – Result dict from loading pipeline.

返回

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

updated in result dict.

返回类型

dict

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

Free document hosting provided by Read the Docs.