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

Method forward

sam2_train/modeling/memory_encoder.py:158–181  ·  view source on GitHub ↗
(
        self,
        pix_feat: torch.Tensor,
        masks: torch.Tensor,
        skip_mask_sigmoid: bool = False,
    )

Source from the content-addressed store, hash-verified

156 self.out_proj = nn.Conv2d(in_dim, out_dim, kernel_size=1)
157
158 def forward(
159 self,
160 pix_feat: torch.Tensor,
161 masks: torch.Tensor,
162 skip_mask_sigmoid: bool = False,
163 ) -> Tuple[torch.Tensor, torch.Tensor]:
164 ## Process masks
165 # sigmoid, so that less domain shift from gt masks which are bool
166 if not skip_mask_sigmoid:
167 masks = F.sigmoid(masks)
168 masks = self.mask_downsampler(masks)
169
170 ## Fuse pix_feats and downsampled masks
171 # in case the visual features are on CPU, cast them to CUDA
172 pix_feat = pix_feat.to(masks.device)
173
174 x = self.pix_feat_proj(pix_feat)
175 x = x + masks
176 x = self.fuser(x)
177 x = self.out_proj(x)
178
179 pos = self.position_encoding(x).to(x.dtype)
180
181 return {"vision_features": x, "vision_pos_enc": [pos]}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected