Skip to content

Why photometric augmentations are also applied for uncorrupted left and right image? #3

@tholmb

Description

@tholmb

Thanks for the great work! I was trying to understand the RandomColorJitter function better and noticed while debugging self.jitter parameters it calculates individual color jitters also for uncorrupted images. This happens because RandomColorJitter is applied for all samples with element type COLOR_IMAGE. Is this wanted behaviour? Uncorrupted images are used at least for calculating smoothness loss and in my opinion they should be calculated for completely original images without any photometric transformations. I could be wrong though.

I tested this effect with following changes to RandomColorJitter

class RandomColorJitter(object):
    """Randomly adjust image hue, saturation, gamma, etc."""

    def __init__(self, generator):
        self.generator = generator
        brightness_scale = 0.5
        contrast_scale = 0.5
        saturation_scale = 0.5
        hue_scale = 0.05
        self.jitter = torchvision.transforms.ColorJitter(brightness_scale, contrast_scale, saturation_scale, hue_scale)

    def __call__(self, sample):
        if self.generator is not None:# and self.generator.random() > 0.5:
            for key, element in sample.elements.items():
                if element.type == ElementType.COLOR_IMAGE:
                    print(key)
                    gamma = random.uniform(0.8, 1.2)
                    print(gamma)
                    print(torchvision.transforms.ColorJitter.get_params(self.jitter.brightness, self.jitter.contrast, self.jitter.saturation, self.jitter.hue))
                    with warnings.catch_warnings():
                        warnings.simplefilter("ignore", category=DeprecationWarning)
                        new_data = np.array(self.jitter(
                            torchvision.transforms.functional.adjust_gamma(Image.fromarray(sample.get_data(key)),
                                                                           gamma=gamma)))
                    sample.set_data(key, new_data)
        return sample

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions