<jupyter_start><jupyter_text>Convolutional AutoEncoder  Convolutional Encoder<jupyter_code>input_img = Input(shape=(28, 28, 1))  # adapt this if using `channels_first` image data format

x = Conv2D(filters = 16, kernel_size = (3, 3), activation='relu', padding='same')(input_img)
x = MaxPooling2D((2, 2), padding='same')(x)

x = Conv2D(filters =  8, kernel_size = (3, 3), activation='relu', padding='same')(x)
x = MaxPooling2D((2, 2), padding='same')(x)

x = Conv2D(filters =  8, kernel_size = (3, 3), activation='relu', padding='same')(x)
encoded = MaxPooling2D((2, 2), padding='same', name = 'LatentSpace')(x)

# at this point the representation is (4, 4, 8) i.e. 128-dimensional

encoder = Model(input_img, encoded, name='CNN_Encoder')
encoder.summary()<jupyter_output>Model: "CNN_Encoder"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
input_2 (InputLayer)         [(None, 28, 28, 1)]       0         
_________________________________________________________________
conv2d_7 (Conv2D)            (None, 28, 28, 16)        160       
_________________________________________________________________
max_pooling2d_2 (MaxPooling2 (None, 14, 14, 16)        0         
_________________________________________________________________
conv2d_8 (Conv2D)            (None, 14, 14, 8)         1160      
_________________________________________________________________
max_pooling2d_3 (MaxPooling2 (None, 7, 7, 8)           0         
_________________________________________________________________
conv2d_9 (Conv2D)            (None, 7, 7, 8)           584       
_______________________________________________________[...]<jupyter_text>Convolutional Decoder<jupyter_code>latent_space = Input(shape=(4, 4, 8))  # adapt this if using `channels_first` image data format

# at this point the representation is (4, 4, 8) i.e. 128-dimensional

x = Conv2D(filters = 8, kernel_size = (3, 3), activation='relu', padding='same')(latent_space)
x = UpSampling2D((2, 2))(x)
x = Conv2D(filters = 8, kernel_size = (3, 3), activation='relu', padding='same')(x)
x = UpSampling2D((2, 2))(x)
x = Conv2D(filters = 16, kernel_size = (3, 3), activation='relu')(x)
x = UpSampling2D((2, 2))(x)
decoded = Conv2D(filters = 1, kernel_size = (3, 3), activation='sigmoid', padding='same')(x)

# create the decoder model
decoder = Model(latent_space, decoded, name='CNN_Decoder')
decoder.summary()
autoencoder = Model(input_img, decoder(encoder(input_img)), name="CNN_autoencoder")
autoencoder.summary()
autoencoder.compile(loss='binary_crossentropy', optimizer=tf.keras.optimizers.Adam(lr=0.001))
autoencoder.summary()
# logdir = os.path.join("logs", datetime.datetime.now().strftime("%m%d_%H%M%S"))
# tensorboard_callback = tf.keras.callbacks.TensorBoard(logdir, histogram_freq=1)

# eStop = tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=3, mode='min')

epochs = 2
batch_size = 128

HistoryAE = autoencoder.fit(noise_train_dataset,
                            fm_X_train,
                            epochs = epochs,
                            batch_size = batch_size,
#                             callbacks=[eStop, tensorboard_callback],
                            validation_data = (noise_test_dataset, fm_X_test)
                            )
plt.plot(HistoryAE.history['loss'], label="loss")
plt.plot(HistoryAE.history['val_loss'], label="val_loss")
plt.legend()
plt.show()
Evaluation = autoencoder.evaluate(noise_test_dataset,
                                  fm_X_test,
                                  batch_size=batch_size,
                                  verbose=2)

print('Test Loss: {:.3f}'.format(Evaluation))
predicted = autoencoder.predict(noise_test_dataset[:10])

fig, axes = plt.subplots(nrows=2, ncols=10, sharex=True, sharey=True, figsize=(20,4))
for images, row in zip([noise_test_dataset[:10], predicted], axes):
    for img, ax in zip(images, row):
        ax.imshow(img.reshape((28, 28)), cmap='Greys_r')
        ax.get_xaxis().set_visible(False)
        ax.get_yaxis().set_visible(False)
# %tensorboard --logdir logs --port=6061<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14508506616257089, 'fraction_numerical': 0.036625708884688093, 'mean_word_length': 3.8767281105990783, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '500331', 'license': 'MIT', 'n_tokens_mistral': 1416, 'n_tokens_neox': 1283, 'n_words': 269, 'path': 'CNN_AutoEncoder Tesis.ipynb', 'repo_name': 'kevinpulido89/DeepLearning-en-Vehiculos-de-Emergencia', 'size': '4232'}