(self, x)
| 115 | |
| 116 | |
| 117 | def forward_flex(self, x): |
| 118 | b, c, h, w = x.shape |
| 119 | |
| 120 | pos_embed = self._resize_pos_embed( |
| 121 | self.pos_embed, h // self.patch_size[1], w // self.patch_size[0] |
| 122 | ) |
| 123 | |
| 124 | B = x.shape[0] |
| 125 | |
| 126 | if hasattr(self.patch_embed, "backbone"): |
| 127 | x = self.patch_embed.backbone(x) |
| 128 | if isinstance(x, (list, tuple)): |
| 129 | x = x[-1] # last feature if backbone outputs list/tuple of features |
| 130 | |
| 131 | x = self.patch_embed.proj(x).flatten(2).transpose(1, 2) |
| 132 | |
| 133 | if getattr(self, "dist_token", None) is not None: |
| 134 | cls_tokens = self.cls_token.expand( |
| 135 | B, -1, -1 |
| 136 | ) # stole cls_tokens impl from Phil Wang, thanks |
| 137 | dist_token = self.dist_token.expand(B, -1, -1) |
| 138 | x = torch.cat((cls_tokens, dist_token, x), dim=1) |
| 139 | else: |
| 140 | cls_tokens = self.cls_token.expand( |
| 141 | B, -1, -1 |
| 142 | ) # stole cls_tokens impl from Phil Wang, thanks |
| 143 | x = torch.cat((cls_tokens, x), dim=1) |
| 144 | |
| 145 | x = x + pos_embed |
| 146 | x = self.pos_drop(x) |
| 147 | |
| 148 | for blk in self.blocks: |
| 149 | x = blk(x) |
| 150 | |
| 151 | x = self.norm(x) |
| 152 | |
| 153 | return x |
| 154 | |
| 155 | |
| 156 | activations = {} |
nothing calls this directly
no outgoing calls
no test coverage detected