About the shape of the decoder


(oasjd7) #1

My encoder shape is like (Conv layers → FC layer)
I want to construct decoder corresponding this encoder and use sigmoid() as the output.
The shape of this decoder will be (FC layer → Conv). then how can I apply sigmoid after convolutional layer?

class Encoder(nn.Module):
    def __init__(self, dim):
        super(Encoder, self).__init__()

        self.extractor1 = nn.Sequential(
            nn.Conv2d(in_channels=1, out_channels=64, kernel_size=5, stride=1, padding=2),
            nn.BatchNorm2d(64),
            nn.ReLU(True),
            nn.MaxPool2d(kernel_size=2),

            nn.Conv2d(in_channels=64, out_channels=128, kernel_size=5, stride=1, padding=0),
            nn.BatchNorm2d(128),
            nn.ReLU(True),
            nn.MaxPool2d(kernel_size=2),

            nn.Conv2d(in_channels=128, out_channels=256, kernel_size=5, stride=1, padding=0),
            nn.ReLU(True),
        )
        self.extractor2 = nn.Sequential(
            nn.Linear(256, dim),
        )

    def forward(self, x):
        x = self.extractor1(x)
        x = x.view(batch_size, -1)
        x = self.extractor2(x)
        return x

(Arul) #2

Sigmoid is just an activation function and it can be applied after conv layer as well.