A production-grade FastAPI application that intelligently removes humans from room images and seamlessly reconstructs the background using state-of-the-art computer vision models.
CleanSlate AI uses a three-stage AI pipeline to detect, segment, and remove humans from images:
| Stage | Model | Purpose |
|---|---|---|
| 1. Detection | YOLOv11 Nano | Locates humans in the image with bounding boxes |
| 2. Segmentation | SAM 2 (Segment Anything Model 2) | Creates pixel-perfect masks of detected humans |
| 3. Inpainting | IOPaint (LaMa) | Reconstructs the background seamlessly |
- Human Detection - Fine-tuned YOLOv11 model for accurate person detection
- Precise Segmentation - SAM 2 generates pixel-level masks with smooth edges
- Background Reconstruction - LaMa-based inpainting fills removed areas naturally
- RESTful API - Clean FastAPI endpoints with automatic OpenAPI documentation
- Session Management - Isolated temporary directories per request with auto-cleanup
- CORS Enabled - Ready for cross-origin frontend integration
CleanSlate-AI/
├── app/
│ ├── api/
│ │ └── routes.py # API endpoint definitions
│ ├── core/
│ │ ├── config.py # Configuration settings
│ │ └── models.py # Model loaders (YOLO + SAM)
│ ├── services/
│ │ ├── processing.py # Core image processing pipeline
│ │ ├── response.py # Response formatting utilities
│ │ └── utils.py # Helper functions
│ └── main.py # FastAPI application entry
├── runs/
│ └── detect/
│ └── train/
│ ├── weights/
│ │ ├── best.pt # Best model checkpoint
│ │ └── last.pt # Latest model checkpoint
│ ├── results.csv # Training metrics
│ └── args.yaml # Training configuration
├── sam2_b.pt # SAM 2 Base model weights
├── requirements.txt # Python dependencies
├── run.py # Server startup script
└── readme.md
- Python 3.10 or higher
- pip package manager
- Git
git clone https://github.com/stellainternational/SIMPLIFIED_AI_PEOPLE.git
cd SIMPLIFIED_AI_PEOPLEWindows:
python -m venv removal-env
.\removal-env\Scripts\activateLinux/macOS:
python -m venv removal-env
source removal-env/bin/activatepip install -r requirements.txtpython run.pyOr using uvicorn directly:
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000The API will be available at http://localhost:8000
Once the server is running, access the interactive API docs:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Removes humans from an uploaded image and returns the processed result.
Request:
- Content-Type:
multipart/form-data - Body:
file- Image file (JPEG or PNG)
Response:
{
"status": "success",
"status_code": 200,
"response": {
"message": "Person Removed from the image",
"mask_image_base64": "<base64-encoded-mask>",
"output_image_base64": "<base64-encoded-result>"
}
}Example using cURL:
curl -X POST "http://localhost:8000/remove-person/" \
-H "accept: application/json" \
-H "Content-Type: multipart/form-data" \
-F "file=@room_with_person.jpg"Example using Python:
import requests
import base64
url = "http://localhost:8000/remove-person/"
files = {"file": open("room_with_person.jpg", "rb")}
response = requests.post(url, files=files)
result = response.json()
# Decode and save the output image
output_data = base64.b64decode(result["response"]["output_image_base64"])
with open("cleaned_room.jpg", "wb") as f:
f.write(output_data)Clears temporary session data from the server.
Response:
{
"message": "All folders inside 'data' directory have been cleaned up."
}┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Upload │───▶│ YOLO │────▶│ SAM 2 │────▶│ IOPaint │
│ Image │ │ Detection │ │ Segmentation│ │ Inpainting │
└─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘
│ │ │
▼ ▼ ▼
Bounding Pixel-level Reconstructed
Boxes Masks Background
Post-Processing Steps:
- Combine multiple masks into a single binary mask
- Apply morphological closing to fill gaps
- Dilate mask to ensure complete coverage
- Gaussian blur for smooth edges
- Threshold to create final binary mask
| Category | Technology |
|---|---|
| Web Framework | FastAPI 0.108.0 |
| Deep Learning | PyTorch 2.6.0, Torchvision 0.21.0 |
| Object Detection | Ultralytics YOLOv11 |
| Segmentation | SAM 2 (Segment Anything Model 2) |
| Inpainting | IOPaint 1.6.0 (LaMa) |
| Image Processing | OpenCV 4.11.0, Pillow 9.5.0 |
| Async I/O | aiofiles |
The application uses the following model paths (configurable in app/core/models.py):
yolo_model = YOLO("runs/detect/train/weights/best.pt")
sam_model = SAM("sam2_b.pt")1. CUDA/GPU not detected
- The application defaults to CPU. For GPU support, ensure CUDA-compatible PyTorch is installed.
2. Out of memory errors
- Try processing smaller images (resize before upload)
- Ensure sufficient RAM (8GB+ recommended)
3. IOPaint command fails
- Verify IOPaint is installed:
pip install iopaint - Check that the LaMa model downloads successfully on first run
4. Model files not found
- Ensure
runs/detect/train/weights/best.ptexists - Ensure
sam2_b.ptis in the project root
This project is licensed under the MIT License.
- Ultralytics for YOLOv11
- Meta AI for SAM 2
- IOPaint for the inpainting engine