AI face recognition web application development case study

FaceMorph AI: How We Built a Custom Face Recognition Web App for a European Client Using Python, Conda & Deep Learning


AI face recognition application development sits at the intersection of computer vision, deep learning infrastructure, and practical software engineering — and it is rarely as straightforward as tutorials suggest. This case study documents how A Square Solutions built FaceMorph, a custom AI facial recognition and transformation web application for a European client, including the real technical errors we encountered, how we solved them, and what the final system delivers.

1,000

Training images collected from client

GPU

High-performance dedicated training hardware

Real-time

Inference speed achieved post-optimisation

4

Major technical errors resolved

The Client Brief

Benjamin, an Italian musician and digital artist, came to A Square Solutions with a specific and technically demanding brief: build a web application that could recognise and transform faces — specifically trained on his own likeness — for use in creative and promotional contexts. The application needed to be accessible via a web browser, perform transformations in real-time, and maintain visual quality standards appropriate for professional use.

The project required building something that did not exist off the shelf. Generic face swap APIs and consumer tools didn’t meet the specificity or quality bar required. What Benjamin needed was a custom-trained model — one built on his specific facial data, optimised for his use case, and deployed as a stable web application.

We agreed on a three-phase engagement: data collection and preparation, model training and validation, and web application development and deployment. The client would supply 1,000 personal photographs as the training dataset. We would handle everything else.

The Technical Architecture

Training environment: We set up a Conda-managed Python environment on a high-performance GPU workstation. Conda was chosen over pip-based virtual environments specifically because of its ability to manage non-Python dependencies — including CUDA toolkit versions and cuDNN libraries — which are critical for stable GPU training and notoriously difficult to manage with pip alone.

Model architecture: We selected a GAN-based architecture (Generative Adversarial Network) with a U-Net generator and PatchGAN discriminator — a proven combination for facial image transformation tasks. The model was initialised with pre-trained weights from a generic face recognition foundation model and fine-tuned on the client’s 1,000-image dataset.

Web application layer: FastAPI served as the backend API, handling image upload, inference requests, and result delivery. The React frontend provided a clean user interface for image input and transformation preview. Results were delivered asynchronously to prevent timeout issues on longer inference calls.

FaceMorph AI application — AI face recognition web application development case study
FaceMorph AI web application — custom deep learning model training and deployment by A Square Solutions

Real Errors — What Actually Went Wrong

We document these errors because they are representative of what every serious AI application development project encounters — and because tutorials rarely show them. These are the actual problems we solved.

1

CUDA Out-of-Memory Error (OOM)

Error: `RuntimeError: CUDA out of memory. Tried to allocate 2.50 GiB`. Cause: Batch size set too large for available VRAM during GAN training with full-resolution images. Resolution: Implemented dynamic batch size scheduling starting at batch_size=4, gradient accumulation over 8 steps to simulate effective batch_size=32, and switched to mixed precision training (torch.cuda.amp) which reduced memory footprint by ~40%.

2

Conda Dependency Conflict

Error: `conda solve failed` when attempting to install torch==2.0.1 alongside opencv-python==4.7.0. Cause: Conflicting CUDA toolkit requirements between PyTorch’s bundled CUDA and OpenCV’s expected system CUDA. Resolution: Created separate conda environment with pinned specifications — `conda install pytorch==2.0.1 torchvision==0.15.2 pytorch-cuda=11.8 -c pytorch -c nvidia` followed by `pip install opencv-python-headless` to avoid GUI library conflicts.

3

Model Overfitting on 1,000 Images

Symptom: Training loss decreasing but validation loss plateauing at epoch 15, visual artifacts on test images not in training set. Cause: 1,000 images insufficient for the model to generalise without augmentation. Resolution: Implemented augmentation pipeline — random horizontal flip, rotation ±15°, colour jitter (brightness 0.2, contrast 0.2, saturation 0.1), random cropping. Added early stopping with checkpoint restoration at best validation loss.

4

Inference Latency Too High for Real-Time

Symptom: Inference time of 4.2 seconds per image on production hardware — unacceptable for web application use. Resolution: Applied post-training quantisation (INT8) using torch.quantization.quantize_dynamic, reducing model size by 60% and inference time to 0.8 seconds. For the most frequently used inference path, we added result caching to avoid redundant computation on identical inputs.

Deployment and Production Performance

After resolving the training challenges, the model achieved the quality and performance benchmarks required for production deployment. The GAN-trained model produced visually coherent transformations that met the client’s creative brief, with inference time under one second on production hardware.

The web application was deployed with a load-balanced architecture to handle concurrent requests without degrading inference quality. The FastAPI backend managed a request queue to prevent GPU memory pressure from simultaneous inference calls — a production consideration that casual AI tutorials never address but that every deployed AI application requires.

The client received a fully documented deployment — including the Conda environment specification, model checkpoint files, training logs, and operational runbook — ensuring that the system could be maintained and updated without requiring our direct involvement for routine operations. This is a principle we apply to every AI deployment engagement: the client should own the system, not just use it.

Performance

0.8s Inference

Post-quantisation inference time — real-time capable

Model Quality

Visually Coherent

Production-quality transformations meeting client’s creative brief

Technical

4 Errors Resolved

OOM, dependency conflicts, overfitting, latency — all resolved

Delivery

Full Documentation

Environment specs, checkpoints, runbook — client owns the system

“Working with A Square Solutions was a game-changer. Their AI expertise brought our face morphing concept to life with stunning precision and smooth performance.”

— Benjamin, Italian Musician & Digital Artist

The FaceMorph project demonstrated something important about AI application development: the gap between a working prototype and a production-grade deployment is not primarily a model quality gap — it is an engineering gap. Getting the model to work on a development machine is step one. Getting it to work reliably, quickly, and maintainably in a web application for real users is the actual challenge.

🚀 A Square Solutions

Need a similar solution? We specialise in Custom AI Application Development — from strategy to live deployment.

Our Services →Free Strategy Call

Frequently Asked Questions

What is FaceMorph and who was the client?

FaceMorph is a custom AI-powered face recognition and transformation web application built by A Square Solutions for a European client — an Italian musician who required a web app capable of training on his likeness from 1,000 personal photographs and performing real-time facial transformations at production-grade speed.

What technology stack was used to build the FaceMorph application?

The application used Python with PyTorch as the deep learning framework, Conda for environment management and dependency isolation, a GPU-accelerated training pipeline, and a React-based frontend with FastAPI backend for the web application layer. The model was trained and tested on a high-performance GPU workstation.

What were the main technical challenges during model training?

Key challenges included CUDA out-of-memory errors requiring batch size optimisation, Conda dependency conflicts between PyTorch, CUDA toolkit, and OpenCV versions, model overfitting on a 1,000-image dataset requiring data augmentation strategies, and inference latency requiring post-training quantisation to achieve acceptable real-time performance.

How did A Square Solutions solve the GPU memory and training errors?

The CUDA OOM errors were resolved through dynamic batch size scheduling, gradient accumulation, and mixed precision training (FP16). Conda environment conflicts were resolved by creating isolated environment specifications and pinning critical library versions. Overfitting was addressed through augmentation pipelines and early stopping with checkpoint restoration.

Reference Sources: PyTorch Documentation | Conda Documentation | FastAPI Documentation

💬 Have a question about this project?

Use the 🤖 Ask Our AI widget (bottom-right) — instant answers, 24/7.

🤖 Ask Our AI — A Square Solutions