Hi everyone.
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.
Data and Network:
class Dataset(Dataset):
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

class ConvNet(nn.Module):
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

If you have any ideas what the problem could be, i would be very thankful. 2632×506 14.3 KB