Skip to content

ImageFolder __getitem__ method returning incorrect horizontal_flip transformation parameter #1

@patrik-bartak

Description

@patrik-bartak

Current Behavior:

The following line performs a horizontal flip on the augmented image with a 50% probability, but due to self.hor_flip(aug_sample) not being deterministic, the augmented image does not correspond to the hor_flip parameter:

aug_sample = self.hor_flip(aug_sample)

Expected Behavior:

The hor_flip parameter should be True iff the augmented image is a flipped version of the sample (possibly with some crop).

This can be done by setting self.hor_flip = tvf.hflip

Steps To Reproduce:

The following code was used to visualize the tensors and verify that sometimes the parameter does not correspond to the augmented image:

import matplotlib.pyplot as plt
import numpy as np

def display_tensors(tensor1, tensor2, hor_flip):
    fig, axs = plt.subplots(1, 2, figsize=(10, 10))

    for i, tensor in enumerate([tensor1, tensor2]):
        # Convert the tensor to numpy array
        image_np = tensor.numpy()

        # Scale the values to [0, 1] range
        image_np = (image_np - image_np.min()) / (image_np.max() - image_np.min())

        # Transpose the numpy array if necessary
        if image_np.shape[0] == 3:  # Check if the image tensor is in the format (channels, height, width)
            image_np = np.transpose(image_np, (1, 2, 0))  # Transpose to (height, width, channels)

        # Display the image
        axs[i].imshow(image_np)
        axs[i].set_title(f"Flipped? {hor_flip}")

    plt.show(block=True)

Anything else:

I am using your CGC paper for reference: https://arxiv.org/pdf/2110.00527.pdf

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions