To demonstrate how simple, yet efficient, these models can be, we will opt for a shallow, fully connected architecture, which we will implement with Keras:
inputs = Input(shape=[img_height * img_width])
# Encoding layers:
enc_1 = Dense(128, activation='relu')(inputs)
code = Dense(64, activation='relu')(enc_1)
# Decoding layers:
dec_1 = Dense(64, activation='relu')(code)
preds = Dense(128, activation='sigmoid')(dec_1)
autoencoder = Model(inputs, preds)
# Training:
autoencoder.compile(loss='binary_crossentropy')
autoencoder.fit(x_train, x_train) # x_train as inputs and targets
We have highlighted here the usual symmetrical architecture of encoders-decoders, with their lower-dimensional bottleneck. To train our AE, we use the images (x_train) both as inputs and as targets. Once trained, this simple model can be used to embed datasets, as shown in Figure 6-1.
We opted for sigmoid as the last activation function,...