Denoising Autoencoder

pedram1: <p>Hi everyone<br>
I have a stupid question,<br>
Is anyone knows that what should be the form of loss function in an Denoising Autoencoder?<br>
should it be like below?;</p>
<p>loss = criterion (model (noisy_data),noise_less_data)<br>
basically model (noisy_data) is the model will be trained with inputs that are corrupted data and loss function calculates the difference (here MSE) between output of the model and the data that are not noisy ?</p>
<p>In this way that makes no sense to me. because if we already have access to noiseless data, then what’s the point of building up a denoising autoencoder?</p>

ptrblck: <p>The goal would be to train the model to be able to denoise new data.<br>
The same question might apply to why we would like to train a model to classify dogs and cats, if we already have the labels. <img src="https://discuss.pytorch.org/images/emoji/apple/wink.png?v=9" title=":wink:" class="emoji" alt=":wink:"></p>

pedram1: <p>That totally makes sense. <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"><br>
One more question:<br>
Do u if there is any method (model) that can be do in an unsupervised way? I mean without seeing noiseless data, to Denise noisy data?<br>
Tnx</p>

ptrblck: <p>This is most likely not the state of the art technique anymore, but have a look at <a href="https://github.com/DmitryUlyanov/deep-image-prior">Deep Image Prior</a>.</p>

pedram1: <p>I have one more question,about that:</p>
<p>For both noiseless data as well as noisy input of the NN, I used dataloader (I have two data loader for each) Now I am a bit of worry because the shuffle option is set to True in both data loader.  Do you think this might affect my training because I should compare same pixel from the noisy data with the same pixel from the noiseless data …</p>

simaiden: <p>You should use one dataloader instead of two, and get the noise and noiseless data at the same time</p>

pedram1: <p>Can you please give me a clue ?<br>
below u can see my DataLoader codes:</p>
<p>class CustomDataset(torch.utils.data.Dataset):<br>
def <strong>init</strong>(self, data):<br>
self.data = data</p>
<pre><code>def __getitem__(self, index):
    return self.data[index]

def __len__(self):
    return len(self.data)
</code></pre>
<p>x = data_ll<br>
separation = int(x.shape[0] * 0.8)<br>
train = x[:separation]<br>
test = x[separation:]</p>
<p>train_dataset = CustomDataset(train)<br>
test_dataset = CustomDataset(test)</p>
<p>train_loader_ll = torch.utils.data.DataLoader(train_dataset, batch_size=2621,shuffle = False)<br>
test_loader_ll = torch.utils.data.DataLoader(test_dataset, batch_size=655,shuffle = False)<br>
print ("//////////////////////////Training dataset//////////////////////////")<br>
for train_sample in train_loader_ll:<br>
print(train_sample.shape)</p>
<p>print ("//////////////////////////Test dataset//////////////////////////")</p>
<p>for test_sample in test_loader_ll:<br>
print(test_sample.shape)</p>
<p>Basically I use this twice. One for noisy data and the other for noiseless data.</p>

simaiden: <p>What it’s the format of your data? I mean <code>x</code> have both noise and noise less data or only one of them?</p>

pedram1: <p>x here is a tensor of the size (65536,1,92) and it is just noisy data.<br>
I made one another class one trainload for the noiseless data.</p>

Abhi: <p>I wish to build a Denoising autoencoder I just use a small definition from another PyTorch thread to add noise in the MNIST dataset. While training my model gives  identical  loss results. please tell me what I am doing wrong.</p>
<p>def add_noise(inputs):</p>
<pre><code>noise = torch.randn_like(inputs)*0.3
return inputs + noise 
</code></pre>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/c/a/ca08daa1ebaf40d1d3bed8c078e579834d2893f9.png" data-download-href="https://discuss.pytorch.org/uploads/default/ca08daa1ebaf40d1d3bed8c078e579834d2893f9" title="Screenshot_120"><img src="https://discuss.pytorch.org/uploads/default/original/3X/c/a/ca08daa1ebaf40d1d3bed8c078e579834d2893f9.png" alt="Screenshot_120" data-base62-sha1="sPhpXwaueYFCbaaQqlp1dLcXrYZ" width="690" height="450" data-dominant-color="E5DDDD"><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">Screenshot_120</span><span class="informations">1116×729 34.1 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>Could you post the model definition so that we could take a look, if you are accidentally detaching the computation graph?</p>

Abhi: <p>Thankyou <a class="mention" href="/u/ptrblck">@ptrblck</a> for the reply. I am posting my model. and please tell me what is wrong<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/5/5/554e847d60f4a3902fc0e5c6d7453adb51da0bee.png" data-download-href="https://discuss.pytorch.org/uploads/default/554e847d60f4a3902fc0e5c6d7453adb51da0bee" title="Screenshot_124"><img src="https://discuss.pytorch.org/uploads/default/original/3X/5/5/554e847d60f4a3902fc0e5c6d7453adb51da0bee.png" alt="Screenshot_124" data-base62-sha1="caEO661C2sZ0faBw4NE4eikTkV8" width="568" height="500" data-dominant-color="EAEAEA"><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">Screenshot_124</span><span class="informations">701×617 35.5 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>The model looks generally alright, but I’m not sure if you really want to apply the last <code>F.relu</code> on the output. As a debugging step you could remove it and rerun your training.</p>
<p>PS: you can post code snippets by wrapping them into three backticks ```, which would allow to copy and debug your code <img src="https://discuss.pytorch.org/images/emoji/apple/wink.png?v=9" title=":wink:" class="emoji" alt=":wink:"></p>