An innovative computer vision project combining SAM 2, Depth Anything V2, and CLIP for comprehensive scene understanding.
VisionMate is a cutting-edge AI system that can:
- π― Segment any object in an image (click to identify)
- π Estimate depth (how far away is each object?)
- π§ Understand language (ask questions about the scene)
- π¬ Answer queries ("What is the closest object?")
VisionMate fuses three state-of-the-art models from 2024-2025:
| Model | What it does | Released |
|---|---|---|
| SAM 2 | Universal object segmentation | July 2024 |
| Depth Anything V2 | Monocular depth estimation | NeurIPS 2024 |
| CLIP | Vision-language understanding | 2021 |
This combination enables spatial reasoning that no single model can achieve:
- "What is the closest object?" β Uses SAM + Depth
- "Where is the person?" β Uses SAM + CLIP + position
- "Describe the scene" β Uses all three!
git clone https://github.com/yourusername/VisionMate.git
cd VisionMate
# Create virtual environment
python -m venv venv
# Activate it
# Windows:
venv\Scripts\activate
# Linux/Mac:
source venv/bin/activate
# Install dependencies
pip install -r requirements.txtpython app.pyOpen your browser to http://127.0.0.1:7860
On first run, models will be downloaded (~2GB total). This only happens once!
The Gradio demo provides:
- Upload & Analyze: Upload any image for full scene analysis
- Depth Map: Visualize distances with color coding
- Q&A: Ask natural language questions
- Click to Identify: Click any point to identify the object
from visionmate import VisionMate
# Initialize (loads models)
vm = VisionMate()
# Analyze an image
scene = vm.analyze("photo.jpg")
# Ask questions
print(vm.query(question="What do you see?"))
print(vm.query(question="What is the closest object?"))
# Interactive segmentation
result = vm.segment_at_point("photo.jpg", x=100, y=200)
print(f"You clicked on: {result['label']}")
print(f"Distance: {result['depth']['mean_distance']:.2f}")
# Get depth map
depth, colormap = vm.get_depth_map("photo.jpg", colormap=True)βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β VisionMate Pipeline β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β π· Image β
β β β
β ββββββββββββββββββββ¬βββββββββββββββββββ¬βββββββββββββββββββ€ β
β βΌ βΌ βΌ β
β ββββββββββ ββββββββββ ββββββββββ β
β β SAM 2 β β Depth β β CLIP β β
β β (Seg) β βAnythingβ β (VLM) β β
β ββββββ¬ββββ ββββββ¬ββββ ββββββ¬ββββ β
β β β β β
β βΌ βΌ βΌ β
β [Masks] [Depth Map] [Labels] β
β β β β β
β βββββββββββββββββββΌβββββββββββββββββββ β
β βΌ β
β βββββββββββββββββ β
β β Spatial β β
β β Reasoner β β
β βββββββββ¬ββββββββ β
β βΌ β
β π¬ Natural Language Answer β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- Foundation Models: Using pre-trained models for zero-shot generalization
- Multi-Modal AI: Fusing vision and language understanding
- Model Orchestration: Combining multiple models into a pipeline
- Spatial Reasoning: Deriving 3D understanding from 2D images
Each file contains detailed comments explaining:
| File | Concepts Covered |
|---|---|
depth_estimator.py |
Monocular depth estimation, Vision Transformers, lazy loading |
segmenter.py |
Foundation models, promptable AI, IoU metrics |
vision_language.py |
CLIP, contrastive learning, embeddings, zero-shot classification |
spatial_reasoner.py |
Model fusion, scene graphs, spatial relationships |
pipeline.py |
Facade pattern, API design, memory management |
app.py |
Gradio, web interfaces, event handling |
Tested on NVIDIA RTX 3050 (6GB VRAM):
| Operation | Time |
|---|---|
| First load | ~30s (downloads models) |
| Analyze image | ~3-5s |
| Answer query | ~0.1s |
| Click segmentation | ~0.5s |
Adjust model sizes for speed/quality trade-off:
# Fast (lower quality) - good for demos
vm = VisionMate(
depth_model="small",
seg_model="tiny",
vlm_model="base",
)
# Balanced
vm = VisionMate(
depth_model="base",
seg_model="small",
vlm_model="base",
)
# High quality (slower, needs more VRAM)
vm = VisionMate(
depth_model="large",
seg_model="large",
vlm_model="large",
)VisionMate/
βββ visionmate/
β βββ __init__.py # Package exports
β βββ depth_estimator.py # Depth Anything V2 wrapper
β βββ segmenter.py # SAM 2 wrapper
β βββ vision_language.py # CLIP wrapper
β βββ spatial_reasoner.py # Fusion & reasoning
β βββ pipeline.py # Main VisionMate class
βββ app.py # Gradio web interface
βββ requirements.txt # Python dependencies
βββ README.md # This file
Contributions welcome! Ideas for extensions:
- Video support (use SAM 2's video capabilities)
- Metric depth estimation (convert relative to absolute)
- More query types (counting, OCR, attributes)
- Voice input/output
- Mobile optimization
MIT License - feel free to use for your portfolio!
- Meta AI for SAM 2
- DepthAnything Team for Depth Anything V2
- OpenAI for CLIP
- Hugging Face for model hosting
- Gradio for the UI framework
Built for learning and portfolio demonstration
β Star this repo if you found it helpful!
