How to get gender information as label from CelebA dataset

Hi,

I’d like to get label which has only gender information from torchvision.datasets.CelebA

My code snippet is as follows:

trainset = torchvision.datasets.CelebA(..., download=True, split='train', target_type='attr', ...)
trainloader = torch.utils.data.DataLoader(trainset, ...)

for idx, (imgs, labels) in enumerate(trainlader):
    imgs = imgs.to(device)
    labels = labels.to(device)

What I really want to do is get labels only have gender information.

In this case, what should I do?

If I’m not mistaken, the default target_type="attr" should yield various attributes including the male attribute, so you could slice the target for this attribute only.