Skip to content

Commit b77e6b6

Browse files
update magc mean std and small improvements
1 parent 2d8d834 commit b77e6b6

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

doctr/models/classification/magc_resnet/tensorflow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323

2424
default_cfgs: Dict[str, Dict[str, Any]] = {
2525
'magc_resnet31': {
26-
'mean': (0.5, 0.5, 0.5),
27-
'std': (1., 1., 1.),
26+
'mean': (0.694, 0.695, 0.693),
27+
'std': (0.299, 0.296, 0.301),
2828
'input_shape': (32, 32, 3),
2929
'classes': list(VOCABS['french']),
3030
'url': None,

doctr/models/recognition/master/tensorflow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def call(
169169
# (N, H, W, C) --> (N, H * W, C)
170170
feature = tf.reshape(feature, shape=(b, h * w, c))
171171
# add positional encoding to features
172-
encoded = self.positional_encoding(feature)
172+
encoded = self.positional_encoding(feature, **kwargs)
173173

174174
out: Dict[str, tf.Tensor] = {}
175175

doctr/models/recognition/transformer/tensorflow.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def scaled_dot_product_attention(
6060
) -> Tuple[tf.Tensor, tf.Tensor]:
6161
""" Scaled Dot-Product Attention """
6262

63-
scores = tf.matmul(query, key, transpose_b=True) / math.sqrt(query.shape[-1])
63+
scores = tf.matmul(query, tf.transpose(key, perm=[0, 1, 3, 2])) / math.sqrt(query.shape[-1])
6464
if mask is not None:
6565
scores = tf.where(mask == 0, -1e9, scores)
6666
p_attn = tf.nn.softmax(scores, axis=-1)
@@ -88,7 +88,7 @@ class MultiHeadAttention(layers.Layer, NestedObject):
8888

8989
def __init__(self, num_heads: int, d_model: int, dropout: float = 0.1) -> None:
9090
super().__init__()
91-
assert d_model % num_heads == 0
91+
assert d_model % num_heads == 0, "d_model must be divisible by num_heads"
9292

9393
self.d_k = d_model // num_heads
9494
self.num_heads = num_heads
@@ -158,7 +158,7 @@ def call(
158158
) -> tf.Tensor:
159159

160160
tgt = self.embed(tgt, **kwargs) * math.sqrt(self.d_model)
161-
pos_enc_tgt = self.positional_encoding(tgt)
161+
pos_enc_tgt = self.positional_encoding(tgt, **kwargs)
162162
output = pos_enc_tgt
163163

164164
for i in range(self.num_layers):

0 commit comments

Comments
 (0)