Created
November 19, 2019 16:02
-
-
Save AFAgarap/0e71879dfeecbe457d3f783a6fa8fba1 to your computer and use it in GitHub Desktop.
TensorFlow 2.0 implementation of mini VGG-based encoder for an autoencoder.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Encoder(tf.keras.layers.Layer): | |
def __init__(self, **kwargs): | |
super(Encoder, self).__init__() | |
self.input_layer = tf.keras.layers.InputLayer( | |
input_shape=kwargs['input_shape'] | |
) | |
self.conv_1_layer_1 = tf.keras.layers.Conv2D( | |
filters=32, | |
kernel_size=(3, 3), | |
activation=tf.nn.relu | |
) | |
self.conv_1_layer_2 = tf.keras.layers.Conv2D( | |
filters=32, | |
kernel_size=(3, 3), | |
activation=tf.nn.relu | |
) | |
self.conv_2_layer_1 = tf.keras.layers.Conv2D( | |
filters=64, | |
kernel_size=(3, 3), | |
activation=tf.nn.relu | |
) | |
self.conv_2_layer_2 = tf.keras.layers.Conv2D( | |
filters=64, | |
kernel_size=(3, 3), | |
activation=tf.nn.sigmoid | |
) | |
def call(self, features): | |
features = self.input_layer(features) | |
activation = self.conv_1_layer_1(features) | |
activation = self.conv_1_layer_2(activation) | |
activation = self.conv_2_layer_1(activation) | |
code = self.conv_2_layer_2(activation) | |
return code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment