Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix onnx in latexocr #14910

Open
wants to merge 2 commits into
base: release/2.10
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions ppocr/modeling/heads/rec_latexocr_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,14 +907,7 @@ def generate(
x = out[:, -self.max_seq_len :]
mask = mask[:, -self.max_seq_len :]
logits = self.net(x, mask=mask, **kwargs)[:, -1, :]
if filter_logits_fn in {top_k, top_p}:
filtered_logits = filter_logits_fn(logits, thres=filter_thres)

probs = F.softmax(filtered_logits / temperature, axis=-1)
else:
raise NotImplementedError("The filter_logits_fn is not supported ")

sample = paddle.multinomial(probs, 1)
sample = paddle.argmax(logits, axis=1).reshape([-1, 1])
out = paddle.concat((out, sample), axis=-1)
pad_mask = paddle.full(shape=[mask.shape[0], 1], fill_value=1, dtype="bool")
mask = paddle.concat((mask, pad_mask), axis=1)
Expand Down Expand Up @@ -966,12 +959,7 @@ def generate_export(
logits = self.net(x, mask=mask, context=context, seq_len=i_idx, **kwargs)[
:, -1, :
]
if filter_logits_fn in {top_k, top_p}:
filtered_logits = filter_logits_fn(logits, thres=filter_thres)

probs = F.softmax(filtered_logits / temperature, axis=-1)

sample = paddle.multinomial(probs, 1)
sample = paddle.argmax(logits, axis=1).reshape([-1, 1])
out = paddle.concat((out, sample), axis=-1)

pad_mask = paddle.full(shape=[mask.shape[0], 1], fill_value=1, dtype="bool")
Expand Down