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

YOCO generates a single image when we have single image #3

Closed
khawar-islam opened this issue Nov 7, 2022 · 4 comments
Closed

YOCO generates a single image when we have single image #3

khawar-islam opened this issue Nov 7, 2022 · 4 comments

Comments

@khawar-islam
Copy link

khawar-islam commented Nov 7, 2022

Hi @JunlinHan

I have a dataset contains single image and I am simply applying your YOCO technique to visualize image generated by YOCO. I just get a single output sometimes the output is same image as input and sometimes flip+cut. Is that correct?

Code

import torch
from torchvision.utils import save_image
import torchvision.transforms as transforms
from torchvision import datasets
from torchvision.transforms import ToTensor
from torch.utils.data import DataLoader

training_data = datasets.ImageFolder(root="/media/cvpr/CM_22/dataset/train", transform=ToTensor())
train_loader = DataLoader(training_data, batch_size=64, shuffle=True)


def YOCO(images, aug, h, w):
    images = torch.cat((aug(images[:, :, :, 0:int(w / 2)]), aug(images[:, :, :, int(w / 2):w])), dim=3) if \
        torch.rand(1) > 0.5 else torch.cat((aug(images[:, :, 0:int(h / 2), :]), aug(images[:, :, int(h / 2):h, :])),
                                           dim=2)
    return images


for i, (images, target) in enumerate(train_loader):
    aug = torch.nn.Sequential(
        transforms.RandomHorizontalFlip(), )
    _, _, h, w = images.shape
    # perform augmentations with YOCO
    images = YOCO(images, aug, h, w)
    save_image(images, 'img' + str(i) + '.png')

Input image:
aeroplane_+_tiger_google_0017

Output Image
img0

@JunlinHan
Copy link
Owner

Hello Khawar,
Thanks for your questions! Yes, it is correct. It depends on the probability of applying augmentation operations. The demo code you are using is horizontal flip, which is applied with a probabily of 0.5 by default. You may modify the following part, an example (p=1) is attached below:

    aug = torch.nn.Sequential(
        transforms.RandomHorizontalFlip(p=1), )

@khawar-islam
Copy link
Author

@JunlinHan thank you for your answer. If i apply two techniques at the same time, it must generate two augmented images.
Am i right?

for i, (images, target) in enumerate(train_loader):
    aug = torch.nn.Sequential(
        transforms.RandomHorizontalFlip(p=1),
        transforms.RandomVerticalFlip(p=1))
    _, _, h, w = images.shape
    # perform augmentations with YOCO
    images = YOCO(images, aug, h, w)
    save_image(images, 'img' + str(i) + '.png')

@JunlinHan
Copy link
Owner

JunlinHan commented Nov 9, 2022

Hello Khawar,
No, this is a sequence operation, so you will get one augmented image only (but this image has been augmented with 2 operations).

@khawar-islam
Copy link
Author

@JunlinHan thank you

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