6. Deep Learning: Neural Networks, PyTorch & Computer Vision
Sections 27-31: Artificial Neurons, Activations, Backprop, Keras/TensorFlow, PyTorch Training Loops, CNNs & Transfer Learning
Module 1: Neural Network Fundamentals & Backpropagation
Artificial neurons, activation functions (ReLU, Sigmoid, Softmax), forward passes, and backpropagation.
๐ฌ๐ง English Definition
A neuron computes z = wยทx + b followed by non-linear activation. Backpropagation computes gradients of the loss function with respect to weights using the calculus chain rule.
๐ฎ๐ณ Hinglish Definition
Neuron z = wยทx + b calculate karke activation function pass karta hai. Backpropagation loss function ka gradient chain rule se calculate karke weights update karta hai.
Core Concepts & Principles
- Activation Functions: ReLU max(0,x) for hidden layers; Sigmoid for binary output; Softmax for multi-class probability output.
- Loss Function & Optimizer: Loss measures prediction error; Optimizers (Adam, SGD) update weights using calculated gradients.
๐ Line-by-Line Code Breakdown
- Line 1-2: Define ReLU activation function max(0, x) and Sigmoid activation 1/(1+exp(-x)).
- Line 3-4: Compute forward output z = w @ x + b.
๐ฏ Interview Focus & Questions
- Q: What is Backpropagation?
A: An algorithm that computes the gradient of the loss function with respect to each weight using the chain rule to update neural network parameters.
import numpy as np
def relu(x): return np.maximum(0, x)
def sigmoid(x): return 1 / (1 + np.exp(-x))
x = np.array([1.0, 2.0])
w = np.array([0.4, 0.6])
b = 0.2
z = w @ x + b
print("Neuron Output (ReLU):", relu(z))
Module 2: PyTorch, TensorFlow/Keras & Computer Vision (CNN)
Building neural architectures in PyTorch/Keras and spatial feature extraction with Convolutional Neural Networks.
๐ฌ๐ง English Definition
CNNs (Convolutional Neural Networks) learn spatial feature hierarchies (edges -> textures -> shapes -> objects) using convolution kernels and pooling layers. Transfer Learning reuses pretrained models (ResNet, MobileNet).
๐ฎ๐ณ Hinglish Definition
CNN filters/kernels se image ke spatial patterns (edges, textures, objects) learn karta hai. Transfer learning pretrained ImageNet models ko naye tasks ke liye reuse karta hai.
Core Concepts & Principles
- PyTorch Training Loop Pattern: opt.zero_grad() -> pred = model(X) -> loss = criterion(pred, y) -> loss.backward() -> opt.step()
- CNN Layers: Conv2d (feature extraction), ReLU (non-linearity), MaxPool2d (downsampling spatial resolution).
๐ Line-by-Line Code Breakdown
- Line 1-2: Import torch and torch.nn modules.
- Line 3-6: Define Sequential CNN architecture with Conv2d, ReLU, and MaxPool2d layers.
๐ฏ Interview Focus & Questions
- Q: What is Transfer Learning?
A: Reusing pretrained neural network weights (trained on large datasets like ImageNet) as feature extractors for a new related task.
import torch
import torch.nn as nn
cnn = nn.Sequential(
nn.Conv2d(in_channels=3, out_channels=32, kernel_size=3, padding=1),
nn.ReLU(),
nn.MaxPool2d(2)
)
print("PyTorch CNN Architecture Initialized:", cnn)