Adding a dense layer after a conv2d layer in a convolutional autoencoder
Hi for me this worked perfectly. I encoded with conv2d and dense and then I flatten I and reshape in the decoder after the dense layer so the encoder and decoder are symmetrical. The only difference is that in my case I use images (224,224,1)
        # create encoder
        # 28,28 -&gt; 1st conv2d (filter 3x3,relu activation, padding, strides == 'jumps')
        self.encoder = tf.keras.Sequential([layers.Input(shape=(224,224,1)),
                                            layers.Conv2D(16,kernel_size=3,activation='relu',padding='same',strides=2),                
                                            layers.Conv2D(8,kernel_size=3,activation='relu',padding='same',strides=2),
                                            layers.Conv2D(4,kernel_size=3,activation='relu',padding='same',strides=2),
                                            layers.Flatten(),
                                            layers.Dense(units=3136,activation='sigmoid')]) # (28,28,4)
        
        # deconvolution -&gt; decoding 
        self.decoder = tf.keras.Sequential([layers.Input(shape=(3136)),
                                            layers.Dense(units=3136,activation='sigmoid'),
                                            layers.Reshape((28,28,4)),
                                            layers.Conv2DTranspose(4,kernel_size=3,activation='relu',padding='same',strides=2),
                                            layers.Conv2DTranspose(8,kernel_size=3,strides=2,activation='relu',padding='same'),
                                            layers.Conv2DTranspose(16,kernel_size=3,strides=2,activation='relu',padding='same'),
                                            layers.Conv2D(1,kernel_size=(3,3),activation='sigmoid',padding='same')])