0

I want to make a binary classifier that classifies the following:

Class 1. Some images that I already have.

Class 2. Some images that I create from a function, using the images of class 1.

The problem is that instead of pre-creating the two classes, and then loading them, to speed up the process I would like the class 2 images to be created for each batch.

Any ideas on how I can tackle the problem? If I use the DataLoader as usual, I have to enter the images of both classes directly, but if I still don't have the images of the second class I don't know how to do it.

Thanks.

2
  • Do you want to save the images of class 2 after processing or only preprocessing them and then train the model? Commented Mar 8, 2022 at 19:02
  • Well a simple way of doing it instead of datasets and loaders is a simple stack to create 1 batch via the torch.stack function Commented Mar 9, 2022 at 3:08

1 Answer 1

1

You can tackle the problem in at least two ways.

  1. (Preferred) You create a custom Dataset class, AugDset, such that AugDset.__len__() returns 2 * len(real_dset), and when idx > len(imgset), AugDset.__getitem__(idx) generates the synthetic image from real_dset(idx).
  2. You create your custom collate_fn function, to be passed to DataLoader that, given a batch, it augments it with your synthetic generated images.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.