This assignment focuses on building and training a Convolutional Neural Network (CNN) using the ResNet18 architecture for gender classification. The dataset contains facial images of males and females, structured into separate folders. The core objective was to implement a complete deep learning pipeline using PyTorch to classify images into two gender categories:
- Male →
0 - Female →
1
- URL: Kaggle - Adience Gender Dataset
- Contains face images divided into
'm'and'f'directories.
Installed the following Python libraries:
torchtorchvisionmatplotlibopencv-pythonPillow
- Mounted Google Drive to Google Colab for file access.
- Extracted the dataset archive to a working directory.
- Verified existence of gender-labeled folders:
'm'and'f'.
- Created
GenderDatasetclass extendingtorch.utils.data.Dataset. - Mapped:
'm'→ label0'f'→ label1
- Applied image transformations:
- Resizing
- Normalization
- Augmentation using
torchvision.transforms
- Split dataset:
- 80% Training
- 10% Validation
- 10% Testing
- Used
torch.utils.data.DataLoaderfor efficient batching and shuffling.
- Loaded a pre-trained ResNet18 model from
torchvision.models. - Replaced the final fully connected layer to output 2 classes for gender classification.
- Trained for 10 epochs.
- Used:
- Loss Function:
CrossEntropyLoss - Optimizer:
Adam
- Loss Function:
- Tracked:
- Training loss
- Training accuracy
- Validation loss
- Validation accuracy
- Evaluated the model on the test dataset.
- Achieved a test accuracy of approximately 82.35%.
- Observed consistent accuracy improvements across epochs.
- Noted improved generalization due to data augmentation.
- Validation accuracy remained stable, suggesting no significant overfitting.
Test Accuracy: ~82.35%
- Google Colab
- PyTorch
- torchvision
- OpenCV
- matplotlib
- Pillow
Priteesh Madhav Reddy
Date: April 2025