Skip to content

Add SAM 3 segmentation converter - #838

Open
Irozuku wants to merge 4 commits into
feat/image-embedding-converterfrom
feat/sam3-segment-converter
Open

Add SAM 3 segmentation converter#838
Irozuku wants to merge 4 commits into
feat/image-embedding-converterfrom
feat/sam3-segment-converter

Conversation

@Irozuku

@Irozuku Irozuku commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds a promptable segmentation converter backed by SAM 3. Given a text prompt such as "cow", it detects every matching instance in an image column and appends segment_1..k and seg_score_1..k, where k is max_masks, leaving the row count unchanged. Instances are ranked by descending confidence, and an image with fewer detections leaves the remaining ranks null.


Type of Change

  • Backend change
  • Frontend change
  • CI / Workflow change
  • Build / Packaging change
  • Bug fix
  • Documentation

Changes (by file)

  • DashAI/back/segmenters/base_segmenter.py: SegmentInstance, the mask, score and bbox contract, plus the segmenter interface. Held by composition rather than registered, because ComponentRegistry._get_base_type rejects a class with two Base ancestors declaring a TYPE.
  • DashAI/back/segmenters/rendering.py: renders one detected object as a masked image, with crop_to_bbox and a black, white or blurred background.
  • DashAI/back/segmenters/sam3_segmenter.py: the SAM 3 adapter over Sam3Model and Sam3Processor. Lazily loaded, so constructing the converter never pulls the weights into memory.
  • DashAI/back/converters/segmentation/sam3_segment_converter.py: the converter. Inherits HFPretrainedDownloadMixin for its weights and declares REQUIRED_CREDENTIALS = ["HuggingFaceCredential"], following the Stable Diffusion 3 pattern, since facebook/sam3 is gated.
  • DashAI/back/initial_components.py: registers the converter.
  • pyproject.toml: floors transformers at 5.0.0, which is where Sam3Model landed.
  • tests/back/segmenters/test_rendering.py, tests/back/segmenters/test_base_segmenter.py: cover the mask rendering and the data contract.

Testing

  • Requires a HuggingFace credential in dashAI, the gated terms accepted at https://huggingface.co/facebook/sam3 with that same account, and the weights downloaded, roughly 3.4 GB.
  • Scope the converter to the image column and set image_column to its index within that scope.
  • device defaults to the first GPU when CUDA is present. SAM 3 is a 0.9B model, so CPU is the slow path.
  • Worth checking max_masks above 1 on images with a varying number of objects, which is what produces null ranks.

Notes

The converter and the segmenter themselves are not unit tested here, since exercising them pulls a 3.4 GB gated model. Only the rendering and the data contract are covered.

Detects every instance of a text prompt in an image column and appends
segment_1..k plus seg_score_1..k, where k is max_masks, leaving the row
count unchanged. Instances are ranked by descending confidence and an
image with fewer detections leaves the remaining ranks null.

SAM 3 is a gated HuggingFace model, so the converter declares
REQUIRED_CREDENTIALS and inherits HFPretrainedDownloadMixin for its
weights, following the Stable Diffusion 3 pattern. Sam3Model needs
transformers 5, hence the dependency floor.

BaseSegmenter is held by composition rather than registered, because the
component registry rejects a class with two Base ancestors declaring a
TYPE. Tests cover the abstraction and the mask rendering; the converter
and the segmenter themselves are left untested here since they pull a
3.4 GB gated model.
The segmenter already accepted a device and auto-picked CUDA when
available, but the converter never exposed the choice, so a user could
not force CPU or select a GPU. It now carries the same DEVICE_ENUM field
the image embedding converter uses, listing the machine's real GPUs, and
resolves the label to a torch device string before handing it to the
segmenter.
@Irozuku Irozuku added enhancement New feature or request back Backend work labels Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

back Backend work enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant