5. Deep Learning: AE, TL
A neural network designed to learn an efficient data encoding (compression)
and then reconstruct the input data from that encoding (decompression).
Tip
Core Idea: Learn a compressed, “latent” representation of data without supervision.
The encoder is a neural network that transforms input data into a smaller,
lower-dimensional representation.

The decoder performs the reverse operation of the encoder.

To expand the data in the decoder, we use upsampling techniques.
UpSampling2D: Commonly used in TensorFlow Keras for image data.Combining the encoder and decoder forms an autoencoder.
Important
The autoencoder aims to reconstruct its own input.

Utilize the Keras Model class for flexible architecture.
from tensorflow.keras.layers import Conv2D, MaxPool2D, UpSampling2D, Input
from tensorflow.keras.models import Model
# Define input layer
input_layer = Input(shape=(28, 28, 1), name='input_image')
# Encoder path
conv_layer = Conv2D(32, (3, 3), activation='relu', padding='same')(input_layer)
latent_layer = MaxPool2D((2, 2), padding='same')(conv_layer)
# Define the encoder model
encoder = Model(input_layer, latent_layer, name='encoder')
print(encoder.summary())Note
The latent_layer represents the compressed output of the encoder.
Connect encoder and decoder using the Keras Functional API.
from tensorflow.keras.layers import Conv2D, MaxPool2D, UpSampling2D, Input
from tensorflow.keras.models import Model
# Example placeholder for decoder output (in a real model, this would be built from latent_layer)
# For this example, let's just make a simple decoder structure
latent_input = Input(shape=(14, 14, 32), name='latent_input')
conv_decoder = Conv2D(32, (3, 3), activation='relu', padding='same')(latent_input)
up_sample = UpSampling2D((2, 2))(conv_decoder)
output_layer = Conv2D(1, (3, 3), activation='sigmoid', padding='same')(up_sample) # Assuming 1-channel output like original input
# Define the encoder model (as on previous slide)
input_autoencoder = Input(shape=(28, 28, 1), name='input_image_autoencoder')
encoder_conv = Conv2D(32, (3, 3), activation='relu', padding='same')(input_autoencoder)
latent_encoded = MaxPool2D((2, 2), padding='same')(encoder_conv)
encoder = Model(input_autoencoder, latent_encoded, name='encoder')
# Define the decoder model
decoder = Model(latent_input, output_layer, name='decoder')
# Connect them to form the autoencoder
autoencoder = Model(
input_autoencoder,
decoder(encoder(input_autoencoder)),
name="autoencoder"
)
print(autoencoder.summary())Tip
Training the autoencoder model simultaneously trains both the encoder and decoder sub-models.
Explore how a 2D convolution filter processes an input matrix.
Adjust filter size and visualize the output.
Now it is your turn to apply what you’ve learned about autoencoders.
In the lab, you will work through examples of:
What specific ECE applications do you envision for autoencoders, beyond those discussed?
This project consolidates your knowledge of image classification.
You will apply various techniques learned throughout the course.
Note
Focus on building, evaluating, and tuning models for a real-world medical imaging task.
You will work with a dataset of chest X-ray images.
NORMAL or PNEUMONIA.
flowchart LR
subgraph "Input Image"
A["Pixel Grid"]
end
subgraph "Filter (Kernel)"
B["Small Matrix"]
end
subgraph "Operation"
C(("Slide & Multiply-Add"))
end
subgraph "Output"
D["Feature Map"]
end
A -- "Apply Filter" --> C
B -- "Over Region" --> C
C --> D
style A fill:#cef,stroke:#333,stroke-width:2px
style B fill:#fec,stroke:#333,stroke-width:2px
style C fill:#ccf,stroke:#333,stroke-width:2px
style D fill:#cfc,stroke:#333,stroke-width:2pxThe dataset is pre-organized into standard machine learning splits.
train set: Used for model training.test set: For hyperparameter tuning and model selection.val set: Final, unbiased evaluation of model generalization.What challenges do you anticipate when working with medical image data?
Now, apply your skills to the Image Classification Project.
Good luck building a robust pneumonia detection model!
What strategies will you prioritize for model evaluation and fine-tuning?
Concept: Reusing a pre-trained model as a starting point for a new task.
Important
Why train from scratch when you can stand on the shoulders of giants?
Just as humans learn by building upon existing knowledge,
ML models can benefit from “transferred” insights.

Imagine identifying a zebra:

Typically involves attaching new layers to a pre-trained base model.

The decision to retrain (fine-tune) the pre-trained model’s weights depends on several factors:
When using a pre-trained model, we typically don’t use its final classification layer.

Understanding these terms helps when configuring pre-trained models.
This convention often comes from how models are diagrammed, with input at the bottom and output at the top.

include_top: A Key ParameterMany pre-trained models (e.g., in Keras) offer an include_top parameter.
include_top=True (default): Includes the original classification layers.include_top=False: Excludes the original classification layers.

Now, let’s put transfer learning into practice.
You will use MobileNetV2, a powerful pre-trained model,
to build a network capable of classifying cats and dogs.
What advantages do you expect from using MobileNetV2 compared to training from scratch for this task?