Normalisation necessary for image reconstruction?

bolt25: <p>I have a dataset which needs to be denoised. When I was looking at the images of my dataloader which are fed into network I saw that the images from dataloader and images in my dataset are very different. Now the only transformation I used are resize and ToTensor().</p>
<p>Is it because of ToTensor()? Is it normalizing my image and is that causing my model to learn nothing?</p>
<p>Can I stop this?</p>

Nikronic: <p>Hi,</p>
<aside class="quote no-group" data-username="bolt25" data-post="1" data-topic="85935">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/bolt25/48/7273_2.png" class="avatar"> bolt25:</div>
<blockquote>
<p>Is it because of ToTensor()?</p>
</blockquote>
</aside>
<p>As you have already figured it out <a href="https://discuss.pytorch.org/t/how-to-input-image-in-a-model-without-normalizing-it/85956" class="inline-onebox">How to input image in a model without normalizing it?</a>.</p>
<p>But AFAIK, normalizing data especially in image processing always improves results. If you look at all pretrained models for different tasks, such as segmentation, classification, etc, all images always have been normalized, so I think the problem is from somewhere else.</p>
<aside class="quote no-group" data-username="bolt25" data-post="1" data-topic="85935">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/bolt25/48/7273_2.png" class="avatar"> bolt25:</div>
<blockquote>
<p>causing my model to learn nothing?</p>
</blockquote>
</aside>
<p>Usually normalization improves results, if your model already cannot learn, using unnormalized images also won’t help much.</p>
<p>Bests</p>

bolt25: <p>See the thing is when I see the image which is going into the model (the normalised one) then as humans we cant make any sense of it. But at the end we need the image which we have in our dataset(unnormalized).</p>
<p>So is there anything I can do to convert the output of model while testing to reverse this normalization effect at the end (while testing)?</p>

Nikronic: <p>This may help:</p>
<pre><code class="lang-auto">min = float(img.min())
max = float(img.max())
img.clamp_(min=min, max=max)
img.add_(-min).div_(max - min + 1e-5)

</code></pre>
<p>Even a simpler way would be using <a href="https://pytorch.org/docs/stable/torchvision/utils.html#torchvision.utils.save_image" rel="nofollow noopener">torchvision.utils.save_image</a></p>

bolt25: <aside class="quote no-group" data-username="Nikronic" data-post="4" data-topic="85935">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/nikronic/48/71873_2.png" class="avatar"> Nikronic:</div>
<blockquote>
<p>torchvision.utils.save_image</p>
</blockquote>
</aside>
<p>Thank you so so much!! This worked like a charm!!</p>

Nikronic: <p>You are welcome.<br>
Are we going to close this question too or it is a different issue?</p><aside class="quote quote-modified" data-post="1" data-topic="85906">
  <div class="title">
    <div class="quote-controls"></div>
    <img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/bolt25/48/7273_2.png" class="avatar">
    <a href="https://discuss.pytorch.org/t/transform-affecting-my-images/85906">Transform affecting my Images</a> <a class="badge-category__wrapper " href="/c/vision/5"><span data-category-id="5" style="--category-badge-color: #AB9364; --category-badge-text-color: #FFFFFF;" data-drop-close="true" class="badge-category " title="Topics related to either pytorch/vision or vision research related topics"><span class="badge-category__name">vision</span></span></a>
  </div>
  <blockquote>
    Im working on fringe pattern denoising and in that I have fringe patterns like:- 
 <a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/b/4/b4f177e003ce9a752dd57ef109872d439493f832.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/b4f177e003ce9a752dd57ef109872d439493f832" title="Screenshot from 2020-06-18 16-43-39">[Screenshot from 2020-06-18 16-43-39]</a> 
but when I apply the transform of ToTensor() 
and then print the image, it turns so bad that my model isn’t learning anything:- 
 <a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/a/6/a62bcd8022392657d6ffe502e04a8fa593e2b404.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/a62bcd8022392657d6ffe502e04a8fa593e2b404" title="Screenshot from 2020-06-18 16-45-37">[Screenshot from 2020-06-18 16-45-37]</a> 
any suggestions on what can I do? 
Because I dont think that its possible train my model on the images without converting them into tensors?
  </blockquote>
</aside>


bolt25: <p>Yeah I’ll close it too!</p>