Skip to content

Hammazb/Using-CNN-to-Classify-Ethnicity-Pytorch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 

Repository files navigation

🧠 UTKFace Ethnicity Classification with CNN (PyTorch)

This project focuses on building a Convolutional Neural Network (CNN) using PyTorch to classify facial images into 5 ethnicity categories using the UTKFace dataset. The model is trained on image data with labels extracted directly from the filenames.


πŸ“‚ Dataset: UTKFace

Ethnicity Classes:

  • 0 β†’ White
  • 1 β†’ Black
  • 2 β†’ Asian
  • 3 β†’ Indian
  • 4 β†’ Others

πŸ’‘ Project Objective

To train a CNN to accurately predict the ethnicity of individuals from facial images using:

  • Data preprocessing & balancing
  • Custom PyTorch Dataset class
  • Weighted random sampling for fair training
  • Visualization of predictions and performance metrics

πŸ—οΈ Architecture

  • 3 Convolutional Layers (Conv2D + ReLU + MaxPooling)
  • Flatten β†’ Fully Connected Layers
  • Dropout Layer (0.5) to reduce overfitting
  • Final Linear Layer with 5 output classes

πŸ§ͺ Evaluation

  • Training loss and accuracy over 30 epochs
  • Confusion matrix heatmap for test predictions
  • Visual examples: Correct vs Incorrect predictions by ethnicity
  • Classification report with precision, recall, F1-score

πŸ”§ Setup Instructions

# Clone the repository
git clone https://github.com/yourusername/utkface-ethnicity-cnn.git
cd utkface-ethnicity-cnn

# Install dependencies
pip install -r requirements.txt

# Download UTKFace dataset and place inside /data/UTKFace

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors