A computer vision pipeline for detecting and segmenting furniture and objects in interior images using state-of-the-art object detection and segmentation models.
This tool automatically identifies and labels furniture and objects in indoor scenes using Florence-2 for open-vocabulary object detection combined with SAM-HQ for precise segmentation.
The detection pipeline consists of two stages:
Input Image → Florence-2 Phrase Grounding → SAM-HQ Segmentation → Annotated Output + COCO JSON
microsoft/Florence-2-base (or Florence-2-large)Clone or download this repository
Create a virtual environment:
python -m venv myenv
myenv\Scripts\activate # Windows
# or
source myenv/bin/activate # Linux/Mac
pip install -r requirements.txt
# For CUDA 12.x
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu124
On the first run, the models will be automatically downloaded:
models/This package provides two scripts:
segment_image.py - Full detection + segmentation pipeline (Florence-2 + SAM-HQ)label_changes.py - Detection only (Florence-2), outputs JSON coordinates for frontend useProcess images with detection and segmentation:
# Process a single image
python segment_image.py path/to/image.jpg
# Process a directory
python segment_image.py path/to/images/
# Custom output directory
python segment_image.py images/ --output custom_results/
Get bounding box coordinates for frontend visualization with automatic JSON and image outputs:
# Basic usage - auto-generates JSON + labeled image
python label_changes.py room.jpg
# With custom vocabulary
python label_changes.py room.jpg "sofa, coffee table, lamp"
# Save to custom directory
python label_changes.py room.jpg --output-dir results/
# Skip image generation (JSON only)
python label_changes.py room.jpg --no-image
# Print to console only (no files)
python label_changes.py room.jpg --no-json --no-image
# Get pixel coordinates instead of normalized
python label_changes.py room.jpg --format pixels
# Disable automatic filtering (keep all detections including duplicates)
python label_changes.py room.jpg --no-filter
Automatic Detection Filtering:
By default, label_changes.py automatically cleans up detections to:
--no-filter to disable this behavior--iou-threshold 0.7 (default)Default Output Files:
{image_stem}_detections.json - Bounding box coordinates (normalized by default){image_stem}_labeled.jpg - Annotated image with colored bounding boxes and labelsVocabulary Priority:
{image_stem}_prompt.json) - if existsconfig.py - fallbackCreating a Prompt JSON File:
For an image named room.jpg, create room_prompt.json:
{
"prompts": ["sofa", "coffee table", "lamp", "chair"]
}
Why use label_changes.py?
segment_image.pyEdit config.py to customize:
Add or remove object types in the VOCABULARY list:
VOCABULARY = [
'sofa', 'chair', 'table', 'bed', 'lamp', ...
]
MODEL_CONFIG = {
'device': 'cuda', # or 'cpu'
'box_threshold': 0.3, # Lower = more detections (try 0.2-0.25)
'text_threshold': 0.25
}
VIZ_CONFIG = {
'box_thickness': 2,
'font_scale': 0.5,
'show_confidence': True
}
For each processed image, the pipeline generates:
*_annotated.jpg: Image with bounding boxes and labels (disabled visually) and SAM-HQ masksAll outputs are saved to the results/ directory (or custom directory specified with --output).
Returns JSON with bounding box coordinates. Example output:
Normalized Format (Default - Recommended for Frontend):
{
"image_path": "room.jpg",
"image_size": {"width": 1920, "height": 1080},
"vocabulary": ["sofa", "table", "lamp"],
"detections": [
{
"label": "sofa",
"confidence": 1.0,
"bbox": [0.125, 0.342, 0.487, 0.856],
"center": [0.306, 0.599],
"width": 0.362,
"height": 0.514
}
],
"count": 1,
"coordinate_format": "normalized"
}
Coordinate Systems:
JavaScript/Canvas:
// Load detections
const detections = await fetch('detections.json').then(r => r.json());
// Draw on canvas
function drawBoxes(canvas, image, detections) {
const ctx = canvas.getContext('2d');
detections.detections.forEach(det => {
const [x1, y1, x2, y2] = det.bbox;
// Convert normalized to pixels
const x = x1 * image.width;
const y = y1 * image.height;
const w = (x2 - x1) * image.width;
const h = (y2 - y1) * image.height;
ctx.strokeStyle = 'red';
ctx.strokeRect(x, y, w, h);
});
}
React/HTML Overlay:
function BoundingBoxOverlay({ detections }) {
return detections.detections.map((det, i) => {
const [x1, y1, x2, y2] = det.bbox;
return (
<div key={i} style={{
position: 'absolute',
left: `${x1 * 100}%`,
top: `${y1 * 100}%`,
width: `${(x2 - x1) * 100}%`,
height: `${(y2 - y1) * 100}%`,
border: '3px solid red',
pointerEvents: 'none'
}}>
<span style={{color: 'red', fontWeight: 'bold'}}>
{det.label}
</span>
</div>
);
});
}
config.pyThe pipeline can detect 40+ interior object types including:
See config.py for the complete vocabulary list.
This project uses the following open-source models:
Special thanks to:
This project uses models with the following licenses:
Please refer to the respective model repositories for detailed license information.
"CUDA not available" error:
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu124device: 'cpu' in config.pyOut of memory errors:
Poor detection results:
VOCABULARYinterior-segment-labeler/
├── config.py # Configuration and vocabulary
├── segment_image.py # Full pipeline (detection + segmentation)
├── label_changes.py # Detection-only API (NEW)
├── models/
│ └── model.py # Model loading and inference
├── visualization.py # Image annotation utilities
├── utils.py # Helper functions
├── requirements.txt # Python dependencies
└── README.md # This file
| Feature | segment_image.py | label_changes.py |
|---|---|---|
| Detection | ✅ Florence-2 | ✅ Florence-2 |
| Segmentation | ✅ SAM-HQ masks | ❌ None |
| Image Output | Annotated with masks | Annotated with boxes |
| JSON Output | Optional | Default (detections) |
| Coordinates | Pixels | Normalized + Pixels |
| Speed | Slower (~5-10s/image) | Faster (~1-2s/image) |
| Memory | Higher (both models) | Lower (Florence-2 only) |
| Use Case | Segmentation masks | Bounding box highlights |
| Best For | Research, pixel-masks | Web apps, UI overlays |
If you use this tool in your research or project, please cite the original models:
@article{xiao2023florence,
title={Florence-2: Advancing a unified representation for a variety of vision tasks},
author={Xiao, Bin and Wu, Haiping and Xu, Weijian and Dai, Xiyang and Hu, Houdong and Lu, Yumao and Zeng, Michael and Liu, Ce and Yuan, Lu},
journal={arXiv preprint arXiv:2311.06242},
year={2023}
}
@inproceedings{sam_hq,
title={Segment Anything in High Quality},
author={Ke, Lei and Ye, Mingqiao and Danelljan, Martin and Liu, Yifan and Tai, Yu-Wing and Tang, Chi-Keung and Yu, Fisher},
booktitle={NeurIPS},
year={2023}
}
16 commits
Python
100.0%
A computer vision pipeline for detecting and segmenting furniture and objects in interior images using state-of-the-art object detection and segmentation models.
This tool automatically identifies and labels furniture and objects in indoor scenes using Florence-2 for open-vocabulary object detection combined with SAM-HQ for precise segmentation.
The detection pipeline consists of two stages:
Input Image → Florence-2 Phrase Grounding → SAM-HQ Segmentation → Annotated Output + COCO JSON
microsoft/Florence-2-base (or Florence-2-large)Clone or download this repository
Create a virtual environment:
python -m venv myenv
myenv\Scripts\activate # Windows
# or
source myenv/bin/activate # Linux/Mac
pip install -r requirements.txt
# For CUDA 12.x
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu124
On the first run, the models will be automatically downloaded:
models/This package provides two scripts:
segment_image.py - Full detection + segmentation pipeline (Florence-2 + SAM-HQ)label_changes.py - Detection only (Florence-2), outputs JSON coordinates for frontend useProcess images with detection and segmentation:
# Process a single image
python segment_image.py path/to/image.jpg
# Process a directory
python segment_image.py path/to/images/
# Custom output directory
python segment_image.py images/ --output custom_results/
Get bounding box coordinates for frontend visualization with automatic JSON and image outputs:
# Basic usage - auto-generates JSON + labeled image
python label_changes.py room.jpg
# With custom vocabulary
python label_changes.py room.jpg "sofa, coffee table, lamp"
# Save to custom directory
python label_changes.py room.jpg --output-dir results/
# Skip image generation (JSON only)
python label_changes.py room.jpg --no-image
# Print to console only (no files)
python label_changes.py room.jpg --no-json --no-image
# Get pixel coordinates instead of normalized
python label_changes.py room.jpg --format pixels
# Disable automatic filtering (keep all detections including duplicates)
python label_changes.py room.jpg --no-filter
Automatic Detection Filtering:
By default, label_changes.py automatically cleans up detections to:
--no-filter to disable this behavior--iou-threshold 0.7 (default)Default Output Files:
{image_stem}_detections.json - Bounding box coordinates (normalized by default){image_stem}_labeled.jpg - Annotated image with colored bounding boxes and labelsVocabulary Priority:
{image_stem}_prompt.json) - if existsconfig.py - fallbackCreating a Prompt JSON File:
For an image named room.jpg, create room_prompt.json:
{
"prompts": ["sofa", "coffee table", "lamp", "chair"]
}
Why use label_changes.py?
segment_image.pyEdit config.py to customize:
Add or remove object types in the VOCABULARY list:
VOCABULARY = [
'sofa', 'chair', 'table', 'bed', 'lamp', ...
]
MODEL_CONFIG = {
'device': 'cuda', # or 'cpu'
'box_threshold': 0.3, # Lower = more detections (try 0.2-0.25)
'text_threshold': 0.25
}
VIZ_CONFIG = {
'box_thickness': 2,
'font_scale': 0.5,
'show_confidence': True
}
For each processed image, the pipeline generates:
*_annotated.jpg: Image with bounding boxes and labels (disabled visually) and SAM-HQ masksAll outputs are saved to the results/ directory (or custom directory specified with --output).
Returns JSON with bounding box coordinates. Example output:
Normalized Format (Default - Recommended for Frontend):
{
"image_path": "room.jpg",
"image_size": {"width": 1920, "height": 1080},
"vocabulary": ["sofa", "table", "lamp"],
"detections": [
{
"label": "sofa",
"confidence": 1.0,
"bbox": [0.125, 0.342, 0.487, 0.856],
"center": [0.306, 0.599],
"width": 0.362,
"height": 0.514
}
],
"count": 1,
"coordinate_format": "normalized"
}
Coordinate Systems:
JavaScript/Canvas:
// Load detections
const detections = await fetch('detections.json').then(r => r.json());
// Draw on canvas
function drawBoxes(canvas, image, detections) {
const ctx = canvas.getContext('2d');
detections.detections.forEach(det => {
const [x1, y1, x2, y2] = det.bbox;
// Convert normalized to pixels
const x = x1 * image.width;
const y = y1 * image.height;
const w = (x2 - x1) * image.width;
const h = (y2 - y1) * image.height;
ctx.strokeStyle = 'red';
ctx.strokeRect(x, y, w, h);
});
}
React/HTML Overlay:
function BoundingBoxOverlay({ detections }) {
return detections.detections.map((det, i) => {
const [x1, y1, x2, y2] = det.bbox;
return (
<div key={i} style={{
position: 'absolute',
left: `${x1 * 100}%`,
top: `${y1 * 100}%`,
width: `${(x2 - x1) * 100}%`,
height: `${(y2 - y1) * 100}%`,
border: '3px solid red',
pointerEvents: 'none'
}}>
<span style={{color: 'red', fontWeight: 'bold'}}>
{det.label}
</span>
</div>
);
});
}
config.pyThe pipeline can detect 40+ interior object types including:
See config.py for the complete vocabulary list.
This project uses the following open-source models:
Special thanks to:
This project uses models with the following licenses:
Please refer to the respective model repositories for detailed license information.
"CUDA not available" error:
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu124device: 'cpu' in config.pyOut of memory errors:
Poor detection results:
VOCABULARYinterior-segment-labeler/
├── config.py # Configuration and vocabulary
├── segment_image.py # Full pipeline (detection + segmentation)
├── label_changes.py # Detection-only API (NEW)
├── models/
│ └── model.py # Model loading and inference
├── visualization.py # Image annotation utilities
├── utils.py # Helper functions
├── requirements.txt # Python dependencies
└── README.md # This file
| Feature | segment_image.py | label_changes.py |
|---|---|---|
| Detection | ✅ Florence-2 | ✅ Florence-2 |
| Segmentation | ✅ SAM-HQ masks | ❌ None |
| Image Output | Annotated with masks | Annotated with boxes |
| JSON Output | Optional | Default (detections) |
| Coordinates | Pixels | Normalized + Pixels |
| Speed | Slower (~5-10s/image) | Faster (~1-2s/image) |
| Memory | Higher (both models) | Lower (Florence-2 only) |
| Use Case | Segmentation masks | Bounding box highlights |
| Best For | Research, pixel-masks | Web apps, UI overlays |
If you use this tool in your research or project, please cite the original models:
@article{xiao2023florence,
title={Florence-2: Advancing a unified representation for a variety of vision tasks},
author={Xiao, Bin and Wu, Haiping and Xu, Weijian and Dai, Xiyang and Hu, Houdong and Lu, Yumao and Zeng, Michael and Liu, Ce and Yuan, Lu},
journal={arXiv preprint arXiv:2311.06242},
year={2023}
}
@inproceedings{sam_hq,
title={Segment Anything in High Quality},
author={Ke, Lei and Ye, Mingqiao and Danelljan, Martin and Liu, Yifan and Tai, Yu-Wing and Tang, Chi-Keung and Yu, Fisher},
booktitle={NeurIPS},
year={2023}
}
16 commits
Python
100.0%