for reference, this is my dataloader
import torch

from torch.utils import data

class Hdf5_dl(data.Dataset):
    """HDF5 datasets"""

    def __init__(self, archive, transform = None):
        self.archive = h5.File(archive, 'r')
        self.labels = torch.tensor(self.archive['labels'])
        self.data = torch.tensor(self.archive['data']).contiguous(memory_format=torch.channels_last)
        self.transform = transform

    def __getitem__(self, index):
        sample = self.data[index]

        if self.transform is not None:
            sample = self.transform(sample)

        return sample, self.labels[index]

    def __len__(self):
        return len(self.labels)

    def close(self):
        self.archive.close()