MCPcopy Create free account
hub / github.com/SLDGroup/MERIT / forward

Method forward

lib/models_timm/layers/ml_decoder.py:136–156  ·  view source on GitHub ↗
(self, x)

Source from the content-addressed store, hash-verified

134 self.group_fc = GroupFC(embed_len_decoder)
135
136 def forward(self, x):
137 if len(x.shape) == 4: # [bs,2048, 7,7]
138 embedding_spatial = x.flatten(2).transpose(1, 2)
139 else: # [bs, 197,468]
140 embedding_spatial = x
141 embedding_spatial_786 = self.embed_standart(embedding_spatial)
142 embedding_spatial_786 = torch.nn.functional.relu(embedding_spatial_786, inplace=True)
143
144 bs = embedding_spatial_786.shape[0]
145 query_embed = self.query_embed.weight
146 # tgt = query_embed.unsqueeze(1).repeat(1, bs, 1)
147 tgt = query_embed.unsqueeze(1).expand(-1, bs, -1) # no allocation of memory with expand
148 h = self.decoder(tgt, embedding_spatial_786.transpose(0, 1)) # [embed_len_decoder, batch, 768]
149 h = h.transpose(0, 1)
150
151 out_extrap = torch.zeros(h.shape[0], h.shape[1], self.duplicate_factor, device=h.device, dtype=h.dtype)
152 self.group_fc(h, self.duplicate_pooling, out_extrap)
153 h_out = out_extrap.flatten(1)[:, :self.num_classes]
154 h_out += self.duplicate_pooling_bias
155 logits = h_out
156 return logits

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected