Group imgs up by targets in ImageFolder

Hi, I’m new to PyTorch. I’m trying to using ImageFolder to load my own dataset.
When I load the folder, the imgs/samples are:

[
    ("img0path.ext",0),
    ("img1path.ext",0),
    ...
]

For some reasons, I need to group them up by targets, just like:

[
    0=[img list of targets 0],
    1=[img list of targets 1],
    ...
]

Is there any convenient way to make this? Or shall I need to implement this on hand?

You could create a custom Dataset and use the ImageFolder as a template or base class, which would probably the cleanest approach.

I see…Actually, I intended to make a siamese pair/triplet dataset with image folder, so that means I have to implement this by myself?

I’m not aware of any dataset implementations for your siamese use case, so I would assume you need to implement a custom Dataset. However, you can of course check other repositories to see if these would provide the needed classes.