If I transform, the model do not start learning

fmsilver: <p>Problem:<br>
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.</p>
<p>Non-working code:</p>
<pre><code class="lang-auto">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)
</code></pre>
<p>Working code (But without normalization…):</p>
<pre><code class="lang-auto">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)
</code></pre>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/d/5/d5ad377ba4d06baa9681c2915fd6042167321843.png" data-download-href="https://discuss.pytorch.org/uploads/default/d5ad377ba4d06baa9681c2915fd6042167321843" title="wrong"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/d/5/d5ad377ba4d06baa9681c2915fd6042167321843_2_332x500.png" alt="wrong" data-base62-sha1="uugOC0qZLx0NOYJyEqjoSS2uTej" width="332" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/d/5/d5ad377ba4d06baa9681c2915fd6042167321843_2_332x500.png, https://discuss.pytorch.org/uploads/default/optimized/3X/d/5/d5ad377ba4d06baa9681c2915fd6042167321843_2_498x750.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/d/5/d5ad377ba4d06baa9681c2915fd6042167321843.png 2x" data-dominant-color="5E5D5C"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">wrong</span><span class="informations">536×806 71.4 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

ptrblck: <p><code>Normalize</code> works on tensors, so <code>ToTensor()</code> should be applied before it.<br>
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.</p>

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