MCPcopy Create free account
hub / github.com/Topdu/OpenOCR / forward

Method forward

openrec/modeling/decoders/cdistnet_decoder.py:255–274  ·  view source on GitHub ↗
(self, x, data=None)

Source from the content-addressed store, hash-verified

253 self.tgt_word_prj.weight.data.normal_(mean=0.0, std=d_model**-0.5)
254
255 def forward(self, x, data=None):
256 if self.add_conv:
257 x = self.convbnrelu(x)
258 # x = rearrange(x, "b c h w -> b (w h) c")
259 x = x.flatten(2).transpose(1, 2)
260 if self.trans_encoder is not None:
261 x = self.positional_encoding(x)
262 vis_feat = self.trans_encoder(x, src_mask=None)
263 else:
264 vis_feat = x
265 if self.training:
266 max_len = data[1].max()
267 tgt = data[0][:, :1 + max_len]
268 res = self.forward_train(vis_feat, tgt)
269 else:
270 if self.beam_size > 0:
271 res = self.forward_beam(vis_feat)
272 else:
273 res = self.forward_test(vis_feat)
274 return res
275
276 def forward_train(self, vis_feat, tgt):
277 sem_feat, sem_mask = self.semantic_branch(tgt)

Callers

nothing calls this directly

Calls 3

forward_trainMethod · 0.95
forward_beamMethod · 0.95
forward_testMethod · 0.95

Tested by

no test coverage detected