If I transform, the model do not start learning

Problem:
When I try to normalize my data, the model never start learning, without error message it just run without actually running, see uploaded picture. The green “In [1]” appears after a few seconds, but the red square keeps being red.

Non-working code:

class DATA(Dataset):
    def __init__(self,x,y,transform):
        self.x_data    = x
        self.y_data    = y
        self.transform = transform
        self.len = self.x_data.shape[0]

    def __getitem__(self, index):
        X_data = self.x_data[index]
        X_data = self.transform(X_data)
        Y_data = self.y_data[index]
        return X_data,Y_data,index

    def __len__(self):
        return self.len
 
def data_aug():
    from torchvision import transforms   
    transform = transforms.Compose([
                transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                     std=[0.229, 0.224, 0.225]),
                transforms.ToTensor()
                ])
    return transform
transform  = data_aug()
dataset = DATA(train_x,train_y,transform)

Working code (But without normalization…):

class DATA(Dataset):
    def __init__(self,x,y,transform):
        self.x_data    = x
        self.y_data    = y
        self.transform = transform
        self.len = self.x_data.shape[0]

    def __getitem__(self, index):
        X_data = self.x_data[index]
        #  X_data = self.transform(X_data)
        Y_data = self.y_data[index]
        return X_data,Y_data,index

    def __len__(self):
        return self.len
 
def data_aug():
    from torchvision import transforms   
    transform = transforms.Compose([
                transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                     std=[0.229, 0.224, 0.225]),
                transforms.ToTensor()
                ])
    return transform
transform  = data_aug()
dataset = DATA(train_x,train_y,transform)

Normalize works on tensors, so ToTensor() should be applied before it.
I’m not sure, why your notebook isn’t raising an error, but if you are running it in your terminal directly, you should get a proper error message.

The ‘ToTensor()’ before ‘Normalize’ raised the error. I had a line with “train_x = transform(train_x)”.
So this was really not a general problem for PyTorch. But big thanks for your response!