Search code examples
machine-learningcomputer-visionconvolutionautoencodermxnet

Is there any toy example of building convolutional autoencoders using MxNet?


I'm looking for implementations of convolutional autoencoder using MxNet. But there is only one example of autoencoder based on Fully Connected Networks, which is here. There is also an issue asking similar questions in github, but receives very few responses. Is there any toy example of convolutional autoencoders implemented using MxNet?


Solution

  • Please find an example of Conv Autoencoder model in Mxnet Gluon. Code quoted from here. Training this model in a standard way in Gluon.

    from mxnet import gluon as g
    
    class CNNAutoencoder(g.nn.HybridBlock):
        def __init__(self):
            super(CNNAutoencoder, self).__init__()
            with self.name_scope():
                self.encoder = g.nn.HybridSequential('encoder_')
                with self.encoder.name_scope():
                    self.encoder.add(g.nn.Conv2D(16, 3, strides=3, padding=1, activation='relu'))
                    self.encoder.add(g.nn.MaxPool2D(2, 2))
                    self.encoder.add(g.nn.Conv2D(8, 3, strides=2, padding=1, activation='relu'))
                    self.encoder.add(g.nn.MaxPool2D(2, 1))
    
                self.decoder = g.nn.HybridSequential('decoder_')
                with self.decoder.name_scope():
                    self.decoder.add(g.nn.Conv2DTranspose(16, 3, strides=2, activation='relu'))
                    self.decoder.add(g.nn.Conv2DTranspose(8, 5, strides=3, padding=1, activation='relu'))
                    self.decoder.add(g.nn.Conv2DTranspose(1, 2, strides=2, padding=1, activation='tanh'))
    
        def forward(self, x):
            x = self.encoder(x)
            x = self.decoder(x)
            return x
    
    model = CNNAutoencoder()
    model.hybridize()