Skip to content

feat(detections): ✨ paligemma segmentation support added - #1663

Draft
onuralpszr wants to merge 2 commits into
developfrom
feat/paligemma_segmentation
Draft

onuralpszr wants to merge 2 commits into
developfrom
feat/paligemma_segmentation

Conversation

@onuralpszr

Copy link
Copy Markdown
Contributor

Description

This PR adding PaliGemma Segmentation parse ability to conver to detections masks

Type of change

  • New feature (non-breaking change which adds functionality)

@onuralpszr
onuralpszr requested a review from LinasKo November 8, 2024 06:47
@onuralpszr onuralpszr self-assigned this Nov 8, 2024
@onuralpszr
onuralpszr force-pushed the feat/paligemma_segmentation branch from 6c4bd86 to 1aeb573 Compare November 8, 2024 06:52
Signed-off-by: Onuralp SEZER <thunderbirdtr@gmail.com>
@onuralpszr
onuralpszr force-pushed the feat/paligemma_segmentation branch from 1aeb573 to 5fdb3fb Compare November 8, 2024 06:59
@onuralpszr
onuralpszr marked this pull request as ready for review November 8, 2024 07:01
@Borda
Borda requested a review from SkalskiP as a code owner January 7, 2026 17:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Segmentation tokens currently produce only empty masks, malformed records may be accepted, and the new behavior lacks tests.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds parsing of PaliGemma segmentation outputs into Detections.

Changes:

  • Parses segmentation tokens and returns masks.
  • Passes parsed masks into Detections.
File summaries
File Description
supervision/detection/lmm.py Adds segmentation parsing and mask output.
supervision/detection/core.py Propagates masks into Detections.
Review details

Suppressed comments (1)

supervision/detection/lmm.py:105

  • The parsed seg_tokens never affect masks, so every valid segmentation is returned as an all-false image-sized mask. Decode each 16-token code with the PaliGemma segmentation decoder and map the decoded mask into its bounding box before returning it; otherwise this feature silently reports empty segmentations.
        seg_tokens = matches[:, 4:-1].astype(int)
        masks = [np.zeros((h, w), dtype=bool) for tokens in seg_tokens]
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

class_name = np.char.strip(class_name.astype(str))
class_id = None
segmentation_pattern = re.compile(
r"<loc(\d{4})><loc(\d{4})><loc(\d{4})><loc(\d{4})>\s*"
Comment on lines +99 to +100
segmentation_matches = segmentation_pattern.findall(result)
if segmentation_matches:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants