Encoder model

To specify the encoder model architecture, we will use the following code:

# Encoder
input_layer <-
layer_input(shape = c(28,28,1))
encoder <- input_layer %>%
layer_conv_2d(filters = 8,
kernel_size = c(3,3),
activation = 'relu',
padding = 'same') %>%
layer_max_pooling_2d(pool_size = c(2,2),
padding = 'same') %>%
layer_conv_2d(filters = 4,
kernel_size = c(3,3),
activation = 'relu',
padding = 'same') %>%
layer_max_pooling_2d(pool_size = c(2,2),
padding = 'same') summary(encoder)
Output
Tensor("max_pooling2d_10/MaxPool:0", shape=(?, 7, 7, 4), dtype=float32)

Here, for the input to the encoder, we specify the input layer so that it's 28 x 28 x 1 in size. Two convolutional layers, one with 8 filters and another with 4 filters, are used. Activation functions for both of these layers use rectified linear units (relus). The convolutional layer includes padding = 'same', which retains the height and width of the input at the time of the output. For example, after the first convolution layer, the output has 28 x 28 as its height and width. Each convolution layer is followed by pooling layers. After the first pooling layer, the height and width change to 14 x 14, and, after the second pooling layer, it changes to 7 x 7. The output of the encoder network in this example is 7 x 7 x 4.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset