We train the model to predict both age and gender simultaneously, using the following loss functions:
| Task | Output Type | Loss Function |
|---|---|---|
| Age | Regression | MSELoss (Mean Squared Error) |
| Gender | Binary Classification | BCEWithLogitsLoss |
The age loss (MSE) often has a larger magnitude than the gender loss (BCE), which can make training unstable.
We apply the technique from:
"Multi-Task Learning Using Uncertainty to Weigh Losses for Scene Geometry and Semantics" (Kendall et al.)
The model learns task-specific uncertainty parameters (
Where:
- L_age = Age regression loss (MSE)
- L_gender = Gender classification loss (BCE)
- σ₁, σ₂ = Learned uncertainties (as log-variance)
This allows the model to dynamically balance the contributions of each task based on its uncertainty during training.
# Clone the repository
git clone https://github.com/baduyne/Age-Gender-Prediction-from-Face-Images-using-CNN.git
cd Age-Gender-Prediction-from-Face-Images-using-CNNHow to Run from Command Line You can run the model in two modes:
- Mode 0: Use Webcam:
python executing_model.py --mode 0
# or shorthand
python executing_model.py -m 0- Mode 1: Predict from a Static Image
python executing_model.py --mode 1 --image_path path_to_image.jpg
# or shorthand
python executing_model.py -m 1 -i path_to_image.jpgRequirements Ensure you have the necessary dependencies installed:
pip install -r requirements.txt(づ。◕‿‿◕。)づ Thank you for your interest on my project.