Skip to content

Commit

Permalink
Add table with supported targets to README.md (albumentations-team#196)
Browse files Browse the repository at this point in the history
* Add table with supported targets to README.md

* Update code for generating table with supported targets

* Update README.md with pixel-level and spatial-level transforms info

* Update description for pixel-level transforms
  • Loading branch information
creafz authored and albu committed Feb 18, 2019
1 parent 2ad9091 commit 594a7c2
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 11 deletions.
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,67 @@ conda install albumentations -c albumentations
The full documentation is available at [albumentations.readthedocs.io](https://albumentations.readthedocs.io/en/latest/).


## Pixel-level transforms
Pixel-level transforms will change just an input image and will leave any additional targets such as masks, bounding boxes, and keypoints unchanged. The list of pixel-level transforms:
- [Blur](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.Blur)
- [CLAHE](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.CLAHE)
- [ChannelShuffle](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.ChannelShuffle)
- [Cutout](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.Cutout)
- [FromFloat](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.FromFloat)
- [GaussNoise](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.GaussNoise)
- [HueSaturationValue](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.HueSaturationValue)
- [IAAAdditiveGaussianNoise](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.imgaug.transforms.IAAAdditiveGaussianNoise)
- [IAAEmboss](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.imgaug.transforms.IAAEmboss)
- [IAASharpen](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.imgaug.transforms.IAASharpen)
- [IAASuperpixels](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.imgaug.transforms.IAASuperpixels)
- [InvertImg](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.InvertImg)
- [JpegCompression](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.JpegCompression)
- [MedianBlur](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.MedianBlur)
- [MotionBlur](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.MotionBlur)
- [Normalize](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.Normalize)
- [RGBShift](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.RGBShift)
- [RandomBrightness](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.RandomBrightness)
- [RandomBrightnessContrast](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.RandomBrightnessContrast)
- [RandomContrast](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.RandomContrast)
- [RandomGamma](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.RandomGamma)
- [ToFloat](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.ToFloat)
- [ToGray](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.ToGray)


## Spatial-level transforms
Spatial-level transforms will simultaneously change both an input image as well as additional targets such as masks, bounding boxes, and keypoints. The following table shows which additional targets are supported by each transform.

| Transform | Image | Masks | BBoxes | Keypoints |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | :---: | :---: | :----: | :-------: |
| [CenterCrop](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.CenterCrop) |||||
| [Crop](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.Crop) |||| |
| [ElasticTransform](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.ElasticTransform) ||| | |
| [Flip](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.Flip) |||||
| [GridDistortion](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.GridDistortion) ||| | |
| [HorizontalFlip](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.HorizontalFlip) |||||
| [IAAAffine](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.imgaug.transforms.IAAAffine) |||||
| [IAACropAndPad](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.imgaug.transforms.IAACropAndPad) |||||
| [IAAFliplr](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.imgaug.transforms.IAAFliplr) |||||
| [IAAFlipud](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.imgaug.transforms.IAAFlipud) |||||
| [IAAPerspective](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.imgaug.transforms.IAAPerspective) |||||
| [IAAPiecewiseAffine](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.imgaug.transforms.IAAPiecewiseAffine) |||||
| [LongestMaxSize](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.LongestMaxSize) |||| |
| NoOp |||||
| [OpticalDistortion](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.OpticalDistortion) ||| | |
| [PadIfNeeded](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.PadIfNeeded) |||||
| [RandomCrop](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.RandomCrop) |||||
| [RandomCropNearBBox](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.RandomCropNearBBox) |||| |
| [RandomRotate90](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.RandomRotate90) |||||
| [RandomScale](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.RandomScale) |||||
| [RandomSizedBBoxSafeCrop](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.RandomSizedBBoxSafeCrop) |||| |
| [RandomSizedCrop](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.RandomSizedCrop) |||||
| [Resize](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.Resize) |||| |
| [Rotate](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.Rotate) |||||
| [ShiftScaleRotate](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.ShiftScaleRotate) |||||
| [SmallestMaxSize](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.SmallestMaxSize) |||| |
| [Transpose](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.Transpose) |||| |
| [VerticalFlip](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations.augmentations.transforms.VerticalFlip) |||||

## Migrating from torchvision to albumentations

Migrating from torchvision to albumentations is simple - you just need to change a few lines of code.
Expand Down
22 changes: 11 additions & 11 deletions albumentations/augmentations/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class PadIfNeeded(DualTransform):
value (list of ints [r, g, b]): padding value if border_mode is cv2.BORDER_CONSTANT.
Targets:
image, mask, bbox, keypoint
image, mask, bbox, keypoints
Image types:
uint8, float32
Expand Down Expand Up @@ -119,7 +119,7 @@ class VerticalFlip(DualTransform):
p (float): probability of applying the transform. Default: 0.5.
Targets:
image, mask, bboxes
image, mask, bboxes, keypoints
Image types:
uint8, float32
Expand All @@ -142,7 +142,7 @@ class HorizontalFlip(DualTransform):
p (float): probability of applying the transform. Default: 0.5.
Targets:
image, mask, bboxes
image, mask, bboxes, keypoints
Image types:
uint8, float32
Expand All @@ -165,7 +165,7 @@ class Flip(DualTransform):
p (float): probability of applying the transform. Default: 0.5.
Targets:
image, mask, bboxes
image, mask, bboxes, keypoints
Image types:
uint8, float32
Expand Down Expand Up @@ -302,7 +302,7 @@ class RandomRotate90(DualTransform):
p (float): probability of applying the transform. Default: 0.5.
Targets:
image, mask, bboxes
image, mask, bboxes, keypoints
Image types:
uint8, float32
Expand Down Expand Up @@ -341,7 +341,7 @@ class Rotate(DualTransform):
p (float): probability of applying the transform. Default: 0.5.
Targets:
image, mask, bboxes
image, mask, bboxes, keypoints
Image types:
uint8, float32
Expand Down Expand Up @@ -379,7 +379,7 @@ class RandomScale(DualTransform):
p (float): probability of applying the transform. Default: 0.5.
Targets:
image, mask, bboxes
image, mask, bboxes, keypoints
Image types:
uint8, float32
Expand Down Expand Up @@ -424,7 +424,7 @@ class ShiftScaleRotate(DualTransform):
p (float): probability of applying the transform. Default: 0.5.
Targets:
image, mask
image, mask, keypoints
Image types:
uint8, float32
Expand Down Expand Up @@ -465,7 +465,7 @@ class CenterCrop(DualTransform):
p (float): probability of applying the transform. Default: 1.
Targets:
image, mask, bboxes
image, mask, bboxes, keypoints
Image types:
uint8, float32
Expand Down Expand Up @@ -500,7 +500,7 @@ class RandomCrop(DualTransform):
p (float): probability of applying the transform. Default: 1.
Targets:
image, mask, bboxes
image, mask, bboxes, keypoints
Image types:
uint8, float32
Expand Down Expand Up @@ -587,7 +587,7 @@ class RandomSizedCrop(DualTransform):
p (float): probability of applying the transform. Default: 1.
Targets:
image, mask, bboxes
image, mask, bboxes, keypoints
Image types:
uint8, float32
Expand Down
120 changes: 120 additions & 0 deletions tools/make_supported_targets_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import inspect
import sys
from enum import Enum

sys.path.append('..')
import albumentations # noqa: E402


IGNORED_CLASSES = {
'BasicTransform',
'BasicIAATransform',
'DualIAATransform',
'DualTransform',
'ImageOnlyIAATransform',
'ImageOnlyTransform',
}


class Targets(Enum):
IMAGE = 'Image'
MASKS = 'Masks'
BBOXES = 'BBoxes'
KEYPOINTS = 'Keypoints'


READTHEDOCS_TEMPLATE = '[{name}](https://albumentations.readthedocs.io/en/latest/api/augmentations.html#albumentations'
TRANSFORM_NAME_WITH_LINK_TEMPLATE = READTHEDOCS_TEMPLATE + '.augmentations.transforms.{name})'
IMGAUG_TRANSFORM_NAME_WITH_LINK_TEMPLATE = READTHEDOCS_TEMPLATE + '.imgaug.transforms.{name})'


def make_separator(width, align_center):
if align_center:
return ':' + '-' * (width - 2) + ':'
return '-' * width


def get_transforms_info():
transforms_info = {}
for name, cls in inspect.getmembers(albumentations):
if (
inspect.isclass(cls) and
issubclass(cls, albumentations.BasicTransform) and
name not in IGNORED_CLASSES
):

targets = {Targets.IMAGE}
if issubclass(cls, albumentations.DualTransform):
targets.add(Targets.MASKS)

if hasattr(cls, 'apply_to_bbox') and cls.apply_to_bbox is not albumentations.DualTransform.apply_to_bbox:
targets.add(Targets.BBOXES)

if (
hasattr(cls, 'apply_to_keypoint') and
cls.apply_to_keypoint is not albumentations.DualTransform.apply_to_keypoint
):
targets.add(Targets.KEYPOINTS)

if issubclass(cls, albumentations.DualIAATransform):
targets.update({Targets.BBOXES, Targets.KEYPOINTS})

docs_link = None
if cls.__module__ == 'albumentations.augmentations.transforms':
docs_link = TRANSFORM_NAME_WITH_LINK_TEMPLATE.format(name=name)
elif cls.__module__ == 'albumentations.imgaug.transforms':
docs_link = IMGAUG_TRANSFORM_NAME_WITH_LINK_TEMPLATE.format(name=name)

transforms_info[name] = {
'targets': targets,
'docs_link': docs_link,
'image_only': issubclass(cls, albumentations.ImageOnlyTransform)
}
return transforms_info


def make_transforms_targets_table(transforms_info, header):
rows = [header]
for transform, info in sorted(transforms_info.items(), key=lambda kv: kv[0]):
transform_targets = []
for target in Targets:
mark = '✓' if target in info['targets'] else ''
transform_targets.append(mark)
row = [info['docs_link'] or transform] + transform_targets
rows.append(row)

column_widths = [max([len(r) for r in column]) for column in zip(*rows)]
lines = [
' | '.join(
'{title: <{width}}'.format(width=width, title=title) for width, title in zip(column_widths, rows[0])
),
' | '.join(
make_separator(width, align_center=column_index > 0) for column_index, width in enumerate(column_widths)
)
]
for row in rows[1:]:
lines.append(' | '.join(
'{column: <{width}}'.format(width=width, column=column)
for width, column in zip(column_widths, row)
))
return '\n'.join('| {line} |'.format(line=line) for line in lines)


def make_transforms_targets_links(transforms_info):
return '\n'.join(
'- ' + info['docs_link'] for transform, info in sorted(transforms_info.items(), key=lambda kv: kv[0])
)


if __name__ == '__main__':
if __name__ == '__main__':
transforms_info = get_transforms_info()
image_only_transforms = {transform: info for transform, info in transforms_info.items() if info['image_only']}
dual_transforms = {transform: info for transform, info in transforms_info.items() if not info['image_only']}
image_only_transforms_links = make_transforms_targets_links(image_only_transforms)
dual_transforms_table = make_transforms_targets_table(
dual_transforms,
header=['Transform'] + [target.value for target in Targets],
)
print(image_only_transforms_links)
print(dual_transforms_table)

0 comments on commit 594a7c2

Please sign in to comment.