darktable-org / darktable-org/darktable

Fix for the multiple-click issue in SegNext (non-SAM AI masks)

Open
#21,451 4 comments 0 reactions 1 assignee View on GitHub

@andriiryzhkov is already working on this.

Since Jun 29, 2026.

reproduce: peculiar scope: AI features
Dominant language
C
Stars
13.1k
Forks
1.4k
Avg merge
22h 14m
Merged PRs (30d)
198

Description

Hello,

Issue: In darktable 5.6, the SegNext model (mask-object-segnext-b2hq) only works with a single click. Unlike SAM, it is not possible to add additional points to refine the mask using additional clicks.
Ro-models ot cause: The SAM decoder has a has_mask_input flag that tells it whether to use the previous mask as context for iterative refinement. The SegNext ONNX graph does not include this flag: the previous mask is always passed to the decoder, making it impossible to distinguish a new prediction from a refinement pass. On a second click, the decoder receives two conflicting signals (new point + obsolete previous mask) and is unable to interpret them.
Fix (10 lines in src/develop/masks/object.c): For SegNext, reset the previous mask to zero before each call to the decoder.

Conclusion: Only one change is needed: in “src/develop/masks/object.c,” two blocks in _run_decoder():
Block 1 — Conditional reset of prev_mask (beginning of _run_decoder)
Replace:

  if(gui->guipoints_count <= 1 && !d->has_selection)
    dt_seg_reset_prev_mask(d->seg);

with :

  if(dt_seg_supports_box(d->seg))
  {
    // SAM: use has_mask_input flag for iterative refinement
    if(gui->guipoints_count <= 1 && !d->has_selection)
      dt_seg_reset_prev_mask(d->seg);
  }
  else
  {
    // SegNext: no has_mask_input flag, always start fresh
    dt_seg_reset_prev_mask(d->seg);
  }

Block 2 — reset in the self-refinement loop (beginning of the for loop) Add just before float *new_mask = dt_seg_compute_mask(...):

if(!dt_seg_supports_box(d->seg))
  dt_seg_reset_prev_mask(d->seg);

What do you think?

Greetings from the Luberon,
Christian

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.