InferenceHandle Struct
Interface for SAM2 automasking inference. More...
Declaration
Included Headers
Derived Structs
| struct | SAM2AutomaskHandle |
|
Default implementation using the pooled SAM2Automask facade. More... | |
Public Destructor Index
| ~InferenceHandle ()=default | |
Public Member Functions Index
| tl::expected< void, std::string > | load (const std::filesystem::path &bundle_manifest, std::string_view runtime_id)=0 |
|
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 =0 |
|
Run SAM2 automasking inference on an image and return the raw mask logits. More... | |
| void | requestTerminate () const =0 |
|
Request termination of any in-flight predict() call. More... | |
| void | clearTerminate () const =0 |
|
Clear a previously-set terminate flag. More... | |
| std::optional< moveit_pro_ml::Device > | servingDevice () const |
|
The device actually serving inference, if known. More... | |
Description
Interface for SAM2 automasking inference.
This interface allows dependency injection of different automasking implementations for testing with GoogleMock.
Definition at line 95 of file sam2_automasking.hpp.
Public Destructor
~InferenceHandle()
| virtual default |
Definition at line 97 of file sam2_automasking.hpp.
Public Member Functions
clearTerminate()
|
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().
Definition at line 148 of file sam2_automasking.hpp.
load()
|
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.
Definition at line 114 of file sam2_automasking.hpp.
predict()
|
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
Definition at line 131 of file sam2_automasking.hpp.
requestTerminate()
|
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.
Definition at line 140 of file sam2_automasking.hpp.
servingDevice()
| inline 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.
Definition at line 155 of file sam2_automasking.hpp.
The documentation for this struct was generated from the following file:
Generated via doxygen2docusaurus 2.2.2 by Doxygen 1.9.8.