libffcv / ffcv

FFCV: Fast Forward Computer Vision (and other ML workloads!)
https://ffcv.io
Apache License 2.0
2.82k stars 178 forks source link

Add color augmentations (RandomBrightness, RandomContrast, RandomSaturation) #155

Closed Jasonlee1995 closed 2 years ago

Jasonlee1995 commented 2 years ago

Random color augmentations similar to torchvision.transforms.ColorJitter.

Lack of my ability, augmentations don't contain adjusting hue and are divided into 3 parts with RandomBrightness, RandomContrast, RandomSaturation.

To avoid errors, I changed some of the methods which occur error on my env. (changing torch unsqueeze, expand operations to numpy expand_dims, repeat operations occurs error)

Reference from torchvision tensor operation

# Pipeline Examples
pipelines = {'image': [RandomResizedCropRGBImageDecoder((224, 224)),
                       RandomBrightness(0.2), RandomContrast(0.2), RandomSaturation(0.2),
                       RandomHorizontalFlip(), Cutout(16), 
                       ToTensor(), ToTorchImage(), ToDevice(0), 
                       NormalizeImage(IMAGENET_MEAN, IMAGENET_STD, np.float16)],

             'label': [IntDecoder(), ToTensor(), ToDevice(0)]}
andrewilyas commented 2 years ago

Hi, thanks for the PR! I took a brief look, and I think that some of these could be done in-place instead of allocating new memory (e.g., brightness?)

Jasonlee1995 commented 2 years ago

@andrewilyas I don't have deep insights on FFCV but I need color augmentations for SSL, so I just made these style of codes reference from ffcv flip operation and ffcv official doc and do PR. (if ffcv can do in in-place, I don't understand why flip operation is written in out-place?)

If there are no problems to use in-place, I'll try and test on my env and re-PR!

GuillaumeLeclerc commented 2 years ago

Thanks for working on that @Jasonlee1995