How do I combine two file(one is training data, another is the corresponding label) into one dataset?

There are two tiff files containing training data and the corresponding label.
I only implemented one experience(MNIST dataset for recognition of handwritten numbers) before, in which case there is one dataloader for me to extract both data and label simultaneously in a tuple.
And I don’t know how to use data in the form I encountered this time…
Wonder what method is commonly used.
Need for Help

Here’s part of my code:

data_set = ISBIdata(‘D:/Projects/U-Net/train-volume.tif’)
label_set = ISBIdata(‘D:/Projects/U-Net/train-labels.tif’)
test_set = ISBIdata(‘D:/Projects/U-Net/test-volume.tif’)

data_loader = DataLoader(data_set, batch_size = args.batch_size)
label_loader = DataLoader(label_set, batch_size = args.batch_size)
test_loader = DataLoader(test_set, batch_size = args.batch_size)

def train():
for idx, in enumerate(data_loader):
data =
label =
data.requires_grad = True
data =
label =
pred = model(data)
loss = criterion(pred, label)

Hello, I would advise you to create one dataloader for training and one for testing. To do this you can implement your own dataset which reads training data and corresponding label. There are a bunch of examples of such datasets online but here is one from the tutorials

Your dataset would know about both the data path and the label path. In the get_item function, you’d read one example from the train-volume.tif and the corresponding one from train-volume.tif. Write back if you’re having problems!

Edit: An ugly way to do it, which might not work would be

data_and_label = zip(data_loader, label_loader)

for idx, data in enumerate(data_and_label):
  data_item, label_item = data
  print(data_item, label_item)

I think i’m getting it, found some related examples but guess i’m not familiar with module ‘pandas’ or ‘os’, got to learn a bit.
thank u~~

1 Like