Skip to content

Setting 0 and 1 to p argument of RandomAutocontrast() gets the same results #8915

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

Open
hyperkai opened this issue Feb 18, 2025 · 1 comment

Comments

@hyperkai
Copy link

🐛 Describe the bug

Setting 0 and 1 to p argument of RandomAutocontrast() gets the same results as shown below:

from torchvision.datasets import OxfordIIITPet
from torchvision.transforms.v2 import RandomAutocontrast

origin_data = OxfordIIITPet(
    root="data",
    transform=None
)

p0_data = OxfordIIITPet(
    root="data",
    transform=RandomAutocontrast(p=0)
)

p1_data = OxfordIIITPet(
    root="data",
    transform=RandomAutocontrast(p=1)
)

import matplotlib.pyplot as plt

def show_images1(data, main_title=None):
    plt.figure(figsize=[10, 5])
    plt.suptitle(t=main_title, y=0.8, fontsize=14)
    for i, (im, _) in zip(range(1, 6), data):
        plt.subplot(1, 5, i)
        plt.imshow(X=im)
        plt.xticks(ticks=[])
        plt.yticks(ticks=[])
    plt.tight_layout()
    plt.show()

show_images1(data=origin_data, main_title="origin_data")
show_images1(data=p0_data, main_title="p0_data")
show_images1(data=p1_data, main_title="p1_data")

Image

Image

Image

I expected the results of ColorJitter() as shown below:

from torchvision.datasets import OxfordIIITPet
from torchvision.transforms.v2 import ColorJitter

origin_data = OxfordIIITPet(
    root="data",
    transform=None
)

contrast06_06_data = OxfordIIITPet(
    root="data",
    transform=ColorJitter(contrast=[0.6, 0.6])
)

contrast4_4_data = OxfordIIITPet(
    root="data",
    transform=ColorJitter(contrast=[4, 4])
)

import matplotlib.pyplot as plt

def show_images1(data, main_title=None):
    plt.figure(figsize=[10, 5])
    plt.suptitle(t=main_title, y=0.8, fontsize=14)
    for i, (im, _) in zip(range(1, 6), data):
        plt.subplot(1, 5, i)
        plt.imshow(X=im)
        plt.xticks(ticks=[])
        plt.yticks(ticks=[])
    plt.tight_layout()
    plt.show()

show_images1(data=origin_data, main_title="origin_data")
show_images1(data=contrast06_06_data, main_title="contrast06_06_data")
show_images1(data=contrast4_4_data, main_title="contrast4_4_data")

Image

Image

Image

Versions

import torchvision

torchvision.__version__ # '0.20.1'
@NicolasHug
Copy link
Member

Thanks for the report - can you try to produce a more minimal example that doesn't depend on OxfordIIITPet? Also, can you try to assert that images are effectively the same at the pixel level? It's possible that the effect of AutoContrast is there but just not immediately visible at the naked eye.

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

No branches or pull requests

2 participants