Compiling and fitting the model

Now, we can compile and fit the model using the following code:

# Compile and fit model
ae_model <- keras_model(inputs = input_layer, outputs = decoder)
ae_model %>% compile( loss='mse',
optimizer='adam')
model_three <- ae_model %>% fit(trainx,
trainy,
epochs = 100,
batch_size = 128,
validation_split = 0.2)
plot(model_three)

In the preceding code, we compile the autoencoder model using mean squared error as the loss function and specify adam as the optimizer. We use trainx, which contains images with a black line across them, as input to the model and trainy, which contains clean images, as output that the model tries to match. We specify the number of epochs as 100 and use a batch size of 128. Using a validation split of 0.2 or 20%, we will use 20 images out of 25 for training and 5 images out of 25 for computing validation errors. 

The following graph shows the mean square error for 100 epochs for the training and validation images for model_three:

The plot for the mean square error shows that there is an improvement in model performance based on the training and validation data as the model training proceeds. We can also see that, between about 80 and 100 epochs, the model's performance becomes approximately flat. In addition to this, it's suggested that increasing the number of epochs isn't likely to improve model performance any further.

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

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