>_ Jorge Uc / project details ← ALL PROJECTS
~/projects/facial-recognition / COMPUTER VISION
CUSTOM CNNCELEBATRANSFER LEARNINGSTREAMLIT

Facial Recognition & Attribute Analysis

From a convolutional neural network trained from scratch to personalized face recognition through transfer learning — with an interactive tool for exploring 40 facial attributes.

Streamlit interface displaying a portrait and facial attribute predictions
FACIAL ATTRIBUTE ANALYZER / STREAMLIT40 OUTPUTS
CELEBA IMAGES202,599training dataset
FACIAL ATTRIBUTES40multi-label sigmoid
CNN VAL. BINARY ACC.91.50%attribute labels, not identity
V2 RECALL93.75%binary identity validation
01 / PROJECT CONTEXT

Can a CNN learn facial representations that transfer?

Instead of starting from a generic pretrained architecture, I trained my own feature extractor on a large facial dataset and explored how well those representations adapted to a much smaller identity classification task.

THE STARTING POINT

Learning visual patterns

Predict multiple facial attributes from images, learning useful visual features through supervised multi-label classification.

202,599 IMAGES · 40 LABELS
THE CHALLENGE

Limited personal data

Adapt this visual knowledge to a binary target-person-versus-others task using a much smaller collection of labeled examples.

TRANSFER LEARNING · FINE-TUNING
THE QUESTION

Accuracy versus recall

Investigate how class imbalance and decision thresholds affect the model's willingness to recognize positive examples.

CLASS WEIGHTS · F1 · THRESHOLDS
02 / END-TO-END WORKFLOW

One backbone, three research stages

The three folders in the repository represent successive experiments, not three unrelated systems.

research_pipeline.pyFROM ATTRIBUTES TO IDENTITY
01CelebA dataset128 × 128 RGB; 40 binary labels
02CNN from scratchFeature learning + multi-label prediction
04Transfer v2Class weighting + augmentation
05Evaluation + demoMetrics / thresholds / Streamlit

The public Streamlit demo uses the original 40-attribute CNN, while the personalized recognition experiments are documented separately.

03 / CNN ARCHITECTURE

First, I taught a CNN to describe faces.

The first stage was multi-label representation learning: supervised training on CelebA before any personalized identity task was introduced.

celebA_grande_mejor.h5TENSORFLOW / KERAS
128²RGB inputPixels scaled to [0, 1]
64 → 128Conv blocksEarly feature extraction
256 → 512Conv blocksDeeper facial patterns
GAPPooling + denseCompact representation

Optimized with Adam and binary cross-entropy; the reported 91.50% validation binary accuracy measures attribute-label predictions, not identity recognition.

01 / PIXEL INPUT

RGB image → numerical tensor

Images were resized to 128 × 128 and pixel values normalized to the [0, 1] range. Each sample provides an image and up to 40 independent binary attribute labels.

(128, 128, 3) → normalized RGB
02 / LOCAL FEATURE LEARNING

Convolution + pooling

Four convolutional blocks, with two Conv2D layers per block and MaxPooling2D, progressively learn spatial patterns. The feature depth increases from 64 to 512 filters.

64 → 128 → 256 → 512 filters
03 / ATTRIBUTE PREDICTIONS

Pooling → dense → sigmoid

Global average pooling summarizes feature maps; dropout and dense layers transform that representation into 40 sigmoid scores. Each score is independent, so several labels can be active at once.

GAP → Dense(256) → Dense(128) → Dense(40)
WHY MULTI-LABEL TRAINING?

Features learned for one problem can support another

During CelebA training, the network learned filters useful for describing facial patterns instead of memorizing an identity label. The research hypothesis was that those filters could provide a useful initialization for recognizing one target person with far fewer examples.

The checkpoint achieved 91.50% validation binary accuracy on the attribute task. This is the mean correctness of binary attribute predictions, not facial recognition accuracy. The model uses sigmoid outputs and binary cross-entropy, not a 40-class softmax.

01 / TRAININGFully custom backbone

Learned visual features directly from the annotated CelebA dataset rather than importing pretrained classification weights.

02 / OUTPUTMulti-label classification

One image can exhibit multiple attributes simultaneously. The 40 outputs are not competing softmax classes.

03 / INFERENCEOriginal checkpoint reused

Recovered the trained Keras model and ran it locally with Python 3.13 for a working public demonstration.

transfer_yo.py / model surgeryREUSE FEATURE EXTRACTOR, REPLACE CLASSIFIER
ORIGINAL / CELEBA
128×128×3 RGB input
4 CNN blocks · trained features
Original GAP + dense layers 40 sigmoid attribute outputs · removed for transfer
ADAPTED / BINARY RECOGNITION
128×128×3 RGB input
Same learned CNN backbone Weights transferred from CelebA
New GAP → Dropout(0.5) → Dense(128) → Dropout(0.3) → Sigmoid(1) others = 0 / target = 1

The scripts extract the feature maps immediately before the original GlobalAveragePooling2D and attach a fresh binary head. The pretrained attribute classifier is not reused.

PHASE 01 / FEATURE EXTRACTION

Freeze the CNN; learn the new decision boundary.

The pretrained convolutional backbone is fixed (trainable = False). Only the new classifier head is optimized, initially with Adam at 1×10⁻³.

CNN backbone · frozenNew head · trainable
Configured maximum: 20 epochs; early stopping can end training sooner.
PHASE 02 / FINE-TUNING

Unfreeze deeper features at a lower learning rate.

The backbone is made trainable again, but its first 10 layers remain frozen. Later convolutional layers and the binary head are adapted using Adam at 1×10⁻⁵.

First 10 layers · frozenRemaining backbone + head · trainable
Configured maximum: 10 epochs; training follows early stopping.
WHAT THE MODEL ACTUALLY PREDICTS

Binary target recognition, not general face identification

The final sigmoid returns a score associated with the target-person class. At a chosen threshold, the output is classified as either target (1) or others (0). This experiment does not implement a face detector, face alignment, named multi-person recognition, or anti-spoofing.

04 / REPRESENTATION TRANSFER

Then, I changed the task without starting over.

The personalized experiment is binary verification of a target person's images versus other faces. It does not identify arbitrary people by name.

Important distinction: this experiment performs binary target-person recognition, not open-set identification of arbitrary named individuals. The public demo does not use personal identity checkpoints.

05 / TWO EXPERIMENTAL STRATEGIES

What changed between V1 and V2?

The second version did not introduce a new backbone: it changed the training strategy to address class imbalance and the difficulty of recognizing positive examples.

EXPERIMENT A / V1

Baseline: transfer learning + fine-tuning

A frozen-then-partially-unfrozen CNN using geometric and brightness augmentation, without explicit class weighting in training.

Rotation±30°
Width / height shift0.20
Zoom / shear0.20
Brightness range0.8–1.2
Class weightingNot applied
Decision threshold0.50

Result: high precision, but 5 of 16 target-person validation images were missed.

WHY CLASS WEIGHTS?

Accuracy can hide poor minority-class detection

The evaluation set contained 16 target-person images and 200 other-face images. A model predicting “others” too often could still obtain high overall accuracy. V2 uses class_weight inversely proportional to class frequency, increasing the training cost of errors on the underrepresented class.

class weight(c) = N / (2 × count(c))

Data augmentation introduces transformed training images; it does not create additional independent people. Threshold selection changes how sigmoid scores are converted into class decisions, not the CNN's weights.

06 / EXPERIMENTAL RESULTS

One change in training, a different error profile.

Rather than treating accuracy as the only goal, I compared precision, recall, F1 and the numbers of missed or incorrectly accepted faces on the validation split.

reported_validation_metricsBINARY IDENTITY TASK
MetricTransfer v1Transfer v2
Accuracy97.69%97.22%
Precision100.00%75.00%
Recall68.75%93.75%
F1-score81.48%83.33%
Decision threshold0.500.60

Validation figures from the original report and saved threshold evaluation. The v1 F1-score is derived from the reported confusion matrix; v2 threshold 0.60 was selected on validation data.

KEY INSIGHTHigher recall came with more false positives.

V1 correctly classified 11 of 16 positive validation images with no false positives among 200 negatives. V2 recognized 15 of 16 positives but also misclassified 5 negatives as positive.

RECALL / V168.75%
RECALL / V293.75%
V1 / THRESHOLD 0.50

Confusion matrix · 216 images

COLUMNS: PREDICTED CLASS
ACTUAL ↓
OTHER
TARGET
OTHER
200TN
0FP
TARGET
5FN
11TP

All 200 other faces were rejected, but five actual target images were missed.

V2 / THRESHOLD 0.60

Confusion matrix · 216 images

COLUMNS: PREDICTED CLASS
ACTUAL ↓
OTHER
TARGET
OTHER
195TN
5FP
TARGET
1FN
15TP

More target faces were recognized, but five other faces were incorrectly accepted.

V2 / THRESHOLD SWEEP

Finding a decision threshold

The saved evaluation compared thresholds from 0.10 to 0.90. The reported F1 peak (83.33%) occurred at 0.60 and 0.70. The report uses 0.60.

These are validation-selected thresholds, not results on a separate untouched test set.

Saved experiment plot comparing precision, recall and F1 across thresholds
Original chart from Transfer Learning v2 / curvas_umbrales.png.
READING THE METRICS

Precision answers “who was accepted?”; recall answers “who was missed?”

Precision

Of the faces classified as the target, what fraction really belonged to the target?

Recall

Of all true target images, what fraction did the model recognize?

F1-score

Harmonic mean of precision and recall, useful for viewing their tradeoff under class imbalance.

The two experiments were evaluated on validation data; these values are not evidence of production readiness or spoof-resistant authentication.

07 / INTERACTIVE DEMONSTRATION

Facial Attribute Analyzer

A usable interface for exploring what the original 40-output CNN learned — without exposing personalized identity recognition models.

STREAMLIT / PYTHON 3.13 / TENSORFLOW

Explore the model, one image at a time.

Upload a single portrait to inspect the model's 40 facial attribute scores, browse prediction categories, change the decision threshold and export results as JSON.

This demonstration runs locally using the original CNN weights. The GitHub repository provides the application code and startup instructions.

VIEW DEMO ON GITHUB ↗
Screenshot of the Streamlit Facial Attribute Analyzer interface
SCREENSHOT / THE PUBLIC DEMONSTRATION PREDICTS ATTRIBUTES, NOT IDENTITY
UPLOADSingle portrait analysis

Upload a JPEG or PNG image and inspect the normalized CNN input pipeline.

EXPLORE40 scores + threshold

Rank attributes, group them by category, and adjust the display threshold.

EXPORTMachine-readable JSON

Download model outputs to inspect scores or reuse the results in further analysis.

08 / LIMITATIONS & RESPONSIBLE USE

Understanding what the results do not prove

Facial-analysis models can be sensitive to dataset bias, preprocessing choices, and the difference between validation performance and real-world reliability.

DATA & GENERALIZATION

Limited external validation

The identity-classification metrics were calculated on validation data. V2's decision threshold was also selected on validation, and an untouched independent test set was not documented.

PREPROCESSING

No automatic face alignment

The public demo resizes the supplied image to 128 × 128 RGB and normalizes pixels. It does not automatically locate, crop, or align faces, so framing matters.

DATASET LABELS

Labels are not objective facts

Attributes such as “Attractive,” “Male,” and “Young” are CelebA annotations rather than verified facts about a person; high sigmoid scores are not calibrated guarantees.

SECURITY & PRIVACY

Research prototype only

No presentation-attack detection, demographic fairness audit or production authentication security evaluation is documented. Personal training photographs are not included in the public demo.

Important: The report and scripts support the architecture and validation results above. The original CSV column order, complete identity dataset provenance, and a truly independent identity test set are not available in the preserved files. These should not be assumed.

09 / WHAT I LEARNED

Beyond training a classifier

The biggest lessons came from comparing training strategies, understanding metric tradeoffs, and recovering a research model as a usable tool.

01 / REPRESENTATION LEARNING

Designing CNNs from scratch

I learned how a multi-label training objective can build a transferable feature representation through progressively deeper convolutional blocks.

02 / TRANSFER LEARNING

Adapting to small datasets

Replacing the classifier, freezing the backbone, and fine-tuning selected layers demonstrated how a learned representation can support a new prediction task.

03 / EVALUATION

Looking beyond accuracy

Class imbalance made precision, recall, F1 and threshold selection more informative than headline accuracy alone.

04 / MODEL DELIVERY

Turning research into a demo

I recovered and loaded a saved Keras checkpoint, reproduced preprocessing, and exposed the 40 CNN outputs through a Streamlit application and a Python CLI.

10 / SOURCE & DOCUMENTATION

Explore the implementation

Training scripts, the original research report, experiment metrics and the public attribute-analysis demo are organized in the repository.

REPOSITORY

Source code & experiments

Architecture, training scripts, saved evaluation outputs and demo implementation.

OPEN GITHUB ↗
RESEARCH NOTEBOOK

Original technical report

Training methodology, evaluation and experiment discussion in the original notebook.

VIEW REPORT ↗
Expanded screenshot of Facial Attribute Analyzer