Back to Case Studies

Ensemble Background Removal

Per-Image Model Routing for an Image-Tools Platform

ProductionEnterprise Software & IT ServicesNov 2024 – Apr 2025Computer Vision & Document Intelligence
99.2%
Mask accuracy on ~50k test images
10
Models benchmarked before routing
Per-image
Routing to the best model per picture
Shipped
In production, handed over

My Role

Role
Architect & tech lead
At Dataforest
Team
Team of 2–3
Stage reached
In production, handed over
Key decisions
  • Ensemble with a per-image router, not one model
  • Benchmark 10 models with a failure catalogue
  • Route via KNN voting on fine-tuned image embeddings

Approach at a Glance

Details
  1. 1Approach Selection
  2. 210-Model Benchmark with a Failure Catalogue
  3. 3Learned Per-Image Router
  4. 4Production Service
  5. 5Handover

Executive Summary

A production background-removal service for an online image-tools platform, a service like iLovePDF but for images, where anyone can upload a picture and get a clean cutout. The images are as varied as the internet: products, people, pets, cars, illustrations, game art, flowers, landscapes.

Our benchmark of 10 background-removal models showed that no single model wins everywhere. One keeps fine details but leaves halos, another removes backgrounds cleanly but cuts off parts of the object, and a third handles people but struggles with fur or foliage. So instead of choosing one model, we built an ensemble with a learned router. For each uploaded image, the router predicts which model will give the best result and sends the image there.

Offline, on about 50,000 test images, the ensemble reached 99.2% pixel-level mask accuracy, and the routed ensemble outperformed every single model on the quality metric. The service was deployed with a cache, a queue and auto-scaling workers, then handed over to the client's team. I was the architect and tech lead in a team of 2–3 people.


Client Profile

The client runs an online platform with simple tools for everyday image tasks. Background removal is one of the most used, and its quality is the product: a missing sleeve, a halo around a dog's fur or a leftover patch of background is immediately visible to the user.

The challenge is the variety of images. A model tuned for product photos fails on hair and fur. A model that handles people well loses thin structures like leaves or umbrella spokes. Some images produce outlines, others blurred edges or dark fringes. The client needed results that were consistently good across all of these, at the speed and cost of an online tool.


Technical Approach

  1. Approach Selection – At the start we compared three directions: a large vision foundation model, a lightweight segmentation model that runs on CPU, and a promptable segmentation model. We weighed quality, latency (under 5 seconds), GPU versus CPU hosting cost and integration effort.

  2. 10-Model Benchmark with a Failure Catalogue – We ran 10 background-removal models over a deliberately varied test set and recorded how each one failed on each image:

    • part of the object missing,
    • a noticeable outline left behind,
    • background partially visible,
    • blurred edges,
    • dark fringes.

    The catalogue made it clear that different models fail on different kinds of images, and that a few models together covered almost every case.

  3. Learned Per-Image Router – The router decides which model to use before any cutout is made:

    • Embeddings: each image is turned into an embedding by a pretrained vision backbone. We compared EfficientNet variants, ViT-B/16, MobileNetV3 and VGG16, and checked how well each separated image types with t-SNE.
    • Labels: about 10,000 images were labeled with which models produced acceptable cutouts.
    • Voting: for a new image, its nearest labeled neighbours vote on the best model, with a fixed priority order to break ties.
    • Triplet loss: we fine-tuned the embedding space with triplet and contrastive losses, so that images that need the same model sit closer together.
  4. Production Service – The service is built for an online tool's traffic:

    • API: a primary API receives the uploads.
    • Cache: an image-hash cache returns repeated images instantly.
    • Queue and workers: a queue feeds the router and the model workers, which run on an auto-scaling group of CPU and GPU instances.
    • Task log: every job's status, timings and errors are recorded for monitoring.
  5. Handover – The service was deployed to production and handed over to the client's team with its documentation.


Business Outcome

The platform got a background-removal tool that holds up across the full variety of images its users upload. Instead of accepting one model's blind spots, every image is routed to the model most likely to cut it out cleanly. Offline, the ensemble reached 99.2% pixel-level mask accuracy on about 50,000 test images and outperformed every single model on the quality metric.

The service runs in production with caching, queuing and auto-scaling, so quality doesn't come at the cost of speed or hosting spend. It was handed over to the client's team, who continue to operate it.

Technologies

Computer VisionImage SegmentationModel EnsemblingImage EmbeddingsKNNTriplet LossCeleryAuto-Scaling GPU Workers

Planning something similar?

Tell me about it on a short call. New projects can start within 2 weeks