mask_layer
sleap_nn.inference.sam.mask_layer
¶
SAM mask inference layer — the producer that emits PredictedSegmentationMask.
:class:SamSegmentationLayer is the full-frame producer. Given a backend, a
prompt mode, and the per-frame poses/centroids, it encodes each frame once,
builds one :class:~sleap_nn.inference.sam.prompts.SamPrompt per instance,
asks the backend for masks, and emits Outputs.pred_masks dicts at the
correct full-frame offset/scale with instance=/track= populated
(PLAN L8). Output collection / SLP packaging is free — it reuses
Outputs.to_masks -> build_predicted_segmentation_mask ->
labels.save exactly like every other seg layer (PLAN §2.5).
It is torch-light: it shells out to a :class:MaskBackend (SAM1 here, SAM3
later). The heavy SAM import lives in the backend.
Classes:
| Name | Description |
|---|---|
SamSegmentationLayer |
Full-frame SAM mask producer (pose / centroid / box prompts). |
SamSegmentationLayer
¶
Full-frame SAM mask producer (pose / centroid / box prompts).
Operates on in-memory sio.LabeledFrame content (image + pose/centroid
instances), not on a torch model — there is no trained net here. For each
frame it encodes the image once via the backend, builds one prompt per
instance, and emits per-frame Outputs.pred_masks dicts that the standard
Outputs.to_masks path packages into sio.PredictedSegmentationMask.
Full-frame masks use identity scale/offset (the whole-frame
representation the P1 prototype produced).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
MaskBackend
|
A :class: |
required |
prompt_mode
|
str
|
One of |
'pose'
|
anchor_ind
|
Optional[int]
|
Optional skeleton node index used as the centroid anchor for
|
None
|
disjointify_masks
|
bool
|
When |
False
|
Methods:
| Name | Description |
|---|---|
__init__ |
Stash the backend and prompt knobs. |
masks_for_frame |
Produce one |
predict_labels |
Build |
Source code in sleap_nn/inference/sam/mask_layer.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
__init__(backend, prompt_mode='pose', anchor_ind=None, disjointify_masks=False)
¶
Stash the backend and prompt knobs.
Source code in sleap_nn/inference/sam/mask_layer.py
masks_for_frame(image, instances)
¶
Produce one pred_masks dict per posed instance for a frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
The frame image ( |
required | |
instances
|
Sequence
|
The frame's |
required |
Returns:
| Type | Description |
|---|---|
List[dict]
|
A list of |
Source code in sleap_nn/inference/sam/mask_layer.py
predict_labels(labels)
¶
Build pred_masks for every labeled frame of a sio.Labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
The source |
required |
Returns:
| Type | Description |
|---|---|
'List[List[dict]]'
|
A list (one entry per labeled frame) of the frame's |