Skip to content

Circuit-Overtime/CNN_Facecom

Repository files navigation

🧠 CNN COMSYS Hackathon

A robust deep learning pipeline for gender classification and face verification under challenging, real-world conditions, inspired by Vedic principles of fairness and accuracy.

Elixpo_Generated (2)


All the submission files are under PROUDUCTION and the two Releases with tags publish101 and publish102.

πŸ“‚ Repository Structure

CNN_vedic/
β”œβ”€β”€ PRODUCTION/
β”‚   β”œβ”€β”€ Task_A/               # Gender classification (VGG19-based)
β”‚   β”‚   β”œβ”€β”€ training/         # Training scripts, logs, plots
β”‚   β”‚   β”œβ”€β”€ inference/        # Inference & Grad-CAM scripts
β”‚   β”‚   └── test/             # Test images for inference
β”‚   β”œβ”€β”€ Task_B/               # Face verification (Triplet Network)
β”‚   β”‚   β”œβ”€β”€ training/         # Triplet model training, embedding extraction
β”‚   β”‚   β”œβ”€β”€ inference/        # Face matching demo
β”‚   β”‚   └── test/             # Test/reference images for verification
β”œβ”€β”€ [DEPRECATED MODELS]/      # Old/experimental models & scripts
β”œβ”€β”€ Data/                     # (Git-ignored) Training/validation/test data
β”œβ”€β”€ TASK.md                   # Challenge description & dataset structure
└── README.md                 # (You are here)
β”œβ”€β”€ app/                      # Contains the server.py for the flask server inference
β”œβ”€β”€ index.html                # frontend entry to check inference using a GUI

πŸš€ Project Overview

This project addresses two core computer vision tasks:

Task A: Gender Classification

  • Goal: Predict gender (male/female) from face images, even in poor lighting or weather.
  • Approach: Fine-tuned VGG19 with focal loss, heavy augmentation, and class balancing.
  • Key Features:
    • Handles class imbalance (more male images than female).
    • Auto-threshold tuning for optimal F1 score.
    • Grad-CAM for model explainability.
    • Visual Explainability: Uses Grad-CAM to highlight which regions of the face the model focuses on to determine gender, displaying a heatmap overlay. See PRODUCTION/Task_A/inference/inference_vgg19_updated.py for implementation details.
  • Relevant Files:
    • PRODUCTION/Task_A/training/train_vgg19_updated.py β€” Full training pipeline.
    • PRODUCTION/Task_A/inference/inference_vgg19_updated.py β€” Inference & Grad-CAM.

    Put the model in this folder from the link:
    vgg19_final_epoch

    • PRODUCTION/models/vgg19_final_epoch.h5 β€” Final model weights.
    • PRODUCTION/Task_A/training/vgg19_training_logs.txt β€” Training/evaluation logs.

Task B: Face Matching (Verification)

  • Goal: Match distorted face images to correct identity using embeddings (not classification).

  • Approach: Triplet Network with ResNet50 backbone, trained to minimize intra-class and maximize inter-class distances.

  • Key Features:

    • Embedding extraction for similarity-based matching.
    • Automatic threshold tuning for best accuracy.
  • Relevant Files:

    • PRODUCTION/Task_B/training/tripletNetwork_updated.py β€” Triplet training pipeline.
    • PRODUCTION/Task_B/training/embedding_model_extract.py β€” Extracts embedding submodel.
    • PRODUCTION/Task_B/inference/verify_face.py β€” Face verification demo.

    Put the model in this folder from the link

    Note: You only need the embedding_sequel.h5 model from here: embedding_sequel.h5

    • PRODUCTION/models/tripletNetwork.h5 β€” Full triplet model.
    • PRODUCTION/models/embedding_sequel.h5 β€” Embedding-only model.
    • PRODUCTION/Task_B/training/tripletTrainingLogs.txt β€” Training/evaluation logs.

πŸ“ Folder Details

PRODUCTION/

  • Task_A/: All scripts, logs, and models for gender classification.
    • training/: Training code, logs, and plots.
    • inference/: Inference script with Grad-CAM visualization.
  • Task_B/: All scripts, logs, and models for face verification.
    • training/: Triplet network training, embedding extraction.
    • inference/: Face verification demo using embeddings.
  • models/: Final production models (.h5), ready for inference.

[DEPRECATED MODELS]/

  • Contains experimental, ablation, and legacy models/scripts (Keras, PyTorch, EfficientNet, etc.).
  • Not for production use; see README.md inside for details.

Data/

  • Not included in repo (see .gitignore).
  • Structure for Task A and Task B as described in Task.md.

Task.md

  • Full challenge description, dataset structure, and objectives for both tasks.

πŸ—οΈ How to Use

1. Gender Classification (Task A)

  • Train:
    Run PRODUCTION/Task_A/training/train_vgg19_updated.py (requires data in Data/Task_A/).
  • Inference:
    Place test image in PRODUCTION/Task_A/test/, run PRODUCTION/Task_B/inference/inference_vgg19_updated.py.
  • Model:
    Download vgg19_final_epoch.h5 from releases.

2. Face Verification (Task B)

  • Train:
    Run PRODUCTION/Task_B/training/tripletNetwork_updated.py (requires data in Data/Task_B/).
  • Extract Embedding Model:
    Run embedding_model_extract.py after training.
  • Inference:
    Place reference/test images, run PRODUCTION/Task_B/inference/verify_face.py.
  • Model:
    Download embedding_sequel.h5 from releases.

πŸ“ Key Features

  • Class Imbalance Handling:
    Automatic class weights and focal loss for fair gender classification.
  • Data Augmentation:
    Robust to real-world distortions (rotation, brightness, etc.).
  • Auto Threshold Tuning:
    Finds best probability/distance threshold for optimal F1/accuracy.
  • Explainability:
    Grad-CAM visualizations for gender model, showing which parts of the face are being scanned to determine gender using a heatmap.
  • Production-Ready:
    All production models and scripts are in PRODUCTION/.

πŸ“ˆ GRAD-CAM Result Showcase (Male and Female)

  • MALE image
  • FEMALE image

πŸ“Š Results


πŸ”§ Development Environment

Component Version
Python 3.10.0
TensorFlow 2.9.0
CUDA Toolkit 11.8
cuDNN 8.6.0
GPU NVIDIA RTX (6GB or higher) recommended

πŸ“¦ Requirements

CPU Environment

Install with:

pip install -r requirements.txt

GPU Environment

Install with:

pip install -r requirements_GPU.txt

OR

conda env create -f facecom_env.yml

Check Runtime File to get detailed steps on 100% reproducable inference smoothly

Ensure CUDA 11.8 and cuDNN 8.6.0 are installed and properly configured for GPU support (only if you are accessing the training scripts)


πŸ“š References

  • See Task.md for dataset structure and challenge details.
  • Model weights and releases:
    GitHub Releases

🀝 Acknowledgements

Developed by Circuit-Overtime and contributors.
For academic/educational use only.