Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ColorJitter #202

Open
wants to merge 4 commits into
base: v1.0.0
Choose a base branch
from
Open

Add ColorJitter #202

wants to merge 4 commits into from

Conversation

bordesf
Copy link

@bordesf bordesf commented Mar 23, 2022

Hi everyone, I just wanted to share my implementation of ColorJitter which is very close to the one used in torchvision.
As ColorJitter in torchvision.transforms, you can specify a float, or a (min,max) to sample the different ratio for brightness/contrast/saturation and hue.

I did simple tests to visualize the transformations between the Pytorch and FFCV version:
ColorJitter (only hue) from torchvision.transforms:
color_jitter_pytorch4
ColorJitter (only hue) from this pull request (FFCV):
color_jitter_fcv4

And ColorJitter with different values for brightness/contrast/saturation and hue:
FFCV ColorJitter (2)

The code used for brightness/contrast/saturation is identical to the ones used in torchvision.transforms, however concerning hue, the code used is an adaptation from
https://sanje2v.wordpress.com/2021/01/11/accelerating-data-transforms/
https://stackoverflow.com/questions/8507885

@lengstrom
Copy link
Contributor

ColorJitter from PyTorch includes support for both grayscale and RGB images, is it possible you could add this feature before we merge it in?

@bordesf
Copy link
Author

bordesf commented Apr 12, 2022

I would love to ! However it's not obvious how to check the number of channel in the compiled function. I tried several things but still got the following errors when trying to check the shape: No implementation of function Function(<function runtime_broadcast_assert_shapes at 0x7f6657fbc670>). I am not super familiar with Numba but ideally, we should compiled one function for RGB and another one for Grayscale, but we will not have the shape until the call to the compiled function.
I looked at the other transforms in this repo, none of them has used a if condition over the shape.
The simplest thing will be to add an argument in the init of the class where the user could switch between RGB and Grayscale mode but, it's not a great solution...
Maybe the best case will be to have access to the decoder attributes inside the transformations. But, again, not sure if this is good idea.

@netw0rkf10w
Copy link

Hi @bordesf. Could you tell how your PR is compared to this one: #162?

@andrewilyas andrewilyas changed the base branch from main to v1.0.0 February 28, 2023 06:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants