Case Study

Computer Vision Segmentation Pipeline

Based on production systems built at Infidea.

Summary

Built and maintained an asynchronous image segmentation pipeline at Infidea for healthcare-adjacent clinical workflows. The system handled large images exceeding model input resolution via sliding-window inference, queued jobs through RabbitMQ, ran PyTorch model inference, and deployed optimized models to Android using TorchScript and JNI for offline inference. Served both cloud API and mobile deployment paths.

What This Page Covers

  • How the async pipeline handles variable inference load without blocking
  • Sliding-window and post-processing techniques for large medical images
  • Why TorchScript + JNI was chosen for mobile deployment over other approaches

Approach

The pipeline used Flask for the API layer, RabbitMQ for job queuing, and PyTorch for model inference. Images are received via the API, queued, and processed by worker processes. For images larger than the model's input resolution, I implemented sliding-window inference that tiles the image, runs inference on overlapping patches, and stitches the results. Post-processing includes morphological operations and contour extraction for mask refinement.

For mobile deployment, I exported trained PyTorch models to TorchScript and integrated them into Android via JNI. This avoided requiring an on-device Python runtime while keeping inference performance close to native PyTorch.

Key Decisions

  • Async queue architecture — decouples API requests from inference processing, handles variable load without request timeouts
  • Sliding-window inference — handles clinical images that far exceed model input resolution without losing spatial detail
  • TorchScript + JNI for mobile — eliminates on-device Python dependency while maintaining inference speed
  • ONNX export option — provides a deployment path for non-PyTorch environments and edge devices

Tech Stack

Python, Flask, PyTorch, OpenCV, ONNX, RabbitMQ, AWS, TorchScript, JNI.

Outcome

Production pipeline serving healthcare-adjacent segmentation workflows with both cloud API access and offline mobile deployment. Reused across multiple image analysis projects at Infidea.

Need something like this?

If you are building a computer vision pipeline, segmentation system, or need model deployment to cloud and mobile, contact me to discuss the architecture.

View all case studies