A face classification system built with MobileNet (transfer learning), face_recognition for preprocessing, and a Streamlit web interface for real-time inference. The pipeline handles everything from raw image preprocessing and augmentation through model training to deployment via Docker.
The project has two main components:
Training pipeline (face-recog-mobile.py) takes a folder of labeled face images, resizes them to 224×224, validates that each image contains a detectable face (discarding those that don't), splits the data into train/validation/test sets (70/20/10), applies image augmentation (50 augmented copies per training image), and fine-tunes a MobileNet model with a custom classification head. The trained model is saved as face-mobile.h5.
Inference app (app.py) loads the trained model into a Streamlit web app where users can upload an image and get a predicted class label with confidence score.
├── data/ # Raw training images (one subfolder per person/class)
│ ├── person_1/
│ ├── person_2/
│ └── ...
├── processed/ # Auto-generated train/val/test splits + augmented data
├── no-face/ # Images where no face was detected (auto-moved)
├── shells/ # Shell scripts
├── face-recog-mobile.py # Training pipeline
├── app.py # Streamlit inference app
├── face-mobile.h5 # Trained model weights (~16 MB)
├── accuracy_plot.png # Training/validation accuracy over epochs
├── confusion_matrix.png # Test set confusion matrix
├── Dockerfile # Container config for deployment
├── requirements.txt # Python dependencies
└── README.md
- Python 3.9+
dlib(required byface_recognition— may need CMake installed)
git clone <repo-url>
cd face-recog-opencv
pip install -r requirements.txtOrganize your images under the data/ directory with one subfolder per class:
data/
├── alice/
│ ├── img1.jpg
│ ├── img2.jpg
│ └── ...
├── bob/
│ ├── img1.jpg
│ └── ...
Note: The final Dense layer in
face-recog-mobile.pyis set to 6 output units. UpdateDense(6, ...)to match your actual number of classes before training.
python face-recog-mobile.pyThis will:
- Resize all images to 224×224
- Detect and filter out images with no faces (moved to
no-face/) - Split data into train, validation, and test sets
- Generate 50 augmented images per training sample
- Fine-tune MobileNet for 10 epochs
- Save the model to
face-mobile.h5 - Output
accuracy_plot.pngandconfusion_matrix.png
streamlit run app.pyOpen http://localhost:8501 in your browser, upload a face image, and get the classification result.
docker build -t face-classifier .
docker run -p 8501:8501 face-classifierThe model uses MobileNet pretrained on ImageNet as a frozen feature extractor, with a custom head:
MobileNet (frozen) → GlobalAveragePooling2D → Dense(256, ReLU) → Dense(num_classes, Softmax)
Training uses Adam optimizer with categorical crossentropy loss. Image augmentation includes rotation, shifts, shear, zoom, and horizontal flips.
| Package | Purpose |
|---|---|
tensorflow/keras |
Model training and inference |
face_recognition |
Face detection and validation |
streamlit |
Web interface |
scikit-learn |
Data splitting and evaluation |
matplotlib |
Accuracy plots |
seaborn |
Confusion matrix visualization |
Pillow |
Image loading and resizing |
opencv-python |
Image processing utilities |
See repository for license details.