3
$\begingroup$

I'm having a problem to understand the needed dimensions of an VAE, especially for mu, logvar and z layer.

Let's say I have an input of 512x512, 1 color channel (CT images), batch size 32. Then my encoder/decoder looks like the following:

self.encoder = nn.Sequential(
            nn.Conv2d(1, 32, kernel_size=3, stride=1, padding=1),  # 32x512x512
            nn.ReLU(True),
            nn.Conv2d(32, 32, kernel_size=3, stride=2, padding=1),  # 32x256x256
            nn.ReLU(True),
            nn.Conv2d(32, 32, kernel_size=3, stride=2, padding=1),  # 32x128x128
            nn.ReLU(True),
            nn.Conv2d(32, 32, kernel_size=3, stride=2, padding=1),  # 32x64x64
            nn.ReLU(True),
            nn.Conv2d(32, 32, kernel_size=3, stride=2, padding=1),  # 32x32x32
            nn.ReLU(True))

self.decoder = nn.Sequential(
            nn.ConvTranspose2d(32, 32, kernel_size=4, stride=2, padding=1),
            nn.ReLU(True),
            nn.ConvTranspose2d(32, 32, kernel_size=4, stride=2, padding=1),
            nn.ReLU(True),
            nn.ConvTranspose2d(32, 32, kernel_size=4, stride=2, padding=1),
            nn.ReLU(True),
            nn.ConvTranspose2d(32, 32, kernel_size=3, stride=1, padding=1),
            nn.ReLU(True),
            nn.ConvTranspose2d(32, 1, kernel_size=4, stride=2, padding=1),
            nn.Sigmoid())

What is the correct dimension of mu/logvar and z? latent_dim = 1000, filter_depth=32

I'm not sure if the input of the linear layer mu/logvar is right or not ?

mu = nn.Linear(self.filter_depth * 32 * 32, self.latent_dim)
logvar = nn.Linear(self.filter_depth * 32 * 32, self.latent_dim)
z = nn.Linear(self.latent_dim, self.filter_depth * 32 * 32)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.