Noel Jeffrey Pinton
Department of Computer Science
University of the Philippines Cebu
Noel Jeffrey Pinton
Department of Computer Science
University of the Philippines Cebu
By the end of this module, you will be able to:
From perceptron to deep networks
Perceptron:
$$y = \sigma\left(\sum_{i=1}^{n} w_i x_i + b\right)$$
Weighted sum of inputs + bias, passed through activation function
$$\sigma(x) = \frac{1}{1+e^{-x}}$$
$$f(x) = \max(0, x)$$
Why is ReLU preferred over sigmoid in deep networks?
ReLU helps avoid the vanishing gradient problem (sigmoid gradients become very small for large inputs). ReLU also computes faster and introduces sparsity. However, it can cause 'dead neurons' if inputs are always negative.
Click the blurred area to reveal the answer
MLP: Multiple layers of neurons connected in sequence.
Learning from data
$$L = \frac{1}{n}\sum(y - \hat{y})^2$$
$$L = -\sum y \log(\hat{y})$$
Parameter Update:
$$w = w - \eta \frac{\partial L}{\partial w}$$
η = learning rate. Move in direction that reduces loss.
What happens if the learning rate is too large or too small?
Too large: oscillates around minimum or diverges. Too small: very slow convergence, may get stuck in local minima. Finding the right learning rate (or using adaptive methods like Adam) is crucial.
Click the blurred area to reveal the answer
Overfitting: Model memorizes training data but fails on new data.
Solutions: Regularization (L1/L2), dropout, early stopping, data augmentation, more data.
Designed for image data
What are the benefits of pooling layers?
1) Reduces spatial dimensions (computational efficiency), 2) Provides translation invariance (small shifts don't change output), 3) Increases receptive field of subsequent layers, 4) Helps prevent overfitting by reducing parameters.
Click the blurred area to reveal the answer
Typical CNN:
Input → [Conv → ReLU → Pool] × N → Flatten → FC → Output
Early layers: edges, textures. Deeper layers: complex patterns, objects.
Getting your data ready
Essential steps:
Augmentation: Artificially expand training set by applying transformations.
End-to-end image classification with a CNN
import torch
import torch.nn as nn
class SimpleCNN(nn.Module):
def __init__(self, num_classes=10):
super().__init__()
self.features = nn.Sequential(
nn.Conv2d(3, 32, kernel_size=3, padding=1),
nn.ReLU(),
nn.MaxPool2d(2, 2),
nn.Conv2d(32, 64, kernel_size=3, padding=1),
nn.ReLU(),
nn.MaxPool2d(2, 2)
)
self.classifier = nn.Sequential(
nn.Flatten(),
nn.Linear(64 * 8 * 8, 128),
nn.ReLU(),
nn.Linear(128, num_classes)
)
Key Takeaways
Thank you for your attention!
Next: Module 10 - Computer Vision & Deep Learning II
Questions?