[GRASS-git] [OSGeo/grass-addons] 7f869d: i.sam2: Fix torch import and output raster writing...

Anna Petrasova noreply at github.com
Tue Oct 6 21:28:36 PDT 2026


  Branch: refs/heads/grass8
  Home:   https://github.com/OSGeo/grass-addons
  Commit: 7f869d201c92690d7c9699eab98c9a229c4f3016
      https://github.com/OSGeo/grass-addons/commit/7f869d201c92690d7c9699eab98c9a229c4f3016
  Author: Anna Petrasova <kratochanna at gmail.com>
  Date:   2026-10-07 (Wed, 07 Oct 2026)

  Changed paths:
    M src/imagery/i.sam2/i.sam2.py

  Log Message:
  -----------
  i.sam2: Fix torch import and output raster writing (#1862)

The tool crashed with NameError because torch was imported only as a
local in main() but used in get_device(). After that, the output was
wrong: SamGeo.objects is a single 2D array of object IDs, not a list
of masks, so write_raster iterated over its rows. The text prompt path
returns per-object masks (a tensor for SAM 1, an array for SAM 2), so
merge them into one array of IDs before writing. Write the result as
CELL instead of DCELL. Pass None instead of an empty string as
checkpoint_dir so samgeo uses its default cache rather than the
current directory.

Written with assistance from Claude Code.

Co-authored-by: Corey White <smortopahri at gmail.com>



To unsubscribe from these emails, change your notification settings at https://github.com/OSGeo/grass-addons/settings/notifications


More information about the grass-commit mailing list