Answers.Body: <p>Perhaps you are getting checkerboard artifacts <a href="https://distill.pub/2016/deconv-checkerboard/" rel="nofollow noreferrer">Explained here</a>, solutions involve changing the kernel and stride size to prevent them from being not divisible. Besides that, a solution could be to apply Gaussian smoothing to minimize the artifacts.</p>
  <p>For example, using Gaussian smoothing in OpenCV with your image results in</p>
  <pre><code>import cv2
  img = cv2.imread('s.png') # I took a screen shot to see how it would look
  blur = cv2.blur(img,(8,8))
  plt.imshow(blur)
  </code></pre>
  <p><a href="https://i.sstatic.net/cBchd.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/cBchd.png" alt="enter image description here" /></a></p>
  <p>The artifact is gone using a kernel of size (8,8). I hope this can help</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-07-01T00:31:43.213Z
Answers.LastActivityDate: 2020-07-01T00:31:43.213Z
Answers.UserDisplayName: RodOnStackOverflow
Body: <p>As experiment, I have tried using an autoencoder to encode height data from the alps, however the decoded image is very pixellated after training for several hours as show in the image below. This repeating patter is larger than the final kernel size, so I would think it would possible to remove these repeating patterns from the image to some extent.</p>
  
  <p>The image is (1, 512, 512) and is sampled down to (16, 32, 32). This is done with pytorch. Here is the relevant sample of the code in which the exact layers are shown.</p>
  
  
  
  <pre><code>        self.encoder = nn.Sequential(
                  # Input is (N, 1, 512, 512)
                  nn.Conv2d(1, 16, 3, padding=1), # Shape (N, 16, 512, 512)
                  nn.Tanh(),
                  nn.MaxPool2d(2, stride=2), # Shape (N, 16, 256, 256)
                  nn.Conv2d(16, 32, 3, padding=1), # Shape (N, 32, 256, 256)
                  nn.Tanh(),
                  nn.MaxPool2d(2, stride=2), # Shape (N, 32, 128, 128)
                  nn.Conv2d(32, 32, 3, padding=1), # Shape (N, 32, 128, 128)
                  nn.Tanh(),
                  nn.MaxPool2d(2, stride=2), # Shape (N, 32, 64, 64)
                  nn.Conv2d(32, 16, 3, padding=1), # Shape (N, 16, 64, 64)
                  nn.Tanh(),
                  nn.MaxPool2d(2, stride=2) # Shape (N, 16, 32, 32)
              )
          self.decoder = nn.Sequential(
                  # Transpose convolution operator
                  nn.ConvTranspose2d(16, 32, 4, stride=2, padding=1), # Shape (N, 32, 64, 64)
                  nn.Tanh(),
                  nn.ConvTranspose2d(32, 32, 4, stride=2, padding=1), # Shape (N, 32, 128, 128)
                  nn.Tanh(),
                  nn.ConvTranspose2d(32, 16, 4, stride=2, padding=1), # Shape (N, 32, 256 256)
                  nn.Tanh(),
                  nn.ConvTranspose2d(16, 1, 4, stride=2, padding=1), # Shape (N, 32, 512, 512)  
                  nn.ReLU()
              )
  </code></pre>
  
  <p><a href="https://i.sstatic.net/VU6u1.png" rel="noreferrer"><img src="https://i.sstatic.net/VU6u1.png" alt="Relevant image: left side original, right side result from autoencoder"></a></p>
  
  <p>Relevant image: left side original, right side result from autoencoder</p>
  
  <p>So could these pixellated effects in the above image be resolved?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-01-09T00:37:12.587Z
Comments.Text: An autoencoder will always lose some features of the original image. Perhaps try increasing the size the original image is down sampled to before reconstruction
Comments.UserDisplayName: Recessive
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-01-09T12:52:07.587Z
Comments.Text: I have tried it now. Still, the same result. I also tried not downsampling at all i.e. sending the image to a 16x128x128 and then transforming it back.
Comments.UserDisplayName: Yadeses
Tags: <convolutional-neural-networks><autoencoders><image-processing>
Title: Autoencoder produces repeated artifacts after convergence
UserDisplayName: Yadeses
ThreadText: # Autoencoder produces repeated artifacts after convergence
  
  (Asked by: username_0 on 2020-01-08)
  
  As experiment, I have tried using an autoencoder to encode height data from the alps, however the decoded image is very pixellated after training for several hours as show in the image below. This repeating patter is larger than the final kernel size, so I would think it would possible to remove these repeating patterns from the image to some extent.
  
  The image is (1, 512, 512) and is sampled down to (16, 32, 32). This is done with pytorch. Here is the relevant sample of the code in which the exact layers are shown.
  
  ```
          self.encoder = nn.Sequential(
                  # Input is (N, 1, 512, 512)
                  nn.Conv2d(1, 16, 3, padding=1), # Shape (N, 16, 512, 512)
                  nn.Tanh(),
                  nn.MaxPool2d(2, stride=2), # Shape (N, 16, 256, 256)
                  nn.Conv2d(16, 32, 3, padding=1), # Shape (N, 32, 256, 256)
                  nn.Tanh(),
                  nn.MaxPool2d(2, stride=2), # Shape (N, 32, 128, 128)
                  nn.Conv2d(32, 32, 3, padding=1), # Shape (N, 32, 128, 128)
                  nn.Tanh(),
                  nn.MaxPool2d(2, stride=2), # Shape (N, 32, 64, 64)
                  nn.Conv2d(32, 16, 3, padding=1), # Shape (N, 16, 64, 64)
                  nn.Tanh(),
                  nn.MaxPool2d(2, stride=2) # Shape (N, 16, 32, 32)
              )
          self.decoder = nn.Sequential(
                  # Transpose convolution operator
                  nn.ConvTranspose2d(16, 32, 4, stride=2, padding=1), # Shape (N, 32, 64, 64)
                  nn.Tanh(),
                  nn.ConvTranspose2d(32, 32, 4, stride=2, padding=1), # Shape (N, 32, 128, 128)
                  nn.Tanh(),
                  nn.ConvTranspose2d(32, 16, 4, stride=2, padding=1), # Shape (N, 32, 256 256)
                  nn.Tanh(),
                  nn.ConvTranspose2d(16, 1, 4, stride=2, padding=1), # Shape (N, 32, 512, 512)  
                  nn.ReLU()
              )
  
  ```
  
  [![Relevant image: left side original, right side result from autoencoder](https://i.sstatic.net/VU6u1.png)](https://i.sstatic.net/VU6u1.png)
  
  Relevant image: left side original, right side result from autoencoder
  
  So could these pixellated effects in the above image be resolved?
  
  **Tags:** convolutional-neural-networks, autoencoders, image-processing
  
  > **Comments:**
  > **username_1**: An autoencoder will always lose some features of the original image. Perhaps try increasing the size the original image is down sampled to before reconstruction  
  > **username_0**: I have tried it now. Still, the same result. I also tried not downsampling at all i.e. sending the image to a 16x128x128 and then transforming it back.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2020-07-01. Score: 3
  
  Perhaps you are getting checkerboard artifacts [Explained here](https://distill.pub/2016/deconv-checkerboard/), solutions involve changing the kernel and stride size to prevent them from being not divisible. Besides that, a solution could be to apply Gaussian smoothing to minimize the artifacts.
  
  For example, using Gaussian smoothing in OpenCV with your image results in
  
  ```
  import cv2
  img = cv2.imread('s.png') # I took a screen shot to see how it would look
  blur = cv2.blur(img,(8,8))
  plt.imshow(blur)
  
  ```
  
  [![enter image description here](https://i.sstatic.net/cBchd.png)](https://i.sstatic.net/cBchd.png)
  
  The artifact is gone using a kernel of size (8,8). I hope this can help
  
  
  ---
  
  