MCPcopy Create free account
hub / github.com/InternRobotics/G2VLM / forward

Method forward

eval_code/recons/models/moge/model/modules.py:111–127  ·  view source on GitHub ↗
(self, image: torch.Tensor, token_rows: int, token_cols: int, return_class_token: bool = False)

Source from the content-addressed store, hash-verified

109 wrap_dinov2_attention_with_sdpa(self.backbone.blocks[i].attn)
110
111 def forward(self, image: torch.Tensor, token_rows: int, token_cols: int, return_class_token: bool = False) -> Tuple[torch.Tensor, torch.Tensor]:
112 image_14 = F.interpolate(image, (token_rows * 14, token_cols * 14), mode="bilinear", align_corners=False, antialias=True)
113 image_14 = (image_14 - self.image_mean) / self.image_std
114
115 # Get intermediate layers from the backbone
116 features = self.backbone.get_intermediate_layers(image_14, n=self.intermediate_layers, return_class_token=True)
117
118 # Project features to the desired dimensionality
119 x = torch.stack([
120 proj(feat.permute(0, 2, 1).unflatten(2, (token_rows, token_cols)).contiguous())
121 for proj, (feat, clstoken) in zip(self.output_projections, features)
122 ], dim=1).sum(dim=1)
123
124 if return_class_token:
125 return x, features[-1][1]
126 else:
127 return x
128
129
130class Resampler(nn.Sequential):

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected