Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

24 Commits

Folders and files

Repository files navigation

๐Ÿ–ผ๏ธ Image Processing Engine

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.


โœจ What's inside

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.

๐Ÿฉน The kinds of damage

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%)

๐Ÿ”„ The pipeline: from data to app

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
Loading

In plain words:

  1. ๐Ÿ“‚ Data: pet photos (Oxford-IIIT Pet) for the repair tasks, and face photos with artist sketches (FS2K) for the sketch task.
  2. ๐Ÿฉน 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.
  3. ๐Ÿ” Optuna tries many combinations of settings (learning rate, model size, โ€ฆ) and keeps the best one.
  4. ๐Ÿ‹๏ธ Training builds the final model with those settings.
  5. ๐Ÿ“Š Testing happens once, at the very end, on images the model has never seen.
  6. ๐Ÿ“ฆ ONNX export saves each model in a portable format that runs fast on a normal CPU, no GPU needed.
  7. ๐Ÿ“ˆ MLflow keeps a record of every experiment along the way.

๐Ÿ—๏ธ How the app is built

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"]
Loading
  • ๐ŸŽจ 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.

๐Ÿง  How each model works

๐Ÿงน 1. Universal Restoration: one model for everything

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"]
Loading

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.

๐Ÿ”€ 2. Hard-Routed Restoration: diagnose, then treat

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
Loading

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.

๐ŸŽ›๏ธ 3. Soft Mixture-of-Experts: blend everyone's answer

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"]
Loading

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.

โœ๏ธ 4. Face-to-Sketch Generator: an artist and a critic

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
Loading

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.


๐Ÿ“Š Results

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).

๐Ÿš€ Run it yourself

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-Engine

2๏ธโƒฃ 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.onnx

On 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.

๐ŸŽฎ Things to try

  • ๐Ÿ“ค 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.

๐Ÿ“ What's in the repository

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

๐Ÿ” Retraining (optional)

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.

  1. Create a Python 3.11 environment, install PyTorch with CUDA, then pip install -r requirements.txt.
  2. Put Oxford-IIIT Pet in data/oxford-iiit-pet/ and FS2K in data/fs2k/FS2K/.
  3. Run python scripts/prepare_data.py, then the optuna_*, train_* and evaluate_* scripts for each task, and finally export_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.


๐Ÿ™ Credits

  • 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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages