0
0
TensorFlowml~12 mins

Flatten and Dense layers in TensorFlow - Model Pipeline Trace

Choose your learning style9 modes available
Model Pipeline - Flatten and Dense layers

This pipeline shows how a simple neural network uses Flatten and Dense layers to learn from image data. The Flatten layer changes the image from a grid of pixels into a list of numbers. Then, Dense layers learn patterns from this list to make predictions.

Data Flow - 4 Stages
1Input Image
1000 rows x 28 x 28 pixelsRaw grayscale images of handwritten digits1000 rows x 28 x 28 pixels
A 28x28 pixel image of digit '7'
2Flatten Layer
1000 rows x 28 x 28 pixelsConvert 2D image pixels into 1D list1000 rows x 784 columns
Image pixels reshaped into a list of 784 numbers
3Dense Layer 1
1000 rows x 784 columnsFully connected layer with 128 neurons and ReLU activation1000 rows x 128 columns
128 features representing learned patterns
4Dense Layer 2 (Output)
1000 rows x 128 columnsFully connected layer with 10 neurons and softmax activation1000 rows x 10 columns
Probabilities for digits 0 to 9
Training Trace - Epoch by Epoch
Loss
1.2 |****
0.8 |***
0.5 |**
0.35|*
0.25| 
     1  2  3  4  5  Epochs
EpochLoss ↓Accuracy ↑Observation
11.20.55Model starts learning, accuracy above random guess
20.80.75Loss decreases, accuracy improves significantly
30.50.85Model learns important features, accuracy rises
40.350.90Loss continues to drop, model becomes confident
50.250.93Training converges with high accuracy
Prediction Trace - 4 Layers
Layer 1: Input Image
Layer 2: Flatten Layer
Layer 3: Dense Layer 1 (128 neurons, ReLU)
Layer 4: Dense Layer 2 (10 neurons, Softmax)
Model Quiz - 3 Questions
Test your understanding
What does the Flatten layer do to the input image?
AReduces the image size by half
BChanges the 2D image into a 1D list of pixels
CAdds color channels to the image
DNormalizes pixel values between 0 and 1
Key Insight
Flatten layers prepare image data for Dense layers by turning 2D pixels into a 1D list. Dense layers then learn patterns from this list to classify images. Watching loss decrease and accuracy increase shows the model is learning well.