Skip to content
data

InstanceSegmentationOutput

extendsModelOutput
InstanceSegmentationOutput(logits: Tensor, pred_boxes: Tensor, pred_masks: Tensor, loss: Tensor | None = None, hidden_states: tuple[Tensor, ...] | None = None, proposals: tuple[Tensor, ...] | None = None, input_size: tuple[int, int] | None = None)

Output of any instance-segmentation model.

Attributes

logitsTensor
Per-proposal class logits.
pred_boxesTensor
Predicted bounding boxes.
pred_masksTensor
Per-instance binary mask logits, typically shape (N, num_classes, mh, mw) for R-CNN-style or (B, num_queries, H, W) for transformer-based instance heads.
loss(Tensor or None, optional)
Total loss (cls + box + mask) when targets were supplied.
hidden_states(tuple[Tensor, ...] or None, optional)
Optional intermediate feature maps.
proposals(tuple[Tensor, ...] or None, optional)
Per-image RoI proposals used by forward. Carried out for the same reason Faster R-CNN carries them: postprocess needs the proposal boxes to map rows of pred_boxes / pred_masks back to images, and when forward generated the proposals itself the caller has no other way to supply them.
input_size(tuple[int, int] or None, optional)
(H, W) of the image batch forward ran on. Mask R-CNN derives its pyramid strides from it, and postprocess must use the same ones to re-align masks on the final boxes; the feature maps alone do not pin it down (every height from 97 to 100 gives a 25-row P2, and the strides differ across them).

Notes

Returned today by Mask R-CNN; Mask2Former when configured for instance segmentation will also produce this shape.

Examples

>>> import lucid
>>> from lucid.models import InstanceSegmentationOutput
>>> out = InstanceSegmentationOutput(
...     logits=lucid.zeros(1, 100, 81),
...     pred_boxes=lucid.zeros(1, 100, 4),
...     pred_masks=lucid.zeros(1, 100, 28, 28),
... )
>>> out.pred_masks.shape          # one mask per detection
(1, 100, 28, 28)

Used by 2