Implementation:Datajuicer Data juicer ImageSegmentMapper
| Knowledge Sources | |
|---|---|
| Domains | Data_Processing, Mapping |
| Last Updated | 2026-02-14 16:00 GMT |
Overview
Concrete tool for performing segment-anything on images using FastSAM provided by Data-Juicer.
Description
ImageSegmentMapper is a mapper operator that uses a FastSAM model (FastSAM-x.pt or FastSAM-s.pt) via the ultralytics library to detect and segment objects in images, returning their bounding boxes. It processes each image with configurable resolution, confidence threshold, and IoU threshold. Bounding boxes in xywh format are extracted from retina masks output and stored in the sample's metadata under bbox_tag as N x M x 4 arrays (N images, M boxes, 4 coordinates). Requires CUDA acceleration and approximately 800MB of GPU memory.
Usage
Use when you need region-level annotations for images, understanding spatial composition, detecting objects of interest, and supporting downstream image analysis tasks in multimodal data pipelines.
Code Reference
Source Location
- Repository: Datajuicer_Data_juicer
- File: data_juicer/ops/mapper/image_segment_mapper.py
Signature
@OPERATORS.register_module("image_segment_mapper")
class ImageSegmentMapper(Mapper):
def __init__(self,
imgsz=1024,
conf=0.05,
iou=0.5,
model_path="FastSAM-x.pt",
*args, **kwargs):
Import
from data_juicer.ops.mapper.image_segment_mapper import ImageSegmentMapper
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| imgsz | int | No | Resolution for image resizing, defaults to 1024 |
| conf | float | No | Confidence score threshold, defaults to 0.05 |
| iou | float | No | IoU (Intersection over Union) score threshold, defaults to 0.5 |
| model_path | str | No | Path to FastSAM model: FastSAM-x.pt or FastSAM-s.pt; defaults to "FastSAM-x.pt" |
Outputs
| Name | Type | Description |
|---|---|---|
| samples | Dict | Transformed samples with bounding boxes stored in meta field under bbox_tag |
Usage Examples
process:
- image_segment_mapper:
imgsz: 1024
conf: 0.05
iou: 0.5
model_path: "FastSAM-x.pt"