my images are in numpy array loaded from csv file
train _X shape: (28709, 1, 48, 48) train _Y shape: (28709,)
val _X shape: (3589, 1, 48, 48) val _Y shape: (3589,)
test _X shape: (3589, 1, 48, 48) test _Y shape: (3589,)
i tried train_X[0].expand(3,-1,-1) and it dint worked .
i created a custom dataset and trying to apply transforms but transforms.ToPILImage is not accepting my image . so i thought  to convert into RGB but dont know how to do it
class MyDataset(Dataset):
def __init__(self, data, targets, transform=None):
    self.data = data
    self.targets = torch.LongTensor(targets)
    self.transform = transform

def __getitem__(self, index):
    x = self.data[index]
    y = self.targets[index]
    if self.transform:
        x = Image.fromarray(self.data[index].astype(np.uint8).transpose(1,2,0)).convert('RGB')
        x = self.transform(x)
    return x, y

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

transform = transforms.Compose([transforms.ToPILImage(),
                            transforms.Resize(256),
                            transforms.RandomHorizontalFlip(),
                            transforms.RandomVerticalFlip(),
                            transforms.RandomRotation(15),
                            transforms.CenterCrop(224),
                            transforms.ToTensor(),
                            transforms.Normalize([0.5, 0.5, 0.5],
                                                [0.5, 0.5, 0.5])])
train_data= MyDataset(train_X, train_Y, transform=transform)
valid_data = MyDataset(val_X, val_Y, transform=transform)
test_data = MyDataset(test_X, test_Y, transform=transform)

This is thowring an error  TypeError: Cannot handle this data type: (1, 1, 1), |u1