MCPcopy Create free account
hub / github.com/ImprintLab/Medical-SAM2 / forward_image

Method forward_image

sam2_train/modeling/sam2_base.py:463–475  ·  view source on GitHub ↗

Get the image feature on the input batch.

(self, img_batch: torch.Tensor)

Source from the content-addressed store, hash-verified

461 )
462
463 def forward_image(self, img_batch: torch.Tensor):
464 """Get the image feature on the input batch."""
465 backbone_out = self.image_encoder(img_batch)
466 if self.use_high_res_features_in_sam:
467 # precompute projected level 0 and level 1 features in SAM decoder
468 # to avoid running it again on every SAM click
469 backbone_out["backbone_fpn"][0] = self.sam_mask_decoder.conv_s0(
470 backbone_out["backbone_fpn"][0]
471 )
472 backbone_out["backbone_fpn"][1] = self.sam_mask_decoder.conv_s1(
473 backbone_out["backbone_fpn"][1]
474 )
475 return backbone_out
476
477 def _prepare_backbone_features(self, backbone_out):
478 """Prepare and flatten visual features."""

Callers 5

train_samFunction · 0.80
validation_samFunction · 0.80
set_imageMethod · 0.80
set_image_batchMethod · 0.80
_get_image_featureMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected