Is data['image']
returning a numpy array?
If so, you could just slice it using e.g. data['image'][:4]
, if you want to get the first 4 images.
You could try to write your custom Dataset
, load all data in __init__
, and get a single sample in __getitem__
. Here is some dummy example:
class MyDataset(Dataset):
def __init__(self, mat_path):
data = io.loadmat(mat_path)
self.images = torch.from_numpy(data['images'])
self.targets = torch.from_numpy(data['tumorMask'])
def __getitem__(self, index):
x = self.images[index]
y = self.targets[index]
return x, y
def __len__(self):
return len(self.images)
Also, have a look at the Data loading tutorial to see how the Dataset
and DataLoader
play together.