Body: <p>I’m trying to train an autoencoder on the hazelnut dataset of MVTec AD for reconstruction to detect anomalies.</p>
  <p>I’m am trying to replicate the results of this study:
  <a href="https://arxiv.org/pdf/2008.12977.pdf" rel="nofollow noreferrer">https://arxiv.org/pdf/2008.12977.pdf</a></p>
  <p>In particular, the simpler setup used in the study as reference, with features a simple AE model with no skip connection and no stain model. Just a plain 6 layer encoder and 6 layer decoder.
  The encoder layers have 16-32-64-128-256-512 filters, strided conv with kernel of 5, BatchNorm, and leakuRelu activation. The decoder have the same filter sizes, and have upsampling, conv (kernel=5), batchnorm, leakyRelu and sigmoid at the final layer.
  As in the paper, i’m using MSE as loss, Adam as optimizer (batch of 16) and i’m augmenting the input data with some cropping, rotations and flipping.</p>
  <p>Although I feel like I have been doing what is described in the paper, my model is unable to learn any anything meaningful and only shows very rough and blurred white shadows for reconstruction:</p>
  <p><a href="https://i.sstatic.net/jbiZp.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/jbiZp.png" alt="hazelnuts originals and reconstructions" /></a></p>
  <p>The code and my notebook is available here : <a href="https://nbviewer.org/urls/gist.githubusercontent.com/KenN7/8e835334a669599b42c4144d3e68f617/raw/2a59b578fc9e5febc1e00f535eb75ec5e72b8f35/gistfile1.txt" rel="nofollow noreferrer">Jupyter Notebook Viewer</a></p>
  <p>I don’t get what I am doing wrong here, I know that some things could improve the situation (e.g. using SSIM as loss), but I’m more interested in achieving the results of the paper ( 0.9 AUC% in the setup ). Do you have any idea what could be wrong ?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-11-07T07:28:16.783Z
Comments.Text: Hi, just brushed over your code and wanted to mention that I don't see any standardizations on the images. When you perform the augmentations, before that we usually normalize images (pixel values) to be in the range [0, 1]; Is it done already?
Comments.UserDisplayName: Suvo
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-11-09T10:32:01.727Z
Comments.Text: Hi, thx for your comment, yes, it is done with the ToTensor transform that automatically turns the images into (0,1) tensors. 
  At the end, i think this behavior and quality of reconstruction is normal, considering the size of my latent space.
Comments.UserDisplayName: JeanMi
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-11-09T12:42:43.653Z
Comments.Text: If it is too large which I think is in your case, it could be a problem. Here I found a similar thread [https://ai.stackexchange.com/questions/37272/what-is-an-appropriate-size-for-a-latent-space-of-variational-autoencoders-and]
Comments.UserDisplayName: Suvo
Tags: <computer-vision><deep-neural-networks><autoencoders><anomaly-detection>
Title: Replicating conv autoencoder for anomaly detection, very blurry reconstructions
UserDisplayName: JeanMi
ThreadText: # Replicating conv autoencoder for anomaly detection, very blurry reconstructions
  
  (Asked by: username_0 on 2023-10-31)
  
  I’m trying to train an autoencoder on the hazelnut dataset of MVTec AD for reconstruction to detect anomalies.
  
  I’m am trying to replicate the results of this study:
  <https://arxiv.org/pdf/2008.12977.pdf>
  
  In particular, the simpler setup used in the study as reference, with features a simple AE model with no skip connection and no stain model. Just a plain 6 layer encoder and 6 layer decoder.
  The encoder layers have 16-32-64-128-256-512 filters, strided conv with kernel of 5, BatchNorm, and leakuRelu activation. The decoder have the same filter sizes, and have upsampling, conv (kernel=5), batchnorm, leakyRelu and sigmoid at the final layer.
  As in the paper, i’m using MSE as loss, Adam as optimizer (batch of 16) and i’m augmenting the input data with some cropping, rotations and flipping.
  
  Although I feel like I have been doing what is described in the paper, my model is unable to learn any anything meaningful and only shows very rough and blurred white shadows for reconstruction:
  
  [![hazelnuts originals and reconstructions](https://i.sstatic.net/jbiZp.png)](https://i.sstatic.net/jbiZp.png)
  
  The code and my notebook is available here : [Jupyter Notebook Viewer](https://nbviewer.org/urls/gist.githubusercontent.com/KenN7/8e835334a669599b42c4144d3e68f617/raw/2a59b578fc9e5febc1e00f535eb75ec5e72b8f35/gistfile1.txt)
  
  I don’t get what I am doing wrong here, I know that some things could improve the situation (e.g. using SSIM as loss), but I’m more interested in achieving the results of the paper ( 0.9 AUC% in the setup ). Do you have any idea what could be wrong ?
  
  **Tags:** computer-vision, deep-neural-networks, autoencoders, anomaly-detection
  > **Comments:**
  > **username_1**: Hi, just brushed over your code and wanted to mention that I don't see any standardizations on the images. When you perform the augmentations, before that we usually normalize images (pixel values) to be in the range [0, 1]; Is it done already?  
  > **username_0**: Hi, thx for your comment, yes, it is done with the ToTensor transform that automatically turns the images into (0,1) tensors.  At the end, i think this behavior and quality of reconstruction is normal, considering the size of my latent space.  
  > **username_1**: If it is too large which I think is in your case, it could be a problem. Here I found a similar thread [https://ai.stackexchange.com/questions/37272/what-is-an-appropriate-size-for-a-latent-space-of-variational-autoencoders-and]  
  
  ---
  
  ## 0 answers
  
  