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)


wrong536×806 71.4 KB