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

Ability to use pre-made augmentations #1525

Open
vedranf opened this issue Apr 22, 2024 · 3 comments
Open

Ability to use pre-made augmentations #1525

vedranf opened this issue Apr 22, 2024 · 3 comments

Comments

@vedranf
Copy link

vedranf commented Apr 22, 2024

Hi, is there ability to use already made augmentations? I have a use-case where the process of creating augmentations is rather complex and time consuming so I pre-created them. It would be ideal if there is a workflow where augmented files could just be read from disk and worked with as is (or with some simple additional transformations applied). Is something like this already possible, perhaps with some clever directory structure?

Thanks,
Vedran

@guarin
Copy link
Contributor

guarin commented Apr 23, 2024

Hi! We don't have built-in support for this use-case. But you can create your own dataset to load the data in the correct format. It should return the following: tuple[list[augmentations1, augmentations2]]. Where augmentations1 and augmentations2 are tensors with a batch of images each.

Maybe store your images in a directory structure like:

root_dir/
    augmentations1/
    augmentations2/
   ...

Then you should be able to load them quite easily in your custom dataset. Let me know if something is unclear :)

@vedranf
Copy link
Author

vedranf commented Apr 24, 2024

Thanks for your response! Initially I thought of somehow subclassing MultiViewCollate, but I saw it's deprecated.
While I can store augmentations that way, if still using LightlyDataset, it would interpret augmentations as weak labels, no?
What do you think of following (hackish) approach:

view_transform = torchvision.transforms.Compose(
    [  LoadAugmentedImage(), ... ]
)
transform = MultiViewTransform(transforms=[view_transform, view_transform])
dataset_train = LightlyDataset(input_dir=path_to_data, transform=transform)

basically instead of transforming an image, first transformer in compose would load from disk and return an already augmented image, I just need to figure out how to get the path of original image in the transform.

@guarin
Copy link
Contributor

guarin commented Apr 26, 2024

Not sure if this would work. LightlyDataset loads one image at a time from the input_dir. Once the image is loaded it is passed to the transform. As the transform only takes an image as input I am not sure how you would load the different augmentations based on the image.

How are your augmentations stored? Do you have one subdirectory per augmentation?

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