Autoencoder strange output

username: lauriat
cooked: <p>Hi,</p>
<p>I’m trying to implement a vanilla autoencoder for the STL10 image dataset, but<br>
I’m facing some issues.<br>
The output of the model looks rather blurry and doesn’t really capture much of the original image. Could be due to bad model size (approx 3M parameters) or poor architecture. What I do not understand is the ‘blockiness’ of the output (attached figure) - it looks like the output image consists of 9 square segments with visible borders, and it happens for every output image. Any ideas where such behaviour coming from?</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/d/6/d66351a85f7f74d87bb27078a59f99601f8fb53f.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/d66351a85f7f74d87bb27078a59f99601f8fb53f" title="Screenshot 2020-05-05 at 21.33.31"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/d/6/d66351a85f7f74d87bb27078a59f99601f8fb53f_2_314x500.jpeg" alt="Screenshot 2020-05-05 at 21.33.31" data-base62-sha1="uAyY3iotC49Sk7bRnzo6zD983kH" width="314" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/d/6/d66351a85f7f74d87bb27078a59f99601f8fb53f_2_314x500.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/d/6/d66351a85f7f74d87bb27078a59f99601f8fb53f_2_471x750.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/d/6/d66351a85f7f74d87bb27078a59f99601f8fb53f_2_628x1000.jpeg 2x" data-dominant-color="9C9687"><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 2020-05-05 at 21.33.31</span><span class="informations">630×1002 103 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>
<p>I’m using BCELoss, Adam optimizer, 128 batch size and the model architecture looks like</p>
<pre><code class="lang-auto">self.downscale_conv = nn.Sequential(
            nn.Conv2d(3, 64, kernel_size=5, stride=2, padding=0),
            nn.BatchNorm2d(64),
            nn.ReLU(),
            nn.Conv2d(64, 128, kernel_size=5, stride=2, padding=1),
            nn.BatchNorm2d(128),
            nn.ReLU(),
            nn.Conv2d(128, 128, kernel_size=5, stride=2, padding=1),
            nn.BatchNorm2d(128),
            nn.ReLU(),
            nn.Conv2d(128, 64, kernel_size=5, stride=2, padding=1),
            nn.BatchNorm2d(64),
            nn.LeakyReLU(),
        )
self.linearEnc = nn.Sequential(
            nn.Linear(1024, 900),
            nn.LeakyReLU(),
        )

 self.linearDec = nn.Sequential(
            nn.Linear(900, 1024),
            nn.LeakyReLU(),
        )

 self.upscale_conv = nn.Sequential(
            nn.ConvTranspose2d(64,128, kernel_size=3, stride=1, padding=0),
            nn.BatchNorm2d(128),
            nn.ReLU(),
            nn.ConvTranspose2d(128,128, kernel_size=3, stride=2, padding=0),
            nn.BatchNorm2d(128),
            nn.ReLU(),
            nn.ConvTranspose2d(128, 128, kernel_size=3, stride=2, padding=1),
            nn.BatchNorm2d(128),
            nn.LeakyReLU(),
            nn.ConvTranspose2d(128, 64, kernel_size=3, stride=2, padding=1),
            nn.BatchNorm2d(64),
            nn.LeakyReLU(),
            nn.ConvTranspose2d(64, 64, kernel_size=3, stride=2, padding=1),
            nn.BatchNorm2d(64),
            nn.LeakyReLU(),
            nn.Conv2d(64, 3, kernel_size=6, stride=1, padding=2),
            nn.Sigmoid(),
        )
</code></pre>

username: rzp0063
cooked: <p>Hi <a class="mention" href="/u/lauriat">@lauriat</a>, I am getting similar blurry results for segmentation even when using a more complex network.</p>
<p><img src="https://discuss.pytorch.org/uploads/default/original/3X/4/c/4cc8e989bda7259f26a083385ee9134c123af90b.png" alt="pytorch_forum_Segmentation" data-base62-sha1="aXgJTDQUANTSU88b6Xdcr4xSPDJ" width="213" height="412"></p>
<p>Is your prediction target only 3 channels (RGB)?. I initially tried the same approach where each of the 3 channels to predict were the original RGB channels and I think this might be one of the main reasons why. Loss function  BCELoss for segmentation expects each channel to be either 0 or 1 (binary) where 1 will be the location of the specific class or color in your case in the image, however, rgb images will contain values from 0 to 1 including fractions at each pixel in the image. I am now trying a different approach by breaking/splitting the image into multiple channels where each will represent a specific color to use these as prediction target. I have not yet obtained results but will notify you if I make some progress.</p>