Deeper networks

The code used for experimenting with a deeper network in this section are as follows:

# Model architecture
model <- keras_model_sequential()
model %>%
layer_dense(units = 512, activation = 'relu', input_shape = c(2352)) %>%
layer_dropout(rate = 0.1) %>%
layer_dense(units = 256, activation = 'relu') %>%
layer_dropout(rate = 0.1) %>%
layer_dense(units = 3, activation = 'softmax')
summary(model)

OUTPUT
_______________________________________________________________________
Layer (type) Output Shape Param #
=======================================================================
dense_1 (Dense) (None, 512) 1204736
_______________________________________________________________________
dropout_1 (Dropout) (None, 512) 0
_______________________________________________________________________
dense_2 (Dense) (None, 256) 131328
_______________________________________________________________________
dropout_2 (Dropout) (None, 256) 0
_______________________________________________________________________
dense_3 (Dense) (None, 3) 771
=======================================================================
Total params: 1,336,835
Trainable params: 1,336,835
Non-trainable params: 0
_______________________________________________________________________

# Compile model
model %>% compile(loss = 'categorical_crossentropy',
optimizer = 'adam',
metrics = 'accuracy')

# Fit model
model_two <- model %>% fit(trainx,
trainLabels,
epochs = 30,
batch_size = 32,
validation_data = list(validx, validLabels))
plot(model_two)

From the preceding code, we can see the following:

  • We are increasing the number of units in the first and second hidden layers to 512 and 256 respectively.
  • We are also adding dropout layers after each hidden layer with a 10% dropout rate.
  • The total number of parameters with this change has now gone up to 1336835.
  • This time, we will also run the model for 50 epochs. We do not make any other changes to the model. 

The following graphs provide accuracy and loss values for the training and validation data for 50 epochs:

From the preceding graphs, we can see the following:

  • There are some major changes observed in the accuracy and loss values compared to the earlier model.
  • The accuracy for both the training and validation data after 50 epochs is 100%.
  • In addition, the closeness of the training- and validation-related curves for loss and accuracy indicate that this image-classification model is not likely to suffer from an overfitting problem.
..................Content has been hidden....................

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