module_7_html = """
A neural network consists of layers of interconnected nodes ("neurons"). Each neuron performs a weighted sum of inputs followed by a non-linear activation function like ReLU or Sigmoid.
output = activation(Wx + b)
import torch.nn as nn
class SimpleCNN(nn.Module):
def __init__(self):
super(SimpleCNN, self).__init__()
self.conv1 = nn.Conv2d(1, 32, kernel_size=3)
self.pool = nn.MaxPool2d(2, 2)
self.fc1 = nn.Linear(32 * 13 * 13, 10)
def forward(self, x):
x = self.pool(nn.functional.relu(self.conv1(x)))
x = x.view(-1, 32 * 13 * 13)
x = self.fc1(x)
return x
for epoch in range(epochs):
for inputs, labels in dataloader:
optimizer.zero_grad()
outputs = model(inputs)
loss = criterion(outputs, labels)
loss.backward()
optimizer.step()
Use a pre-trained model like ResNet and fine-tune it for your dataset. Benefits:
Objective: Train a CNN from scratch and compare with transfer learning
Due: End of Week 7