lightly icon indicating copy to clipboard operation
lightly copied to clipboard

Ability to use pre-made augmentations

Open vedranf opened this issue 10 months ago • 3 comments

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

vedranf avatar Apr 22 '24 13:04 vedranf

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 :)

guarin avatar Apr 23 '24 06:04 guarin

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.

vedranf avatar Apr 24 '24 18:04 vedranf

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?

guarin avatar Apr 26 '24 06:04 guarin

Will close this for now, please reopen if you have more questions.

guarin avatar Aug 16 '24 07:08 guarin