1. Manual Seed
A manual seed is used to control randomness in a machine learning program so that
the results can be reproduced more consistently.
In my code, I used:
SEED = 42
torch.manual_seed(SEED)
torch.cuda.manual_seed_all(SEED)
I also used the same seed for Python's random and NumPy.
This is useful because things like data shuffling, weight initialization, and some other
operations can involve randomness. Using the same seed helps us get consistent
results when running the experiment again.
So, the main purpose of a manual seed is reproducibility.
2. Gradient Descent
Gradient descent is an optimization method used to reduce the loss of a machine
learning model.
During training, the model makes a prediction and the loss function tells us how
wrong that prediction is. Gradient descent uses the gradient of the loss to determine
how the model's weights should be changed to reduce the loss.
The basic idea is:
Prediction → Loss → Gradient → Update Weights → Repeat
The learning rate controls how large each update is.
In my code, I used the Adam optimizer:
optimizer = optim.Adam(...)
Adam is a gradient-based optimizer. The line:
loss.backward()
calculates the gradients, and:
optimizer.step()
updates the model's weights using those gradients.
So, gradient descent is the basic idea of minimizing the loss by updating model
parameters, while Adam is a specific optimizer that performs these updates using
gradients.
3. PyTorch
PyTorch is a deep learning framework used to build and train neural networks.
It provides tools for:
Working with tensors
Using GPUs
Building neural networks
Calculating gradients
Defining loss functions
Optimizing model parameters
In my code, I used PyTorch for the model training process, including the loss
function, Adam optimizer, gradients, and moving data/model to the GPU.
For example:
loss.backward()
optimizer.step()
are PyTorch operations used during training.
4. Torchvision
Torchvision is a library built on PyTorch that provides tools specifically for computer
vision.
In my code, I used it for three main things:
Datasets:
datasets.ImageFolder(...)
This loads images arranged in folders according to their classes.
Transforms:
transforms.Resize(...)
transforms.RandomHorizontalFlip(...)
transforms.ToTensor()
transforms.Normalize(...)
These are used for image preprocessing and augmentation.
Models:
models.efficientnet_b0(...)
I used Torchvision's pretrained EfficientNet-B0 model and modified its final classifier
for my two classes.
So, in simple terms:
PyTorch → general deep learning framework
Torchvision → computer-vision tools built around PyTorch