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] PARSeq tensorflow fixes #1228

Merged
merged 7 commits into from
Jun 23, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
update decoding
  • Loading branch information
felixdittrich92 committed Jun 23, 2023
commit e9aac295c11ec2864765bd57c84f6e45ccaf378d
9 changes: 6 additions & 3 deletions doctr/models/recognition/parseq/tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,15 @@ def decode_autoregressive(self, features: tf.Tensor, max_len: Optional[int] = No

sos = tf.fill((tf.shape(features)[0], 1), self.vocab_size + 1)
ys = tf.concat([sos, tf.cast(tf.argmax(logits[:, :-1], axis=-1), dtype=tf.int32)], axis=1)
# Create padding mask for refined target input maskes all behind EOS token as False
# Create padding mask for refined target input sequence
# (N, 1, 1, max_length)
target_pad_mask = tf.cast(
tf.expand_dims(tf.expand_dims(tf.not_equal(ys, self.vocab_size), axis=1), axis=1), tf.bool
tf.math.cumsum(tf.cast(tf.equal(ys, self.vocab_size), dtype=tf.int32), axis=-1, reverse=True) > 0,
dtype=tf.bool,
)
mask = tf.math.logical_or(target_pad_mask, query_mask[:, : ys.shape[1]])
target_pad_mask = target_pad_mask[:, tf.newaxis, tf.newaxis, :]

mask = tf.math.logical_and(target_pad_mask, query_mask[:, : ys.shape[1]])
logits = self.head(self.decode(ys, features, mask, target_query=pos_queries, **kwargs), **kwargs)

return logits # (N, max_length, vocab_size + 1)
Expand Down