Dataloader for two labels:coarse_label anf fine_label

I have to have two labels: coarse_label and fine_label, under there is the dataloader for a single label. How to modify the dataloader?
here I have the piece of train code for cifar 100 with only label:
if args.onlygan:
loaders = {
‘train’: trainloader
loaders = {
‘train’: trainloader,
‘test’: testloader
} for epoch in range(args.epochs):

    #print("EPOCH: ", epoch, "/", args.epochs)
    for split in loaders:
        data_loader = loaders[split]

        for  i ,(inputs,labels) in enumerate(tqdm(data_loader, desc=f'EPOCH: {epoch+1}/{args.epochs}')):

in a separate file:
trainset = torchvision.datasets.CIFAR100(root='./data' ,train=True,
                             download=True, transform=transform)
``` trainloader =, batch_size=batch_size,
                                              shuffle=True, num_workers=4)

My doubt is this: if there are inputs and labels for the cifar 100 in the train, the inputs, coarse labels and labels should be in the train. The dataloader for how it is implemented with 2 labels load.

You could create a custom Dataset which would return both labels with the input data as described in this tutorial.

import torch
import torchvision.transforms as transforms
import torchvision
from tqdm import tqdm
#from utils.saver import Saver
from torchvision.utils import save_image
import pickle
def get_loaders(batch_size):

classes = ('beaver', 'dolphin', 'otter', 'seal','whale',
          'aquarium fish','flatfish','ray', 'shark', 'trout',
      'orchids', 'poppies','roses','sunflowers','tulips',
      'bottles',' bowls', 'cans', 'cups', 'plates',
      'apples',' mushrooms', 'oranges',' pears','sweet peppers',
      'clock','computer keyboard','lamp','telephone', 'television',
      'bed', 'chair','couch', 'table', 'wardrobe',
      'bee',' beetle','butterfly','caterpillar', 'cockroach',
      'bear', 'leopard', 'lion', 'tiger',' wolf',
          'bridge', 'castle', 'house','road', 'skyscraper',
      'cloud', 'forest', 'mountain', 'plain', 'sea',
      'fox',' porcupine',' possum', 'raccoon',' skunk',
          'crab', 'lobster', 'snail', 'spider', 'worm',
      'baby', 'boy', 'girl', 'man',' woman',
      'crocodile', 'dinosaur', 'lizard',' snake', 'turtle',
      'hamster', 'mouse', 'rabbit', 'shrew','squirrel',
      'maple','oak', 'palm',' pine', 'willow',
      'bicycle', 'bus','motorcycle', 'pickup truck', 'train',
          'lawn-mower', 'rocket',' streetcar', 'tank', 'tractor')
transform = transforms.Compose(
    [   #transforms.Resize(224), #for alexnet
        transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))]
trainset = torchvision.datasets.CIFAR100(root='./data', train=True,
                         download=True, transform=transform)

testset = torchvision.datasets.CIFAR100(root='./data', train=False,
                        download=True, transform=transform)

trainloader =, batch_size=batch_size,
                                          shuffle=True, num_workers=4)

testloader =, batch_size=batch_size,
                                         shuffle=False, num_workers=4) 



return trainloader, testloader, classes,label_names,trainset

this is the file i had for the cifar100, i wonder if i can specify the labels inside Dataloader () type label_mode = ‘coarse_label’ or coarse label = True since the above dataloader nn allows me to have two labels.
assuming that the cifar10 train file contains a dictionary with data, labels, for the cifar 100 the train would contain data, labels and coarse_labels?

The DataLoader will just use the passed Dataset to create batches by loading each sample via the Dataset.__getitem__ method.
I don’t see, where your current script allows the DataLoader to return two labels.
Do you mean that your get_loaders method returns multiple values?

CIFAR10 uses lists to store the data and target as seen here.
If you want to add another label or manipulate the already loaded labels, I would recommend to write a custom Dataset and apply the modifications in the new __init__ method.