- Project Overview
- Motivation
- System Architecture
- Dataset
- Active Learning Workflow
- Segment Anything Model (SAM) Integration
- Frontend: Web-Based Correction Interface
- Correction Logic
- Data Organization
- Retraining Pipeline
- Performance Considerations
- Limitations and Future Work
- Installation and Usage
- Deployment on Azure App Service
- Demo
This project implements an interactive human-in-the-loop correction system for object detection and segmentation. The objective is to iteratively improve model performance while minimizing manual annotation effort by focusing only on incorrect predictions.
Key components:
- YOLO-based object detection and segmentation model
- Web-based frontend for prediction review and correction
- Segment Anything Model (SAM) for high-quality mask refinement
- Active learning loop with incremental retraining
Core principle: Correct only what is wrong; preserve what is already correct.
High-quality segmentation annotation is expensive and time-consuming, particularly for high-resolution industrial imagery. This project addresses that problem by:
- Using a pretrained model to generate predictions on new data
- Asking the user to correct only erroneous predictions
- Leveraging SAM to automate fine-grained mask creation
- Feeding corrections back into the training loop
The result is a scalable active learning system that improves with minimal human intervention.
-
Initial Training
- YOLO model trained on a Roboflow-labeled dataset.
-
Prediction
- Model performs inference on new image batches.
- Bounding boxes and masks are generated.
-
Results Review
- Visual overlays and per-object metrics are displayed.
-
User Correction
- Users correct only incorrect predictions via the frontend.
-
SAM Refinement
- User-drawn bounding boxes are converted into precise masks.
-
Feedback Collection
- Corrections and metadata are stored in structured JSON.
-
Retraining
- Original predictions and corrections are merged.
- Model is fine-tuned incrementally.
This architecture forms a closed-loop active learning system.
The baseline dataset was sourced from Roboflow and includes:
-
Images annotated with classes such as:
ChipVoid
-
YOLO-compatible detection and segmentation formats
-
Data augmentation (blur, rotation, etc.) applied via Roboflow
- Initial dataset used for baseline training
- User corrections progressively expand and refine the dataset
Instead of re-labeling entire datasets:
- The model predicts on unseen images
- The user reviews predictions
- Only incorrect regions are corrected
- Unsatisfactory predicted boxes can be deleted
- Corrections are reintegrated into retraining
This approach significantly reduces annotation cost while improving model accuracy.
SAM is used to convert coarse user corrections into high-quality segmentation masks.
Key characteristics:
- SAM is used only during correction, never during inference
- Bounding boxes are sufficient input for mask generation
- Manual polygon drawing is avoided entirely
This design balances annotation speed with segmentation precision.
The frontend is a lightweight Flask-based web interface designed to support the active learning loop. It is organized into four main pages.
Purpose: Trigger model inference on new images.
Functionality:
- Launch batch prediction
- Generate overlays with bounding boxes and class labels
- Store prediction results for review
Purpose: Review model predictions before correction.
Functionality:
- Display predicted images sequentially
- Show bounding boxes, masks, and class labels
- Display per-chip metrics
Submitting no correction implicitly validates the prediction.
We can save the results in a csv file at the bottom of the page.
Purpose: Correct only erroneous predictions.
Functionality:
- Draw bounding boxes over incorrect regions
- Assign class labels (
Chip,Void) - Delete incorrect predicted boxes
- Undo and modify corrections
Submitted boxes are refined into masks using SAM.
If no changes has been made on the batch, UI inform user and don't let him retrain.
Purpose: Monitor and control retraining.
Functionality:
- Trigger retraining manually
- Display retraining is happening by a spinning wheel
-
Original predictions are preserved by default
-
Corrections override only erroneous regions
-
During retraining:
- Corrected masks replace incorrect predictions
- Valid predictions remain unchanged
This guarantees annotation integrity.
Stores visual artifacts:
- Prediction overlays
- Corrected overlays
- SAM-generated masks (
.npy)
Stored as structured JSON:
- Image ID
- Correction status (
ok,corrected) - Bounding boxes and class labels
- Mask references
This separation simplifies retraining and debugging.
- Corrections are merged with original labels and predictions
- YOLO is retrained incrementally
- Fewer epochs are used for new data to avoid catastrophic forgetting
This enables efficient iterative improvement.
- SAM invoked only when needed
- Minimal disk I/O
- Batch-based retraining
- Asynchronous background retraining
- Box-based corrections only
- No real-time SAM preview
- Batch retraining (not fully online)
- Single-user workflow assumption
- Confidence-based sample selection
- Incremental online learning
- Multi-user correction sessions
- Dataset versioning
- Automated evaluation dashboards
- Scaling up: Better model for correction (sam-vit-h instead of sam-vit-b), more data for traininng a better yolo model (yolo11X maybe instead of actual 11m ...)
- Python 3.10+
- PyTorch (CPU or CUDA)
- YOLOv8 (Ultralytics)
- Flask
- Segment Anything Model dependencies
See the rest of the dependencies in the requirements.txt
- Clone the repository
- Install dependencies
- Run the Flask application
- Access the web interface locally
The application was deployed as a containerized AI web service using Azure Container Apps (ACA). This solution enables scalable execution of a compute-intensive AI workload without managing virtual machines.
The application was packaged into a Docker container to ensure portability and environment consistency.
- Flask application served with Gunicorn
- AI inference and processing logic embedded in the container
- Application listens on port 5000
- All dependencies included inside the image
A dedicated Azure Resource Group was created to host all deployment resources.
- Logical organization of cloud components
- Simplified lifecycle management and cost tracking
- Isolation from other Azure projects
On the free tier, you need to be particularly attentive to the location you choose (Azure gives you your allowed set of region for your student account).
An Azure Container Registry was used to store and distribute the application image.
- Docker image built locally
- Image pushed to a private ACR instance
- Secure image pull by Azure Container Apps
Purpose of ACR:
- Hosts custom AI containers (models, frameworks, dependencies)
- Supports large container images
- Provides secure, high-performance access inside Azure
A Container Apps Environment was created to act as a secure runtime boundary.
- Manages networking, logging, and scaling
- Provides isolation between container apps
- Fully managed by Azure
The container app was configured to run the AI service.
- Image source: Azure Container Registry
- Automatic authentication to ACR
- Default container entrypoint (Gunicorn)
Resource allocation:
- CPU and memory allocated for AI inference workload
- Resources sufficient to load deep learning models at startup
Pricing model:
- Consumption-based pricing
- No upfront payment required
- Costs incurred only when the app is running
Public access was enabled using Azure Container Apps ingress.
- Ingress enabled
- HTTP traffic allowed
- Target port set to 5000
- Azure-generated public URL provided
This allows direct access to the web interface and API endpoints.
The deployment was validated using Azure logs and diagnostics.
- Container startup confirmed
- Gunicorn successfully listening on port 5000
- AI models loaded correctly
- Web interface and API endpoints operational
The application is successfully deployed as a fully managed AI web service on Azure Container Apps.
- No virtual machines to manage
- Scalable and resilient architecture
- Secure container image delivery
- Suitable for production-grade AI inference workloads