GithubHelp home page GithubHelp logo

albumentations-team / albumentations Goto Github PK

View Code? Open in Web Editor NEW
13.4K 129.0 1.6K 100.33 MB

Fast image augmentation library and an easy-to-use wrapper around other libraries. Documentation: https://albumentations.ai/docs/ Paper about the library: https://www.mdpi.com/2078-2489/11/2/125

Home Page: https://albumentations.ai

License: MIT License

Python 99.91% Shell 0.09%
image-augmentation machine-learning augmentation deep-learning detection fast-augmentations segmentation image-segmentation image-processing image-classification

albumentations's Introduction

Albumentations

PyPI version CI PyPI Downloads Conda Downloads Stack Overflow License: MIT

Docs | Discord | Twitter | LinkedIn

Albumentations is a Python library for image augmentation. Image augmentation is used in deep learning and computer vision tasks to increase the quality of trained models. The purpose of image augmentation is to create new training samples from the existing data.

Here is an example of how you can apply some pixel-level augmentations from Albumentations to create new images from the original one: parrot

Why Albumentations

  • Albumentations supports all common computer vision tasks such as classification, semantic segmentation, instance segmentation, object detection, and pose estimation.
  • The library provides a simple unified API to work with all data types: images (RBG-images, grayscale images, multispectral images), segmentation masks, bounding boxes, and keypoints.
  • The library contains more than 70 different augmentations to generate new training samples from the existing data.
  • Albumentations is fast. We benchmark each new release to ensure that augmentations provide maximum speed.
  • It works with popular deep learning frameworks such as PyTorch and TensorFlow. By the way, Albumentations is a part of the PyTorch ecosystem.
  • Written by experts. The authors have experience both working on production computer vision systems and participating in competitive machine learning. Many core team members are Kaggle Masters and Grandmasters.
  • The library is widely used in industry, deep learning research, machine learning competitions, and open source projects.

Sponsors

Table of contents

Authors

Vladimir I. Iglovikov | Kaggle Grandmaster

Mikhail Druzhinin | Kaggle Expert

Alex Parinov | Kaggle Master

Alexander Buslaev — Computer Vision Engineer at Mapbox | Kaggle Master

Evegene Khvedchenya — Computer Vision Research Engineer at Piñata Farms | Kaggle Grandmaster

Installation

Albumentations requires Python 3.8 or higher. To install the latest version from PyPI:

pip install -U albumentations

Other installation options are described in the documentation.

Documentation

The full documentation is available at https://albumentations.ai/docs/.

A simple example

import albumentations as A
import cv2

# Declare an augmentation pipeline
transform = A.Compose([
    A.RandomCrop(width=256, height=256),
    A.HorizontalFlip(p=0.5),
    A.RandomBrightnessContrast(p=0.2),
])

# Read an image with OpenCV and convert it to the RGB colorspace
image = cv2.imread("image.jpg")
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Augment an image
transformed = transform(image=image)
transformed_image = transformed["image"]

Getting started

I am new to image augmentation

Please start with the introduction articles about why image augmentation is important and how it helps to build better models.

I want to use Albumentations for the specific task such as classification or segmentation

If you want to use Albumentations for a specific task such as classification, segmentation, or object detection, refer to the set of articles that has an in-depth description of this task. We also have a list of examples on applying Albumentations for different use cases.

I want to know how to use Albumentations with deep learning frameworks

We have examples of using Albumentations along with PyTorch and TensorFlow.

I want to explore augmentations and see Albumentations in action

Check the online demo of the library. With it, you can apply augmentations to different images and see the result. Also, we have a list of all available augmentations and their targets.

Who is using Albumentations

See also

List of augmentations

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:

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 Mask BBoxes Keypoints
Affine
BBoxSafeRandomCrop
CenterCrop
CoarseDropout
Crop
CropAndPad
CropNonEmptyMaskIfExists
D4
ElasticTransform
Flip
GridDistortion
GridDropout
HorizontalFlip
Lambda
LongestMaxSize
MaskDropout
Morphological
NoOp
OpticalDistortion
PadIfNeeded
Perspective
PiecewiseAffine
PixelDropout
RandomCrop
RandomCropFromBorders
RandomGridShuffle
RandomResizedCrop
RandomRotate90
RandomScale
RandomSizedBBoxSafeCrop
RandomSizedCrop
Resize
Rotate
SafeRotate
ShiftScaleRotate
SmallestMaxSize
Transpose
VerticalFlip
XYMasking

Mixing-level transforms

Transforms that mix several images into one

Transform Image Mask BBoxes Keypoints Global Label
MixUp

A few more examples of augmentations

Semantic segmentation on the Inria dataset

inria

Medical imaging

medical

Object detection and semantic segmentation on the Mapillary Vistas dataset

vistas

Keypoints augmentation

Benchmarking results

To run the benchmark yourself, follow the instructions in benchmark/README.md

Results for running the benchmark on the first 2000 images from the ImageNet validation set using an AMD Ryzen Threadripper 3970X CPU. The table shows how many images per second can be processed on a single core; higher is better.

Library Version
Python 3.10.13 (main, Sep 11 2023, 13:44:35) [GCC 11.2.0]
albumentations 1.4.1
imgaug 0.4.0
torchvision 0.17.1+rocm5.7
numpy 1.26.4
opencv-python-headless 4.9.0.80
scikit-image 0.22.0
scipy 1.12.0
pillow 10.2.0
kornia 0.7.2
augly 1.0.0
albumentations
1.4.0
torchvision
0.17.1+rocm5.7
kornia
0.7.2
augly
1.0.0
imgaug
0.4.0
HorizontalFlip 9843 ± 2135 2436 ± 29 1014 ± 3 3663 ± 18 4884 ± 51
VerticalFlip 9898 ± 18 2570 ± 37 1024 ± 4 5325 ± 13 8683 ± 5
Rotate 610 ± 4 153 ± 2 204 ± 1 626 ± 3 499 ± 5
Affine 1705 ± 67 159 ± 1 200 ± 1 - 663 ± 24
Equalize 1061 ± 14 337 ± 1 77 ± 1 - 845 ± 33
RandomCrop64 203197 ± 2105 15931 ± 27 837 ± 2 21858 ± 362 5681 ± 96
RandomResizedCrop 2998 ± 30 1160 ± 4 190 ± 1 - -
ShiftRGB 1400 ± 3 - 435 ± 1 - 1528 ± 6
Resize 2581 ± 3 1239 ± 1 197 ± 1 431 ± 1 1728 ± 1
RandomGamma 4556 ± 3 230 ± 1 205 ± 1 - 2282 ± 110
Grayscale 7234 ± 4 1539 ± 7 444 ± 3 2606 ± 2 918 ± 42
ColorJitter 452 ± 43 51 ± 1 50 ± 1 221 ± 1 -
RandomPerspective 465 ± 1 121 ± 1 115 ± 1 - 433 ± 16
GaussianBlur 2315 ± 9 106 ± 2 72 ± 1 161 ± 1 1213 ± 3
MedianBlur 3711 ± 2 - 2 ± 1 - 566 ± 3
MotionBlur 2763 ± 25 - 101 ± 4 - 508 ± 2
Posterize 4238 ± 51 2581 ± 20 284 ± 4 - 1893 ± 9
JpegCompression 208 ± 1 - - 692 ± 4 435 ± 1
GaussianNoise 64 ± 9 - - 67 ± 1 212 ± 16
Elastic 129 ± 1 3 ± 1 1 ± 1 - 128 ± 1

Contributing

To create a pull request to the repository, follow the documentation at CONTRIBUTING.md

https://github.com/albuemntations-team/albumentation/graphs/contributors

Community and Support

Comments

In some systems, in the multiple GPU regime, PyTorch may deadlock the DataLoader if OpenCV was compiled with OpenCL optimizations. Adding the following two lines before the library import may help. For more details pytorch/pytorch#1355

cv2.setNumThreads(0)
cv2.ocl.setUseOpenCL(False)

Citing

If you find this library useful for your research, please consider citing Albumentations: Fast and Flexible Image Augmentations:

@Article{info11020125,
    AUTHOR = {Buslaev, Alexander and Iglovikov, Vladimir I. and Khvedchenya, Eugene and Parinov, Alex and Druzhinin, Mikhail and Kalinin, Alexandr A.},
    TITLE = {Albumentations: Fast and Flexible Image Augmentations},
    JOURNAL = {Information},
    VOLUME = {11},
    YEAR = {2020},
    NUMBER = {2},
    ARTICLE-NUMBER = {125},
    URL = {https://www.mdpi.com/2078-2489/11/2/125},
    ISSN = {2078-2489},
    DOI = {10.3390/info11020125}
}

albumentations's People

Contributors

5n7 avatar akarsakov avatar albu avatar alimbekovkz avatar arquestro avatar arsenyinfo avatar ayasyrev avatar bfialkoff avatar bloodaxe avatar creafz avatar dipet avatar gavrin-s avatar i-aki-y avatar ilialarchenko avatar ilyaovodov avatar libfun avatar linashiryaeva avatar michaelmonashev avatar ocourtin avatar onurtore avatar qubvel avatar sergei3000 avatar strikerrus avatar sunqpark avatar ternaus avatar vfdev-5 avatar victor1cea avatar virajbagal avatar zakajd avatar zfturbo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

albumentations's Issues

Error while installing imaug due to Shapely package

🐛 Installation error

Collecting Shapely (from imgaug)
  Using cached https://files.pythonhosted.org/packages/a2/fb/7a7af9ef7a35d16fa23b127abee272cfc483ca89029b73e92e93cdf36e6b/Shapely-1.6.4.post2.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\ADMINI~1\AppData\Local\Temp\pip-install-kdsk2c_6\Shapely\setup.py", line 80, in <module>
        from shapely._buildcfg import geos_version_string, geos_version, \
      File "C:\Users\ADMINI~1\AppData\Local\Temp\pip-install-kdsk2c_6\Shapely\shapely\_buildcfg.py", line 200, in <module>
        lgeos = CDLL("geos_c.dll")
      File "C:\ProgramData\Anaconda3\envs\pytorch04_py36\lib\ctypes\__init__.py", line 348, in __init__
        self._handle = _dlopen(self._name, mode)
    OSError: [WinError 126] The specified module could not be found

Windows Server 2016
python 3.6.6
albumentations version 0.1.8

Steps to reproduce the behavior:
pip install imgaug
(or pip install albumentations )

The error is probably due to missing C compiler required for building the dll.
Workaround:

  1. install binaries from https://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely
  2. conda install shapely
    pip install imgaug

ref: https://gis.stackexchange.com/questions/62925/why-is-shapely-not-installing-correctly

Resize transform for masks

After applying the Resize transform to the binary mask, we get a non-binary mask:

In: np.unique(mask), mask.shape
Out: (array([  0, 255], dtype=uint8), (101, 101))

In: t_mask = Resize(256, 256)(image=img, mask=mask)['mask']
In: np.unique(t_mask), t_mask.shape
Out: (array([  0,   1,   2,   3,   4,   5,   6,   7,   9,  10,  11,  12,  13,
         14,  15,  17,  18,  20,  22,  23,  24,  25,  26,  27,  29,  32,
         33,  34,  35,  36,  37,  38,  40,  42,  43,  44,  48,  50,  52,
         53,  54,  55,  56,  57,  58,  60,  61,  62,  65,  66,  68,  69,
         72,  74,  75,  79,  81,  82,  83,  84,  86,  87,  88,  89,  90,
         91,  93,  94,  95,  96, 100, 103, 111, 112, 118, 119, 120, 121,
        126, 132, 133, 134, 135, 136, 137, 138, 141, 142, 143, 144, 147,
        151, 154, 155, 156, 158, 159, 162, 164, 165, 166, 167, 168, 169,
        173, 179, 180, 181, 182, 183, 186, 187, 190, 193, 194, 195, 196,
        197, 199, 201, 205, 207, 208, 212, 213, 215, 216, 217, 220, 221,
        222, 223, 224, 226, 227, 228, 229, 232, 233, 234, 235, 236, 237,
        238, 239, 240, 242, 243, 244, 245, 246, 250, 251, 252, 253, 254,
        255], dtype=uint8), (256, 256))

I think the code https://github.com/albu/albumentations/blob/master/albumentations/augmentations/transforms.py#L213-L214 needs to be changed:

def apply(self, img, interpolation, **params):
        return F.resize(img, height=self.height, width=self.width, interpolation=interpolation)

Can't iterate over transformation output

I'm using PyTorch to augment a dataset. I have downloaded the dataset and loaded it using the torchvision.datasets.ImageFolder 'n torch.utils.data.DataLoader functions. If I use a transformation from PyTorch the data is loaded, transformed and plotted without any errors, but if I apply some transformation from Albumentation I receive the following error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-6a0e45004b2c> in <module>
      4 for item in train_vectors:
      5     # Get epoch
----> 6     images, labels = iter(item['data']).next()
      7 
      8     # Plot images

TypeError: Traceback (most recent call last):
  File "/home/pc/.pyenv/versions/anaconda3-2018.12/envs/vida/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 106, in _worker_loop
    samples = collate_fn([dataset[i] for i in batch_indices])
  File "/home/pc/.pyenv/versions/anaconda3-2018.12/envs/vida/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 106, in <listcomp>
    samples = collate_fn([dataset[i] for i in batch_indices])
  File "/home/pc/.pyenv/versions/anaconda3-2018.12/envs/vida/lib/python3.6/site-packages/torchvision/datasets/folder.py", line 103, in __getitem__
    sample = self.transform(sample)
  File "/home/pc/.pyenv/versions/anaconda3-2018.12/envs/vida/lib/python3.6/site-packages/torchvision/transforms/transforms.py", line 49, in __call__
    img = t(img)
TypeError: __call__() takes 1 positional argument but 2 were given

or

tensor is not a torch image

The transformation list:

transform_train = [
    albumentations.augmentations.transforms.JpegCompression(),
    torchvision.transforms.Resize((height, width)),
    torchvision.transforms.ToTensor(),
    torchvision.transforms.Normalize(mean=(0,485, 0,456, 0,406), std=(0,229, 0,224, 0,225))
]

The loading:

torch.utils.data.DataLoader(
    dataset=torchvision.datasets.ImageFolder(
        root=path,
        transform=transform
    ),
    batch_size=batch,
    shuffle=shuffle,
    num_workers=workers        
)

The iteration:

for item in train_vectors:
    # Get epoch
    images, labels = iter(item['data']).next()

I'm using PyTorch 0.4.1, Albumentations 0.1.11 and Img Aug 0.2.7 (I'm running the notebooks inside a virtual environment created based on a virtual image installed using Pyenv).

I researched, but I couldn't figure out why I'm receiving this error, I have tried to iterate using enumerate, range and so on and nothing works, the complete code and references can be found here.

Do I need to iterate over the dataset of a different way or convert the data to another format... ?

About RandomSizedCrop implementation

When using RandomSizedCrop(), is it better to use padding if a suggested crop region is bigger than the original image size, rather than raise ValueError?
For example, the augmentation method used for achieving cityscapes good result uses padding.
https://github.com/PkuRainBow/OCNet/blob/8184d9d55ec474c7e22278256f1db8b3d7ebce88/dataset/cityscapes.py#L121

So I suggest changing this part;
https://github.com/albu/albumentations/blob/8626026910d6b0236bccd09af276ca9432af5d22/albumentations/augmentations/functional.py#L207-L221

to

def random_crop(img, crop_height, crop_width, h_start, w_start, pad_value=(0.0,)):
    height, width = img.shape[:2]
    if height < crop_height or width < crop_width:
        pad_h = max(crop_height - height, 0)
        pad_w = max(crop_width - width, 0)
        img = cv2.copyMakeBorder(img, 0, pad_h, 0,
                                 pad_w, cv2.BORDER_CONSTANT,
                                 value=pad_value)  # if gt label, pad_value should be ignore index.
    x1, y1, x2, y2 = get_random_crop_coords(height, width, crop_height, crop_width, h_start, w_start)
    img = img[y1:y2, x1:x2]
    return img

Errors when running example

Hello! I just found that example from https://albumentations.readthedocs.io/en/latest/examples.html sometime gives me TypeError and OpenCV related errors

Here is minimal example

import albumentations
from albumentations import (
    HorizontalFlip, IAAPerspective, ShiftScaleRotate, CLAHE, RandomRotate90,
    Transpose, ShiftScaleRotate, Blur, OpticalDistortion, GridDistortion, HueSaturationValue,
    IAAAdditiveGaussianNoise, GaussNoise, MotionBlur, MedianBlur, IAAPiecewiseAffine,
    IAASharpen, IAAEmboss, RandomContrast, RandomBrightness, Flip, OneOf, Compose
)
import numpy as np

def strong_aug(p=.5):
    return Compose([
        RandomRotate90(),
        Flip(),
        Transpose(),
        OneOf([
            IAAAdditiveGaussianNoise(),
            GaussNoise(),
        ], p=0.2),
        OneOf([
            MotionBlur(p=.2),
            MedianBlur(blur_limit=3, p=.1),
            Blur(blur_limit=3, p=.1),
        ], p=0.2),
        ShiftScaleRotate(shift_limit=0.0625, scale_limit=0.2, rotate_limit=45, p=.2),
        OneOf([
            OpticalDistortion(p=0.3),
            GridDistortion(p=.1),
            IAAPiecewiseAffine(p=0.3),
        ], p=0.2),
        OneOf([
            CLAHE(clip_limit=2),
            IAASharpen(),
            IAAEmboss(),
            RandomContrast(),
            RandomBrightness(),
        ], p=0.3),
        HueSaturationValue(p=0.3),
    ], p=p)

print(albumentations.__version__)

for i in range(1000):
    print(i)
    image = np.ones((300, 300))
    mask = np.ones((300, 300))
    whatever_data = "my name"
    augmentation = strong_aug(p=0.9)
    data = {"image": image, "mask": mask, "whatever_data": whatever_data, "additional": "hello"}
    augmented = augmentation(**data)
    image, mask, whatever_data, additional = augmented["image"], augmented["mask"], augmented["whatever_data"], augmented["additional"]

First full error message

Traceback (most recent call last):
  File "a.py", line 49, in <module>
    augmented = augmentation(**data)
  File "/home/daiver/.local/lib/python3.6/site-packages/albumentations/core/composition.py", line 17, in __call__
    data = t(**data)
  File "/home/daiver/.local/lib/python3.6/site-packages/albumentations/core/transforms_interface.py", line 22, in __call__
    return {key: self.targets.get(key, lambda x, **p: x)(arg, **params) for key, arg in kwargs.items()}
  File "/home/daiver/.local/lib/python3.6/site-packages/albumentations/core/transforms_interface.py", line 22, in <dictcomp>
    return {key: self.targets.get(key, lambda x, **p: x)(arg, **params) for key, arg in kwargs.items()}
  File "/home/daiver/.local/lib/python3.6/site-packages/albumentations/augmentations/transforms.py", line 414, in apply
    assert image.dtype == np.uint8 or self.hue_shift_limit < 1.
TypeError: '<' not supported between instances of 'tuple' and 'float'

Second full error message

OpenCV(3.4.1) Error: Unsupported format or combination of formats () in medianBlur, file /io/opencv/modules/imgproc/src/smooth.cpp, line 4597
Traceback (most recent call last):
  File "a.py", line 49, in <module>
    augmented = augmentation(**data)
  File "/home/daiver/.local/lib/python3.6/site-packages/albumentations/core/composition.py", line 17, in __call__
    data = t(**data)
  File "/home/daiver/.local/lib/python3.6/site-packages/albumentations/core/composition.py", line 33, in __call__
    data = t(**data)
  File "/home/daiver/.local/lib/python3.6/site-packages/albumentations/core/transforms_interface.py", line 22, in __call__
    return {key: self.targets.get(key, lambda x, **p: x)(arg, **params) for key, arg in kwargs.items()}
  File "/home/daiver/.local/lib/python3.6/site-packages/albumentations/core/transforms_interface.py", line 22, in <dictcomp>
    return {key: self.targets.get(key, lambda x, **p: x)(arg, **params) for key, arg in kwargs.items()}
  File "/home/daiver/.local/lib/python3.6/site-packages/albumentations/augmentations/transforms.py", line 551, in apply
    return F.median_blur(image, ksize)
  File "/home/daiver/.local/lib/python3.6/site-packages/albumentations/augmentations/functional.py", line 193, in median_blur
    return cv2.medianBlur(img, ksize)
cv2.error: OpenCV(3.4.1) /io/opencv/modules/imgproc/src/smooth.cpp:4597: error: (-210)  in function medianBlur

Third full error message

OpenCV(3.4.1) Error: Assertion failed (depth == 0 || depth == 2 || depth == 5) in cvtColor, file /io/opencv/modules/imgproc/src/color.cpp, line 11109
Traceback (most recent call last):
  File "a.py", line 49, in <module>
    augmented = augmentation(**data)
  File "/home/daiver/.local/lib/python3.6/site-packages/albumentations/core/composition.py", line 17, in __call__
    data = t(**data)
  File "/home/daiver/.local/lib/python3.6/site-packages/albumentations/core/composition.py", line 33, in __call__
    data = t(**data)
  File "/home/daiver/.local/lib/python3.6/site-packages/albumentations/core/transforms_interface.py", line 22, in __call__
    return {key: self.targets.get(key, lambda x, **p: x)(arg, **params) for key, arg in kwargs.items()}
  File "/home/daiver/.local/lib/python3.6/site-packages/albumentations/core/transforms_interface.py", line 22, in <dictcomp>
    return {key: self.targets.get(key, lambda x, **p: x)(arg, **params) for key, arg in kwargs.items()}
  File "/home/daiver/.local/lib/python3.6/site-packages/albumentations/augmentations/transforms.py", line 597, in apply
    return F.clahe(img, clip_limit, self.tile_grid_size)
  File "/home/daiver/.local/lib/python3.6/site-packages/albumentations/augmentations/functional.py", line 156, in clahe
    img = cv2.cvtColor(img, cv2.COLOR_RGB2LAB)
cv2.error: OpenCV(3.4.1) /io/opencv/modules/imgproc/src/color.cpp:11109: error: (-215) depth == 0 || depth == 2 || depth == 5 in function cvtColor

My Python version: 3.6.3
albumentations version: 0.0.4

PS Sorry for my poor English

OpenCV(3.4.2) /io/opencv/modules/imgproc/src/resize.cpp:4044: error: (-215:Assertion failed) !ssize.empty() in function 'resize'

python env:
Python 3.6.6 |Anaconda, Inc.| (default, Jun 28 2018, 17:14:51)
[GCC 7.2.0] on linux
Name Version Build Channel
albumentations 0.1.2

I flow notebooks/showcase.ipynb
my code:
import albumentations as A
import random
import cv2
random.seed(42)
image = cv2.imread('images/parrot.jpg')
tfms = [ A.Resize(256, 256),
A.RandomContrast(p=1),
A.RandomGamma(p=1),
A.RGBShift(),
A.CLAHE(p=1)]
aug = A.Compose(tfms, p=1)
r = augment_and_show(aug, image)

run output error:
~/anaconda3/envs/pytorch/lib/python3.6/site-packages/albumentations/core/transforms_interface.py in apply_to_mask(self, img, **params)
68
69 def apply_to_mask(self, img, **params):
---> 70 return self.apply(img, **{k: cv2.INTER_NEAREST if k == 'interpolation' else v for k, v in params.items()})
71
72

~/anaconda3/envs/pytorch/lib/python3.6/site-packages/albumentations/augmentations/transforms.py in apply(self, img, interpolation, **params)
238
239 def apply(self, img, interpolation=cv2.INTER_LINEAR, **params):
--> 240 return F.resize(img, height=self.height, width=self.width, interpolation=interpolation)
241
242 def apply_to_bbox(self, bbox, **params):

~/anaconda3/envs/pytorch/lib/python3.6/site-packages/albumentations/augmentations/functional.py in resize(img, height, width, interpolation)
81
82 def resize(img, height, width, interpolation=cv2.INTER_LINEAR):
---> 83 img = cv2.resize(img, (width, height), interpolation=interpolation)
84 return img
85

error: OpenCV(3.4.2) /io/opencv/modules/imgproc/src/resize.cpp:4044: error: (-215:Assertion failed) !ssize.empty() in function 'resize'

Git-less installation recommendation in readme

The current recommended way to install is

pip install -U git+https://github.com/albu/albumentations

This requires git, something not everyone might have installed (particularly on windows).

If you change it to

pip install -U https://github.com/albu/albumentations/archive/master.zip

The installation can be done without git.

"image" element in the augmentation is required

Currently, you take size of the images with such code:

params.update({'cols': kwargs['image'].shape[1], 'rows': kwargs['image'].shape[0]})

But that is not always correct. What if user wants to have a list of images to augment as this one: {"image1": image1, "image2": image2}

MedianBlur randomly fails with OpenCV error

This issue is a bit mysterious from my point of view, as it's kind of complicated to reproduce it a single try.

In [1]: from albumentations import MedianBlur
   ...: import numpy as np
   ...:
   ...: success, fail = 0, 0
   ...: for _ in range(100):
   ...:     img = np.random.rand(100, 100)
   ...:     try:
   ...:         img = MedianBlur()(image=img).get('image')
   ...:         success += 1
   ...:     except Exception:
   ...:         fail += 1
   ...: print(success, fail)
   ...:
OpenCV Error: Assertion failed (src.depth() == CV_8U && (cn == 1 || cn == 3 || cn == 4)) in medianBlur, file /Users/travis/build/skvark/opencv-python/opencv/modules/imgproc/src/smooth.cpp, line 3538
OpenCV Error: Unsupported format or combination of formats () in medianBlur, file /Users/travis/build/skvark/opencv-python/opencv/modules/imgproc/src/smooth.cpp, line 3529
OpenCV Error: Unsupported format or combination of formats () in medianBlur, file 

// some errors removed from the log

48 52

I've reproduced this stochastic issue on two different computers, both using opencv-python==3.3.0.10.

MotionBlur RuntimeWarning

There is RuntimeWarning when I use example for a loop.
code:

from albumentations import (
    HorizontalFlip, IAAPerspective, ShiftScaleRotate, CLAHE, RandomRotate90,
    Transpose, ShiftScaleRotate, Blur, OpticalDistortion, GridDistortion, HueSaturationValue,
    IAAAdditiveGaussianNoise, GaussNoise, MotionBlur, MedianBlur, IAAPiecewiseAffine,
    IAASharpen, IAAEmboss, RandomContrast, RandomBrightness, Flip, OneOf, Compose
)
import numpy as np

def strong_aug(p=0.5):
    return Compose([
        RandomRotate90(),
        Flip(),
        Transpose(),
        OneOf([
            IAAAdditiveGaussianNoise(),
            GaussNoise(),
        ], p=0.2),
        OneOf([
            MotionBlur(p=0.2),
            MedianBlur(blur_limit=3, p=0.1),
            Blur(blur_limit=3, p=0.1),
        ], p=0.2),
        ShiftScaleRotate(shift_limit=0.0625, scale_limit=0.2, rotate_limit=45, p=0.2),
        OneOf([
            OpticalDistortion(p=0.3),
            GridDistortion(p=0.1),
            IAAPiecewiseAffine(p=0.3),
        ], p=0.2),
        OneOf([
            CLAHE(clip_limit=2),
            IAASharpen(),
            IAAEmboss(),
            RandomContrast(),
            RandomBrightness(),
        ], p=0.3),
        HueSaturationValue(p=0.3),
    ], p=p)
import cv2
image = cv2.imread("test.jpg")
augmentation = strong_aug(p=0.9)
for i in range(10000):
    data = {"image": image}
    augmented = augmentation(**data)
    aug_img= augmented["image"]
    cv2.namedWindow("1", 2)
    cv2.imshow("1", aug_img.astype(np.uint8))
    cv2.waitKey(1)
cv2.destroyAllWindows()

The warning information below:
albumentations\augmentations\functional.py:257: RuntimeWarning: invalid value encountered in true_divide
return cv2.filter2D(img, -1, kernel / np.sum(kernel))

I found it in the function of motion_blur. That means something wrong in the function of MotionBlur?
Am I get bug in my code?
Could you please help me to solve the problem?

Does it support multiple channels?(>3 channels)

I stack 4 single-channel image to a 4-D image and transform it. It fails.

How to transform a image more than 3 channels?

Or is there some method to transform the 4 single-channel image with the same random transformation?

Allow list in `to_tuple()`

Reason: building composition of transformations from json file, but json only has list as sequences.
Example: it would be great to be able to do RandomScale(scale_limit=[0.5, 3], p=1)

Where: https://github.com/albu/albumentations/blob/3a294a3c993109aaabeca5b4901e90f03f1079ce/albumentations/core/transforms_interface.py#L8

How:

def to_tuple(param, low=None):
    if isinstance(param, (tuple, list)):
        return tuple(param)
    else:
        return (-param if low is None else low, param)
  • a one-liner in the tests, if we fancy so

Availability in Anaconda

Hello all,

thanks for working on such a nice project, I have tried imgaug, augmentor and keras, but wasn't satisfied since I am doing a lot of patch segmentation.

I would have wanted to know if it were possible to add albumentations in the repository of Anaconda, so that we could install it and keep track of the versions easily?

Thanks in advance,
Nicolas

Setting random seed

Hi,

I've noticed I receive different augmentation results between two identical runs, although my seeds are fixed. I set tensorflow (which shouldn't be related) and numpy random seeds.

Is there an additional seed needs to be set for albumentations?

Thanks,

Overflow encountered in long_scalars and other bbox problems

🐛 Bug

Bug appears when bboxes are used.

To Reproduce

def strong_aug(p=.5):
    return Compose([
        HorizontalFlip(p=0.001),
        # IAAPiecewiseAffine(p=1.0),
        OneOf([
            # OpticalDistortion(p=0.1),
            # GridDistortion(p=0.1),
            # IAAPerspective(p=1.0),
            # IAAAffine(p=1.0),
            IAAPiecewiseAffine(p=1.0),
        ], p=0.0),
    ],
        bbox_params={'format': 'pascal_voc',
                     'min_area': 1,
                     'min_visibility': 0.1,
                        'label_fields': ['labels']},
    p=p)

x0 = 0
x1 = 200
y0 = 10
y1 = 200
bb = np.array([[int(x0), int(y0), int(x1), int(y1)]])
augm = strong_aug(p=1.0)(image=img, bboxes=bb, labels=['labels'])
img = augm['image']
bboxes = np.array(augm['bboxes'])

Error message:

\site-packages\albumentations\augmentations\bbox_utils.py:42: RuntimeWarning: overflow encountered in long_scalars
area = (x_max - x_min) * (y_max - y_min)

Returned boxes are empty.

It works fine in this case:

return Compose([
        HorizontalFlip(p=0.001),
        IAAPiecewiseAffine(p=1.0),
        
    ],
        bbox_params={'format': 'pascal_voc',
                     'min_area': 1,
                     'min_visibility': 0.1,
                        'label_fields': ['labels']},
    p=p)

It returns empty boxes in this case (without warning):

return Compose([
        HorizontalFlip(p=0.001),
        IAAPiecewiseAffine(p=1.0),
        OneOf([
            # OpticalDistortion(p=0.1),
            # GridDistortion(p=0.1),
            # IAAPerspective(p=1.0),
            IAAAffine(p=1.0),
            # IAAPiecewiseAffine(p=1.0),
        ], p=0.0),
    ],
        bbox_params={'format': 'pascal_voc',
                     'min_area': 1,
                     'min_visibility': 0.1,
                        'label_fields': ['labels']},
    p=p)

It returns incorrect boxes which looks like ([['0.0' '0.173015873015873' '0.9742857142857143' '0.9285714285714286' 'labels']]):

return Compose([
        # HorizontalFlip(p=0.001),
        # IAAPiecewiseAffine(p=1.0),
        OneOf([
            OpticalDistortion(p=0.1),
            GridDistortion(p=0.1),
            # IAAPerspective(p=1.0),
            # IAAAffine(p=1.0),
            # IAAPiecewiseAffine(p=1.0),
        ], p=0.0),
    ],
        bbox_params={'format': 'pascal_voc',
                     'min_area': 1,
                     'min_visibility': 0.1,
                        'label_fields': ['labels']},
    p=p)

Environment

  • Albumentations version: 0.1.8
  • Python version: 3.5
  • OS: Windows
  • How you installed albumentations (conda, pip, source): pip

pip install albumentations is failed with error code 1

🐛 Bug

When I install the albumentations on windows7 for keras, the bug is jump on face.

Expected behavior

Environment

  • Albumentations version (e.g., 0.1.10):
  • Python version (e.g., 3.5):
  • OS (e.g., windows7):
  • How you installed albumentations (conda, pip, source):

Additional context

(keras) $ pip install imgaug
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting imgaug
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/af/fc/c56a7da8c23122b7c5325b941850013880a7a93c21dc95e2b1ecd4750108/imgaug-0.2.7-py3-
none-any.whl (644kB)
100% |████████████████████████████████| 645kB 2.9MB/s
Requirement already satisfied: Pillow in d:\software\anaconda3\envs\keras\lib\site-packages (from imgaug) (5.4.1)
Requirement already satisfied: imageio in d:\software\anaconda3\envs\keras\lib\site-packages (from imgaug) (2.4.1)
Requirement already satisfied: numpy>=1.7.0 in d:\software\anaconda3\envs\keras\lib\site-packages (from imgaug) (1.15.4)
Requirement already satisfied: scikit-image>=0.11.0 in d:\software\anaconda3\envs\keras\lib\site-packages (from imgaug) (0.14.1)
Collecting Shapely (from imgaug)
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a2/fb/7a7af9ef7a35d16fa23b127abee272cfc483ca89029b73e92e93cdf36e6b/Shapely-1.6.4.pos
t2.tar.gz (225kB)
100% |████████████████████████████████| 235kB 6.4MB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\WangZhao\AppData\Local\Temp\pip-install-h64vi3v5\Shapely\setup.py", line 80, in
from shapely.buildcfg import geos_version_string, geos_version,
File "C:\Users\WangZhao\AppData\Local\Temp\pip-install-h64vi3v5\Shapely\shapely_buildcfg.py", line 200, in
lgeos = CDLL("geos_c.dll")
File "D:\Software\Anaconda3\envs\keras\lib\ctypes_init
.py", line 348, in init
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] 找不到指定的模块。

----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in C:\Users\WangZhao\AppData\Local\Temp\pip-install-h64vi3v5\Shapely\

Problems with gray images and ToGray function

Can't figure out how to use albumentations for gray images, due to error in functions like RandomContrast which try to cast image to gray => raise an error

And also ToGray is impossible to use in Compose:

im = np.random.randint(0,255,(224,224,3))
aug = Compose([ToGray(p=1.)],p=1.)
augmented = ToGray()(image = im) # works
augmented2 = aug(image=im) # fails with opencv error:

Unsupported depth of input image:
>     'VDepth::contains(depth)'
> where
>     'depth' is 4 (CV_32S)

it looks like the problem is due to cast from int8 to float32 before calling this transform

Add support of None values for masks etc.

Currently passing mask = None as argument causes an error.
It results in sofistication code that must be common for train and test data. Somthing like this:

if mask is not None: #validation pipeline
   augm = MyAugmentation(image = img, mask = mask)
   augm_img, augm_mask = augm['image'], augm['mask']
else: #production pipeline
   augm = MyAugmentation(image = img)
   augm_img = augm['image']

It can be simplified if augmentations will accept None parameters (and return None result for them):

augm = MyAugmentation(image = img, mask = mask) # both validation and production pipelines
augm_img, augm_mask = augm['image'], augm['mask']

Improve custom targeting

  • Get rows and cols as "dependent targets" not implicitly "image" as now.
  • Optionally pass targets to Compose {"img": type_img, "mask": type_mask}

Incompatible with numpy==1.16.0

🐛 Bug

When installed with pip, incompatible versions of numpy and skimage may be installed.

To Reproduce

Steps to reproduce the behavior:

  1. pip install -U albumentations
  2. python
  3. import albumentations
root@11e08e49dff0:/app# pip install -U albumentations
Requirement already up-to-date: albumentations in /usr/local/lib/python3.6/dist-packages (0.1.10)
Requirement already satisfied, skipping upgrade: numpy>=1.11.1 in /usr/local/lib/python3.6/dist-packages (from albumentations) (1.16.0)
Requirement already satisfied, skipping upgrade: scipy in /usr/local/lib/python3.6/dist-packages (from albumentations) (1.2.0)
Requirement already satisfied, skipping upgrade: opencv-python in /usr/local/lib/python3.6/dist-packages (from albumentations) (4.0.0.21)
Requirement already satisfied, skipping upgrade: imgaug>=0.2.5 in /usr/local/lib/python3.6/dist-packages (from albumentations) (0.2.7)
Requirement already satisfied, skipping upgrade: scikit-image>=0.11.0 in /usr/local/lib/python3.6/dist-packages (from imgaug>=0.2.5->albumentations) (0.14.1)
Requirement already satisfied, skipping upgrade: six in /usr/local/lib/python3.6/dist-packages (from imgaug>=0.2.5->albumentations) (1.12.0)
Requirement already satisfied, skipping upgrade: matplotlib in /usr/local/lib/python3.6/dist-packages (from imgaug>=0.2.5->albumentations) (3.0.2)
Requirement already satisfied, skipping upgrade: Pillow in /usr/local/lib/python3.6/dist-packages (from imgaug>=0.2.5->albumentations) (5.4.1)
Requirement already satisfied, skipping upgrade: imageio in /usr/local/lib/python3.6/dist-packages (from imgaug>=0.2.5->albumentations) (2.4.1)
Requirement already satisfied, skipping upgrade: Shapely in /usr/local/lib/python3.6/dist-packages (from imgaug>=0.2.5->albumentations) (1.6.4.post2)
Requirement already satisfied, skipping upgrade: networkx>=1.8 in /usr/local/lib/python3.6/dist-packages (from scikit-image>=0.11.0->imgaug>=0.2.5->albumentations) (2.2)
Requirement already satisfied, skipping upgrade: PyWavelets>=0.4.0 in /usr/local/lib/python3.6/dist-packages (from scikit-image>=0.11.0->imgaug>=0.2.5->albumentations) (1.0.1)
Requirement already satisfied, skipping upgrade: dask[array]>=0.9.0 in /usr/local/lib/python3.6/dist-packages (from scikit-image>=0.11.0->imgaug>=0.2.5->albumentations) (1.0.0)
Requirement already satisfied, skipping upgrade: cloudpickle>=0.2.1 in /usr/local/lib/python3.6/dist-packages (from scikit-image>=0.11.0->imgaug>=0.2.5->albumentations) (0.6.1)
Requirement already satisfied, skipping upgrade: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib->imgaug>=0.2.5->albumentations) (2.3.1)
Requirement already satisfied, skipping upgrade: kiwisolver>=1.0.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib->imgaug>=0.2.5->albumentations) (1.0.1)
Requirement already satisfied, skipping upgrade: python-dateutil>=2.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib->imgaug>=0.2.5->albumentations) (2.7.5)
Requirement already satisfied, skipping upgrade: cycler>=0.10 in /usr/local/lib/python3.6/dist-packages (from matplotlib->imgaug>=0.2.5->albumentations) (0.10.0)
Requirement already satisfied, skipping upgrade: decorator>=4.3.0 in /usr/local/lib/python3.6/dist-packages (from networkx>=1.8->scikit-image>=0.11.0->imgaug>=0.2.5->albumentations) (4.3.0)
Requirement already satisfied, skipping upgrade: toolz>=0.7.3; extra == "array" in /usr/local/lib/python3.6/dist-packages (from dask[array]>=0.9.0->scikit-image>=0.11.0->imgaug>=0.2.5->albumentations) (0.9.0)
Requirement already satisfied, skipping upgrade: setuptools in /usr/local/lib/python3.6/dist-packages (from kiwisolver>=1.0.1->matplotlib->imgaug>=0.2.5->albumentations) (40.6.3)
root@11e08e49dff0:/app# python
Python 3.6.8 (default, Dec 24 2018, 19:24:27) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import albumentations
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/albumentations/__init__.py", line 5, in <module>
    from .core.composition import *
  File "/usr/local/lib/python3.6/dist-packages/albumentations/core/composition.py", line 11, in <module>
    from albumentations.imgaug.transforms import DualIAATransform
  File "/usr/local/lib/python3.6/dist-packages/albumentations/imgaug/transforms.py", line 1, in <module>
    import imgaug as ia
  File "/usr/local/lib/python3.6/dist-packages/imgaug/__init__.py", line 2, in <module>
    from imgaug.imgaug import *
  File "/usr/local/lib/python3.6/dist-packages/imgaug/imgaug.py", line 22, in <module>
    import skimage.draw
  File "/usr/local/lib/python3.6/dist-packages/skimage/__init__.py", line 167, in <module>
    from .util.dtype import (img_as_float32,
  File "/usr/local/lib/python3.6/dist-packages/skimage/util/__init__.py", line 8, in <module>
    from .arraycrop import crop
  File "/usr/local/lib/python3.6/dist-packages/skimage/util/arraycrop.py", line 8, in <module>
    from numpy.lib.arraypad import _validate_lengths
ImportError: cannot import name '_validate_lengths'

Expected behavior

Working installation of the library

Environment

  • Albumentations version: (e.g., 0.1.8)
  • Python version: 3.6.8
  • OS (e.g., Linux): Ubuntu 16.04
  • How you installed albumentations: pip
  • Any other relevant information: docker

Additional context

pip install -U numpy==1.15.4 fixes the problem

exception in GridDistortion

version: albumentations-0.1.7
call:

    distortion = albumentations.GridDistortion(num_steps=32, distort_limit=0.7, border_mode=cv2.BORDER_CONSTANT, p=0.3)
    sample = distortion(image=sample)['image']

image is 256x256x3

Thrown exception:

File "C:\Users\owner\AppData\Local\conda\conda\envs\allegro_env\lib\site-packages\albumentations\augmentations\functional.py", line 412, in grid_distortion
cur = prev + x_step * xsteps[idx]
IndexError: list index out of range

mask_to_tensor : function explanation

Hi,
Very interesting and thorough package for playing with images.
I am curious to know what is the purpose of the function mask_to_tensor in .torch.functional? More specifically, what does it mean to create a mask, like:

for c in range(mask.shape[2]):
    long_mask[mask[..., c] > 0] = c

and where/why would I use such a weird looking mask?

Please bear in mind that I am not asking how this code work but that why would someone ever need to create such a mask? Application of the mask. Few examples would be enlightening, thanks!

https://github.com/albu/albumentations/blob/master/albumentations/torch/functional.py#L15

Target shape squeeze

Augmentation squeeze target shape:

import numpy as np
import albumentations

from albumentations import Flip, Compose

sample = {
    'image': np.ones((224, 224, 1)),
    'mask': np.ones((224, 224, 1)),
}

aug = Compose([Flip(p=0.5)], p=1.)

sample_1 = aug(**sample)
sample_2 = aug(**sample)

print(sample_1['mask'].shape)   # (224, 224, 1) - augmentation not applied
print(sample_2['mask'].shape)   # (224, 224)

Is it possible to fix this behavior?
Obvious solution - squeeze before aug and expand after. But maybe you have another ideas (smth like ShapeGuard)?

Unobvious Compose behavior when processing bboxes

Hi.
I've found some unobvious behavior when using bbox-aware Compose along with ToTensor augmentation for PyTorch. The problem is that boxes_postprocessing() method assumes image has numpy format (HxWxC), but it is not if when ToTensor was applied.

As a workaround, bbox modifying augs should be separrated from ToTensor(). For example

full_aug = Compose([VerticalFlip(p=1), ToTensor()], bbox_params=bbox_conf)

should be rewritten as

 bbox_modifying_aug = alb.Compose([alb.VerticalFlip(p=1)], bbox_params=box_conf)
 full_aug = alb.Compose([bbox_modifying_aug, ToTensor()])

Complete snipped reproducing the problem and demonstrating workaround in action is available here.

As far as I know, this thing is not mentioned anywhere in docs, but it should be if it is intentional behavior.
I think it should not be left like that and should be changed.

Multiprocessing isn't working

I have a piece of code which I am trying to use to augment some images. If I try to augment my images sequentially, everything works perfectly but as soon as I try to use multiprocessing, everything breaks.
Here is the code I am using to do multiprocessing:

def strong_aug(p=.5):
    return Compose([
        RandomRotate90(),
        Flip(),
        Transpose(),
        OneOf([IAAAdditiveGaussianNoise(), GaussNoise(),], p=0.2),
        OneOf([MotionBlur(p=.2), MedianBlur(blur_limit=3, p=.1), Blur(blur_limit=3, p=.1),], p=0.2),
        ShiftScaleRotate(shift_limit=0.0625, scale_limit=0.2, rotate_limit=45, p=.2),
        OneOf([OpticalDistortion(p=0.3), GridDistortion(p=.1), IAAPiecewiseAffine(p=0.3),], p=0.2),
        OneOf([CLAHE(clip_limit=2), IAASharpen(), IAAEmboss(), RandomBrightness(),], p=0.3),
        HueSaturationValue(p=0.3),], 
        p=p)

aug = strong_aug(p=1)

class ImageProcessor:
    def __init__(self,aug):
        self._aug = aug

    def __call__(self,filename):
        name = "aug_" + filename
        img = cv2.imread(str(train_dir / filename))
        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
        image = aug(image=img)['image']
        imsave("augmented_train_images/" + name, image)

final_images = .... # list containing all the filenames corresponding to the images
proc=ImageProcessor(aug)
pool=multiprocessing.Pool()
pool.map(proc,final_images) 

Here is the error log:

<ipython-input-22-eab8d2bb2f8e> in <module>()
      7     proc=ImageProcessor(aug)
      8     pool=multiprocessing.Pool()
----> 9     pool.map(proc,final_images)
     10     print("Augmentation done for label: ", k)

~/miniconda2/envs/py36/lib/python3.6/multiprocessing/pool.py in map(self, func, iterable, chunksize)
    264         in a list that is returned.
    265         '''
--> 266         return self._map_async(func, iterable, mapstar, chunksize).get()
    267 
    268     def starmap(self, func, iterable, chunksize=None):

~/miniconda2/envs/py36/lib/python3.6/multiprocessing/pool.py in get(self, timeout)
    642             return self._value
    643         else:
--> 644             raise self._value
    645 
    646     def _set(self, i, obj):

~/miniconda2/envs/py36/lib/python3.6/multiprocessing/pool.py in _handle_tasks(taskqueue, put, outqueue, pool, cache)
    422                         break
    423                     try:
--> 424                         put(task)
    425                     except Exception as e:
    426                         job, idx = task[:2]

~/miniconda2/envs/py36/lib/python3.6/multiprocessing/connection.py in send(self, obj)
    204         self._check_closed()
    205         self._check_writable()
--> 206         self._send_bytes(_ForkingPickler.dumps(obj))
    207 
    208     def recv_bytes(self, maxlength=None):

~/miniconda2/envs/py36/lib/python3.6/multiprocessing/reduction.py in dumps(cls, obj, protocol)
     49     def dumps(cls, obj, protocol=None):
     50         buf = io.BytesIO()
---> 51         cls(buf, protocol).dump(obj)
     52         return buf.getbuffer()
     53 

AttributeError: Can't pickle local object 'Sharpen.<locals>.create_matrices'

DualIAATransform doesn't implement separate mask transform

I'd like to use IAAAffine and IAAPerspective to augment images for segmentation. I have the label masks one-hot encoded as 8-bit values, and the missing mask-only transform from DualIAATransform interpolates the values in the the label masks, making them invalid (i.e. more than one bit set for a given pixel)

How to qucikly generate image in one batch?

📚 Documentation

Thanks for you work, I have other question, how to use your Albumentations to make one image generate more different photos from each other in one batch?

jpeg compression changes dtype

Current implementation of Jpeg compression works only with uint8 data, so it can break some pipelines where data is casted to [0, 1] floats from the very beginning.

In [29]: from albumentations.augmentations import functional as f_aug

In [30]: img = np.random.rand(100, 100).astype('float32')

In [31]: f_aug.jpeg_compression(img, 95).dtype
Out[31]: dtype('uint8')

Please let me know if you'd like to get PR on this issue.

P.S. BTW, it may be a good idea to check for input and output dtype equality to make the debugging of similar issues easier.

Randomly zooming out possible?

Hi, if I would like to randomly zoom out my image like with iaa.Scale((0.5, 1.0)), how would I do this with albumentations? I could pad the image first, but the amount of padding would not be random.

image

Could not broadcast on Crop Images

Hello, thank you very much for your work before anything else. I'm having problems applying random crops and center crops when going from a given shape to a smaller one obviously. Also happens with Resize(). The output is as follows:

seleccion_001
Outputs:

seleccion_002

Where original sample shape is (64,64,3)

How to approach TTA with albumentations?

Hi.
Is there a recommended approach to do test time augmentation? I would like to pick several random augmentations and apply them to test and validation sets for later stacking. I'm not sure how to proceed. How do I make sure that one set of augmentations is applied to the whole test set and then to validation set and not random augmentations to every image?
Thanks.

cannot import name 'Resize'

pip install --force-reinstall albumentations, but still can't import resize. As discussed at sbsj, open a ticket. Could you please check?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.