I had a quick look and I don’t think you need to write your own ToTensor class since one already exists in pytorch (https://pytorch.org/docs/stable/torchvision/transforms.html#torchvision.transforms.ToTensor 7). I would just use that one to transform into tensor and then rearrange the axes with transpose to get the shape you want. In your version, you load the tensor onto the Cuda device before forming the batch but actually, I think it’s better to do all the preprocessing on the CPU and then move to the device you want.
Here is a snippet showing what I think the result should look like
from torchvision import transforms

class my_loader(Dataset):
def __init__(self, root_dir, transform=None):
	self.root_dir = root_dir
	self.transform = transforms.ToTensor()

def __len__(self):
	return 9294

def __getitem__(self, idx):
	img_name = os.path.join(self.root_dir, str(idx) + ".jpg")
	image = io.imread(img_name)
	gray_img = rgb2gray(image)
	lab_img = rgb2lab(image)[:,:,1:]

	gray_img = self.transform(gray_img)
            lab_img = self.transform(lab_img).transpose((2,0,1)

	return sample