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] Prob comp in vitstr and parseq for empty words #1345

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion doctr/models/recognition/parseq/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,9 @@ def __call__(
for encoded_seq in out_idxs.cpu().numpy()
]
# compute probabilties for each word up to the EOS token
probs = [preds_prob[i, : len(word)].clip(0, 1).mean().item() for i, word in enumerate(word_values)]
probs = [
preds_prob[i, : len(word)].clip(0, 1).mean().item() if word else 0.0 for i, word in enumerate(word_values)
]

return list(zip(word_values, probs))

Expand Down
5 changes: 4 additions & 1 deletion doctr/models/recognition/parseq/tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,10 @@ def __call__(
word_values = [word.decode() for word in decoded_strings_pred.numpy().tolist()]

# compute probabilties for each word up to the EOS token
probs = [preds_prob[i, : len(word)].numpy().clip(0, 1).mean().item() for i, word in enumerate(word_values)]
probs = [
preds_prob[i, : len(word)].numpy().clip(0, 1).mean().item() if word else 0.0
for i, word in enumerate(word_values)
]

return list(zip(word_values, probs))

Expand Down
4 changes: 3 additions & 1 deletion doctr/models/recognition/vitstr/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ def __call__(
for encoded_seq in out_idxs.cpu().numpy()
]
# compute probabilties for each word up to the EOS token
probs = [preds_prob[i, : len(word)].clip(0, 1).mean().item() for i, word in enumerate(word_values)]
probs = [
preds_prob[i, : len(word)].clip(0, 1).mean().item() if word else 0.0 for i, word in enumerate(word_values)
]

return list(zip(word_values, probs))

Expand Down
5 changes: 4 additions & 1 deletion doctr/models/recognition/vitstr/tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ def __call__(
word_values = [word.decode() for word in decoded_strings_pred.numpy().tolist()]

# compute probabilties for each word up to the EOS token
probs = [preds_prob[i, : len(word)].numpy().clip(0, 1).mean().item() for i, word in enumerate(word_values)]
probs = [
preds_prob[i, : len(word)].numpy().clip(0, 1).mean().item() if word else 0.0
for i, word in enumerate(word_values)
]

return list(zip(word_values, probs))

Expand Down