Four AI models that repair damaged photos and turn faces into sketches, all in one web app.
You give it a photo, damage it (noise, blur or black patches), and see how three different AI approaches repair it. Or you give it a face and get a pencil sketch back in one of three artist styles. Everything runs on your own computer with one command.
| Workspace | In one sentence | |
|---|---|---|
| ๐งน | Universal Restoration | One model tries to fix any kind of damage on its own. |
| ๐ | Hard-Routed Restoration | First figure out what is wrong, then send the photo to the one specialist for that problem. |
| ๐๏ธ | Soft Mixture-of-Experts | Ask all specialists and blend their answers, trusting some more than others. |
| โ๏ธ | Face-to-Sketch Generator | Turn a face photo into a sketch, in the style you pick. |
| Damage | What it looks like | Low โ Medium โ High | |
|---|---|---|---|
| ๐ง | Salt-and-pepper noise | random black and white dots | 3% โ 8% โ 15% of pixels |
| ๐ซ๏ธ | Gaussian blur | the photo is out of focus | slight โ medium โ strong |
| โฌ | Occlusion | black boxes hide parts of the photo | 1 box (~10%) โ 2 (~20%) โ 3 (~35%) |
flowchart LR
A["๐ Datasets<br/>pet photos ยท face sketches"] --> B["๐ฉน Add damage<br/>on the fly"]
B --> C["๐ Optuna<br/>finds the best settings"]
C --> D["๐๏ธ Train<br/>the final model"]
D --> E["๐ Test once<br/>on unseen images"]
D --> F["๐ฆ Export to ONNX<br/>portable model file"]
F --> G["๐ Web app<br/>in Docker"]
C -.-> H[("๐ MLflow<br/>logs every run")]
D -.-> H
E -.-> H
In plain words:
- ๐ Data: pet photos (Oxford-IIIT Pet) for the repair tasks, and face photos with artist sketches (FS2K) for the sketch task.
- ๐ฉน Damage on the fly: every time a photo is loaded during training, it gets a fresh random damage, so the models never memorise one fixed version. The test photos get fixed damage, so all models are compared on exactly the same 36,690 images.
- ๐ Optuna tries many combinations of settings (learning rate, model size, โฆ) and keeps the best one.
- ๐๏ธ Training builds the final model with those settings.
- ๐ Testing happens once, at the very end, on images the model has never seen.
- ๐ฆ ONNX export saves each model in a portable format that runs fast on a normal CPU, no GPU needed.
- ๐ MLflow keeps a record of every experiment along the way.
flowchart LR
U["๐ง You<br/>in the browser"] <--> FE["๐จ Frontend<br/>React + Tailwind<br/>(nginx)"]
FE <-->|"/api"| BE["โ๏ธ Backend<br/>FastAPI"]
BE --> M["๐ง 7 AI models<br/>ONNX Runtime ยท CPU"]
BE --> S["๐ผ๏ธ Sample images"]
- ๐จ The frontend is the website you click around in.
- โ๏ธ The backend receives your photo, checks it, applies damage using the same code as training, and runs the models.
- ๐ง The models are the 7 exported files: 1 universal repairer, 1 damage classifier, 3 specialists, 1 mixture model and 1 sketch generator.
- ๐ณ Docker packs both parts into containers, so the whole thing starts with one command on any computer.
flowchart LR
A["Damaged photo<br/>128ร128"] --> B["Encoder<br/>shrinks it step by step"]
B --> C["๐ Bottleneck<br/>tiny summary<br/>(24ร smaller)"]
C --> D["Decoder<br/>rebuilds the photo"]
D --> E["Repaired photo"]
The model has to squeeze the whole photo into a tiny summary and rebuild it from there. Noise and damage don't fit through that squeeze, so they get removed. The catch: fine details don't fit either, so results look a little soft.
flowchart LR
A["Damaged photo"] --> C{"๐ Classifier<br/>what's wrong?"}
C -->|clean| I["โ
Keep as is"]
C -->|noise| S["๐ง Noise specialist"]
C -->|blur| B["๐ซ๏ธ Blur specialist"]
C -->|boxes| O["โฌ Occlusion specialist"]
I --> R["Result"]
S --> R
B --> R
O --> R
A classifier (99.8% accurate) decides what kind of damage the photo has and sends it to the one specialist trained for exactly that. Clean photos skip the repair step completely, so they come out perfect.
flowchart LR
A["Damaged photo"] --> G["๐๏ธ Gate<br/>decides the weights"]
A --> I["Original photo"]
A --> S["๐ง Noise specialist"]
A --> B["๐ซ๏ธ Blur specialist"]
A --> O["โฌ Occlusion specialist"]
G -.weights.-> M
I --> M(("โ Weighted<br/>mix"))
S --> M
B --> M
O --> M
M --> R["Result"]
Instead of picking one specialist, a "gate" gives each option a weight (e.g. 80% original photo + 20% blur specialist) and mixes them. It learned on its own to keep more of the original when the damage is mild, which made it the best of the three repair models.
flowchart LR
P["๐ท Face photo"] --> G["๐จ Generator<br/>(U-Net)<br/>draws the sketch"]
St["๐๏ธ Style 1 / 2 / 3"] --> G
G --> SK["โ๏ธ Sketch"]
SK --> D{"๐ง Discriminator<br/>(PatchGAN)<br/>real or fake?"}
P --> D
St --> D
RS["Real artist sketch"] --> D
D -.feedback.-> G
Two networks train against each other: the generator draws sketches, and the discriminator tries to tell its sketches apart from real artist drawings. Over time the generator gets better at fooling it. The chosen style goes into both networks, so the same face really comes out differently in each style.
How well each repair model does on the test photos (higher is better):
| Model | Similarity to original (SSIM) | Image quality (PSNR) | |
|---|---|---|---|
| ๐ฉน | Damaged photo, no repair | 0.639 | 19.7 dB |
| ๐งน | Universal Restoration | 0.806 | 25.5 dB |
| ๐ | Hard-Routed Restoration | 0.808 | 24.9 dB |
| ๐๏ธ | Soft Mixture-of-Experts | 0.845 ๐ | 26.2 dB ๐ |
- ๐ The damage classifier picks the right specialist 99.8% of the time.
- โ๏ธ The sketch generator produces clearly different drawings for the three styles: light lines, heavy shading, soft grey tones.
- โ Every exported model gives the same answers as the original training code (difference below 0.00003).
You need: ๐ง Git and ๐ณ Docker Desktop (open and running). No Python or programming setup needed.
1๏ธโฃ Get the code
git clone https://github.com/FaatehHaneef/Image-Processing-Engine.git
cd Image-Processing-Engine2๏ธโฃ Download the sketch model (168 MB, too big to store on GitHub directly)
curl -L -o models/onnx/task4_generator.onnx https://github.com/FaatehHaneef/Image-Processing-Engine/releases/download/models-v1/task4_generator.onnxOn Windows PowerShell, type curl.exe instead of curl. You can also download it from the release page and put it in models/onnx/.
3๏ธโฃ Start the app
docker compose up --buildโณ The first start takes a few minutes. Then open ๐ http://localhost:8080
When the top-right corner shows ๐ข Models loaded, you're ready. To stop: press Ctrl+C, then run docker compose down.
- ๐ค Upload your own photo (JPG/PNG, up to 10 MB) or pick one of the samples.
- ๐ฉน Choose a damage type and strength, click Apply corruption, then Restore.
- ๐ Compare the result, the error map, the classifier's guesses and the mixture weights.
- ๐ท In Face-to-Sketch, try your webcam and switch between the three styles.
- ๐พ Download any result.
| Folder | Contents |
|---|---|
๐ฆ src/ |
shared code: data loading, damage functions, models, training helpers |
๐ ๏ธ scripts/ |
data preparation, Optuna searches, training, testing, ONNX export |
โ๏ธ configs/ |
the best settings Optuna found for each model |
๐ artifacts/ |
data splits, fixed test damage, Optuna studies, result tables |
๐ง models/onnx/ |
the exported models the app uses |
โ๏ธ backend/ |
the FastAPI server, sample images, tests |
๐จ frontend/ |
the React website |
๐ docs/ |
design decisions, figures and notes |
โ
tests/ |
automated tests |
Only needed if you want to train the models again yourself. It requires an NVIDIA GPU (built on a 4 GB RTX 3050 Ti) and the two datasets, which aren't included.
- Create a Python 3.11 environment, install PyTorch with CUDA, then
pip install -r requirements.txt. - Put Oxford-IIIT Pet in
data/oxford-iiit-pet/and FS2K indata/fs2k/FS2K/. - Run
python scripts/prepare_data.py, then theoptuna_*,train_*andevaluate_*scripts for each task, and finallyexport_onnx.py --all.
๐ To browse the experiment history: mlflow ui --backend-store-uri sqlite:///mlruns/mlflow.db, then open http://127.0.0.1:5000 and choose Model training.
- Oxford-IIIT Pet Dataset: Parkhi et al., "Cats and Dogs", CVPR 2012 (CC BY-SA 4.0). The 16 sample pet photos come from its test set.
- FS2K: Fan et al., "Facial-Sketch Synthesis: A New Challenge", 2022. The 6 sample faces come from its test set.
- Interface designed with Google Stitch.