Skip to main content

SAM2AutomaskHandle Struct

Default implementation using the pooled SAM2Automask facade. More...

Declaration

struct moveit_pro::behaviors::GetMasks2DAutomask::SAM2AutomaskHandle { ... }

Included Headers

#include <sam2_automasking.hpp>

Base struct

structInferenceHandle

Interface for SAM2 automasking inference. More...

Public Member Functions Index

tl::expected< void, std::string >load (const std::filesystem::path &bundle_manifest, std::string_view runtime_id) override

Load a runtime variant from a SAM2 automask model bundle. More...

tl::expected< moveit_pro_ml::SAM2Automask::Result, std::string >predict (const moveit_pro_ml::data::Tensor< float, moveit_pro_ml::data::format::NCHW > &image, int grid_size, float score_threshold) const override

Run SAM2 automasking inference on an image and return the raw mask logits. More...

voidrequestTerminate () const override

Request termination of any in-flight predict() call. More...

voidclearTerminate () const override

Clear a previously-set terminate flag. More...

std::optional< moveit_pro_ml::Device >servingDevice () const override

The device actually serving inference, if known. More...

Public Member Attributes Index

std::shared_ptr< moveit_pro_ml::SAM2Automask >model
moveit_pro_ml::model::RunControlcontrol

Description

Default implementation using the pooled SAM2Automask facade.

Definition at line 164 of file sam2_automasking.hpp.

Public Member Functions

clearTerminate()

void moveit_pro::behaviors::GetMasks2DAutomask::SAM2AutomaskHandle::clearTerminate ()
virtual

Clear a previously-set terminate flag.

Must be called before predict() if the previous predict() was halted, otherwise the next run aborts immediately. The behavior calls this at the start of doWork() before signalling that halt is allowed via notifyCanHalt().

Declaration at line 175 of file sam2_automasking.hpp, definition at line 195 of file sam2_automasking.cpp.

load()

tl::expected< void, std::string > moveit_pro::behaviors::GetMasks2DAutomask::SAM2AutomaskHandle::load (const std::filesystem::path & bundle_manifest, std::string_view runtime_id)
virtual

Load a runtime variant from a SAM2 automask model bundle.

This method is idempotent: if a model is already loaded it returns immediately. The model therefore latches for the handle's lifetime — the arguments are read on the first call only.

That means this is not the place a changed bundle or runtime is detected. The caller compares the ports against what it latched and fails the Behavior, because swapping models mid-run would stall an Objective in an uninterruptible multi-second load while ignoring the change would keep serving masks from a bundle the tree no longer asks for.

Parameters
bundle_manifest

Path to the relocatable versioned bundle manifest.

runtime_id

Runtime variant to select from the bundle.

Returns

An error message if model initialization fails.

Declaration at line 166 of file sam2_automasking.hpp, definition at line 151 of file sam2_automasking.cpp.

predict()

tl::expected< moveit_pro_ml::SAM2Automask::Result, std::string > moveit_pro::behaviors::GetMasks2DAutomask::SAM2AutomaskHandle::predict (const moveit_pro_ml::data::Tensor< float, moveit_pro_ml::data::format::NCHW > & image, int grid_size, float score_threshold)
virtual

Run SAM2 automasking inference on an image and return the raw mask logits.

Returns the unprocessed inferred logits/masks for every grid point scoring at or above score_threshold. Post-processing (NMS, splitting connected components, upscaling to the original resolution) is performed separately by the behavior via refineAndSplit(); it does not happen inside this call.

Parameters
image

Image data in NCHW format [1, 3, H, W] (RGB float normalized to [0,1])

grid_size

Grid size for point generation (e.g., 11 = 11x11 = 121 points)

score_threshold

Minimum score to keep masks (0.0 to 1.0)

Returns

Raw inferred mask logits for all points in the grid

Declaration at line 170 of file sam2_automasking.hpp, definition at line 172 of file sam2_automasking.cpp.

requestTerminate()

void moveit_pro::behaviors::GetMasks2DAutomask::SAM2AutomaskHandle::requestTerminate ()
virtual

Request termination of any in-flight predict() call.

Thread-safe; intended to be called from the behavior's doHalt() handler while another thread is blocked inside predict(). The terminate flag is sticky; the caller is responsible for calling clearTerminate() before the next predict() so a stale flag does not abort it.

Declaration at line 173 of file sam2_automasking.hpp, definition at line 190 of file sam2_automasking.cpp.

servingDevice()

std::optional< moveit_pro_ml::Device > moveit_pro::behaviors::GetMasks2DAutomask::SAM2AutomaskHandle::servingDevice ()
virtual

The device actually serving inference, if known.

Defaults to unknown so test doubles need not implement it. The behavior uses this to surface an operator-facing warning when inference silently fell back to CPU.

Declaration at line 177 of file sam2_automasking.hpp, definition at line 203 of file sam2_automasking.cpp.

Public Member Attributes

control

moveit_pro_ml::model::RunControl moveit_pro::behaviors::GetMasks2DAutomask::SAM2AutomaskHandle::control
mutable

Definition at line 180 of file sam2_automasking.hpp.

model

std::shared_ptr<moveit_pro_ml::SAM2Automask> moveit_pro::behaviors::GetMasks2DAutomask::SAM2AutomaskHandle::model

Definition at line 179 of file sam2_automasking.hpp.


The documentation for this struct was generated from the following files:


Generated via doxygen2docusaurus 2.2.2 by Doxygen 1.9.8.