1 / 8

๐Ÿง  Neural Network Training

Understanding Epochs, Batches & More

๐ŸŽฏ

Master the fundamental concepts of training neural networks and CNNs

๐Ÿ’ก Learning Objective: By the end of this presentation, you'll understand how neural networks learn through epochs, batches, and iterations!

๐Ÿ“Š What is Training Data?

Training data is the dataset used to teach your neural network.

๐Ÿฑ
๐Ÿถ
๐Ÿฑ
๐Ÿถ
๐Ÿฑ
๐Ÿถ
๐Ÿฑ
๐Ÿถ

Example: 1000 images of cats and dogs

๐Ÿ“ฆ What is a Batch?

A batch is a subset of training data processed together.

Batch 1 (size=4)
1
2
3
4
Batch 2 (size=4)
5
6
7
8
Total Data = 1000 images
Batch Size = 32
Number of Batches = 1000 รท 32 = ~31 batches

๐Ÿ”„ What is an Iteration?

One iteration = Processing one batch through the network

Batch
1
2
3
4
โ†’
Neural Network
โ†’
๐Ÿ“ˆ Update Weights
1 Iteration = Forward Pass + Backward Pass + Weight Update

๐ŸŒ What is an Epoch?

One epoch = The network has seen ALL training data once

Epoch 1 Complete!
Batch 1
1-32
Batch 2
33-64
...
...
Batch 31
969-1000

โš–๏ธ Batch Size Trade-offs

Aspect Small Batches (8-16) Medium Batches (32-64) Large Batches (128+)
Memory Usage โœ… Low โšก Moderate โŒ High
Training Speed โŒ Slower โšก Balanced โœ… Faster
Gradient Quality โŒ Noisy โšก Good โœ… Smooth
Generalization โœ… Better โšก Good โŒ May overfit
๐Ÿ’ก Sweet Spot: Batch sizes of 32-64 often work best for most problems!

๐Ÿ–ผ๏ธ CNN Training Specifics

Conv Layer
Pool Layer
Conv Layer
Dense Layer
CNN Batch Shape: [batch_size, height, width, channels]
Example: [32, 224, 224, 3] = 32 color images of 224ร—224 pixels

๐Ÿ”€ Do We Create New Batches Each Epoch?

Great Question! It Depends...

โœ… WITH Shuffling (Recommended)

Epoch 1: [A,B,C,D] [E,F,G,H] [I,J,K,L]
Epoch 2: [C,A,I,F] [B,L,E,D] [G,K,H,J]
Epoch 3: [J,B,A,K] [I,C,F,L] [H,D,E,G]

โ†’ Better learning, avoids patterns

โŒ WITHOUT Shuffling

Epoch 1: [A,B,C,D] [E,F,G,H] [I,J,K,L]
Epoch 2: [A,B,C,D] [E,F,G,H] [I,J,K,L]
Epoch 3: [A,B,C,D] [E,F,G,H] [I,J,K,L]

โ†’ May memorize order, poor learning

๐Ÿ’ก Best Practice: Always shuffle your training data between epochs (unless working with sequential data like time series or text)!

๐ŸŽฏ Complete Training Process

Step 1: Load your dataset (e.g., 10,000 images)
Step 2: Set batch size (e.g., 32)
Step 3: Shuffle data and create batches (313 batches)
Step 4: Train through all batches (1 epoch complete)
Step 5: Shuffle again and repeat for 50 epochs
Result: 313 iterations ร— 50 epochs = 15,650 updates!
for epoch in range(50):
    shuffle(training_data) # ๐Ÿ”€ Key step!
    create_batches(batch_size=32)
    for batch in batches:
        train_on_batch(batch)
๐ŸŽ‰ Congratulations! You now understand the complete training process, including the crucial role of data shuffling between epochs!

ยฉ 2025 Machine Learning for Health Research Course | Prof. Gennady Roshchupkin

Interactive slides designed for enhanced learning experience