CNN creates strange output

Marcel_Iten: <p>Hi everyone.</p>
<p>I am having problems while learning my CNN. The input is an image and the output is an image of the same size. The network should learn to reconstruct the output from the input image. But i get different results everytime. So i think something with the update of parameters is wrong.<br>
Data and Network:</p>
<p>class Dataset(Dataset):</p>
<pre><code>def __init__(self, data_dir, transform):

    self.data_dir = data_dir

    self.transform = transform

    self.train_imgs = os.listdir(data_dir)

    

def __len__(self):

    return len(self.train_imgs)



def __getitem__(self, idx):

    #loads the images to train

    img_loc = os.path.join(self.data_dir, self.train_imgs[idx])

    image = Image.open(img_loc)

    image = image.convert('L')

    image = image.resize((80,60))

    image = image.resize((640,480),Image.BICUBIC)

    image = np.asarray(image)

    image = image/255

    tensor_train = torch.from_numpy(image).float()

    tensor_train = tensor_train.unsqueeze(0)

    

    #loads the images as ground truth

    ground_loc = os.path.join(self.data_dir, self.train_imgs[idx])

    ground = Image.open(ground_loc)

    ground = ground.convert('L')

    ground = ground.resize((320,240))

    ground = ground.resize((640,480),Image.BICUBIC)

    ground = np.asarray(ground)

    ground = ground/255

    ground = ground-image

    tensor_ground = torch.from_numpy(ground).float()

    tensor_ground = tensor_ground.unsqueeze(0)

    return tensor_train, tensor_ground
</code></pre>
<p>class ConvNet(nn.Module):</p>
<pre><code>def __init__(self):

    super(ConvNet, self).__init__()

    self.conv1 = nn.Conv2d(1,32,3, padding = 1)

    self.conv2 = nn.Conv2d(32,32,3, padding= 1)

    #self.conv3 = nn.Conv2d(32,32,3, padding = 1)

    #self.conv4 = nn.Conv2d(32,32,3, padding = 1)

    #self.conv5 = nn.Conv2d(32,32,3, padding = 1)

    #self.conv6 = nn.Conv2d(32,32,3, padding = 1)

    #self.conv7 = nn.Conv2d(32,32,3, padding = 1)

    #self.conv8 = nn.Conv2d(32,32,3, padding = 1)

    #self.conv9 = nn.Conv2d(32,32,3, padding = 1)

    #self.conv10 = nn.Conv2d(32,32,3, padding = 1)

    #self.conv11 = nn.Conv2d(32,32,3, padding = 1)

    #self.conv12 = nn.Conv2d(32,32,3, padding = 1)

    #self.conv13 = nn.Conv2d(32,32,3, padding = 1)

    #self.conv14 = nn.Conv2d(32,32,3, padding = 1)

    #self.conv15 = nn.Conv2d(32,32,3, padding = 1)

    #self.conv16 = nn.Conv2d(32,32,3, padding = 1)

    #self.conv17 = nn.Conv2d(32,32,3, padding = 1)

    #self.conv18 = nn.Conv2d(32,32,3, padding = 1)

    #self.conv19 = nn.Conv2d(32,32,3, padding = 1)

    self.conv20 = nn.Conv2d(32,1,3, padding = 1)

    

def forward(self, x):

    x = F.relu(self.conv1(x))

    x = F.relu(self.conv2(x))

    #x = F.relu(self.conv3(x))

    #x = F.relu(self.conv4(x))

    #x = F.relu(self.conv5(x))

    #x = F.relu(self.conv6(x))

    #x = F.relu(self.conv7(x))

    #x = F.relu(self.conv8(x))

    #x = F.relu(self.conv9(x))

    #x = F.relu(self.conv10(x))

    #x = F.relu(self.conv11(x))

    #x = F.relu(self.conv12(x))

    #x = F.relu(self.conv13(x))

    #x = F.relu(self.conv14(x))

    #x = F.relu(self.conv15(x))

    #x = F.relu(self.conv16(x))

    #x = F.relu(self.conv17(x))

    #x = F.relu(self.conv18(x))

    #x = F.relu(self.conv19(x))

    x = self.conv20(x)

    return x
</code></pre>
<p>If you have any ideas what the problem could be, i would be very thankful. <div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/1/8/18611699500205514b805b58de037f7d3a5d22fd.png" data-download-href="https://discuss.pytorch.org/uploads/default/18611699500205514b805b58de037f7d3a5d22fd" title="2"><img src="https://discuss.pytorch.org/uploads/default/original/3X/1/8/18611699500205514b805b58de037f7d3a5d22fd.png" alt="2" data-base62-sha1="3tFt8xJazXTu9r4WwM8NniGLZoh" width="624" height="500" data-dominant-color="F0F0F0"><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">2</span><span class="informations">632×506 14.3 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>