Skip to content

change repeat to repeat_interleave #792

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

Merged
merged 2 commits into from
Feb 14, 2025
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
5 changes: 3 additions & 2 deletions mindocr/models/backbones/mindcv_models/repmlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,9 @@ def local_inject(self):
self.fc3.bias.data = fc3_bias

def _convert_conv_to_fc(self, conv_kernel, conv_bias):
I = ops.eye(self.h * self.w).repeat(1, self.S).reshape(self.h * self.w, self.S, self.h, self.w) # noqa: E741
fc_k = ops.Conv2D(I, conv_kernel, pad=(conv_kernel.size(2) // 2, conv_kernel.size(3) // 2), group=self.S)
# noqa: E741
x = ops.eye(self.h * self.w).repeat_interleave(1, self.S).reshape(self.h * self.w, self.S, self.h, self.w)
fc_k = ops.Conv2D(x, conv_kernel, pad=(conv_kernel.size(2) // 2, conv_kernel.size(3) // 2), group=self.S)
fc_k = fc_k.reshape(self.h * self.w, self.S * self.h * self.w).t()
fc_bias = conv_bias.repeat_interleave(self.h * self.w)
return fc_k, fc_bias
Expand Down
4 changes: 2 additions & 2 deletions mindocr/models/heads/kie_relationextraction_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ def __init__(self, hidden_size=768, hidden_dropout_prob=0.1, use_float16: bool =
def construct(self, hidden_states, question, question_label, answer, answer_label):
__, _, hidden_size = hidden_states.shape
q_label_repr = self.entity_emb(question_label)
question = question.expand_dims(-1).repeat(hidden_size, -1)
question = question.expand_dims(-1).repeat_interleave(hidden_size, -1)
tmp_hidden_states = ops.gather_d(hidden_states, 1, question)
q_repr = ops.concat((tmp_hidden_states, q_label_repr), axis=-1)

a_label_repr = self.entity_emb(answer_label)
answer = answer.expand_dims(-1).repeat(hidden_size, -1)
answer = answer.expand_dims(-1).repeat_interleave(hidden_size, -1)
tmp_hidden_states = ops.gather_d(hidden_states, 1, answer)
a_repr = ops.concat((tmp_hidden_states, a_label_repr), axis=-1)

Expand Down
2 changes: 1 addition & 1 deletion mindocr/models/heads/rec_robustscanner_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def construct(self, query, key, value, h, w, valid_width_masks=None):
logits_i = logits[i].squeeze(0) # (c, h, w)
logits_i = logits_i.view((-1, w)) # (c*h, w)
ch = c * h
valid_width_mask = valid_width_mask.repeat(ch, axis=0) # (c*h, w)
valid_width_mask = valid_width_mask.repeat_interleave(ch, 0) # (c*h, w)
valid_width_mask = ops.cast(valid_width_mask, ms.bool_)
logits_i = ops.select(valid_width_mask, logits_i, float('-inf')) # (c*h, w)
logits_list.append(logits_i.view((c, h, w))) # (c, h, w)
Expand Down
2 changes: 1 addition & 1 deletion mindocr/models/heads/rec_sar_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def _2d_attention(self,
attn_weight_i = attn_weight_i.transpose((0, 1, 3, 2)) # (T, h, c, w)
attn_weight_i = attn_weight_i.view((-1, w)) # (T*h*c, w)
Tch = T * h * c
valid_width_mask = valid_width_mask.repeat(Tch, axis=0) # (T*h*c, w)
valid_width_mask = valid_width_mask.repeat_interleave(Tch, 0) # (T*h*c, w)
valid_width_mask = ops.cast(valid_width_mask, ms.bool_)
attn_weight_i = ops.select(
valid_width_mask, attn_weight_i.astype(ms.float32), float('-inf')) # (T*h*c, w)
Expand Down
2 changes: 1 addition & 1 deletion mindocr/models/heads/rec_visionlan_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def __init__(self, n_dim: int = 512, N_max_character: int = 25, n_position: int
def construct(self, enc_output):
# enc_output: b,256,512
reading_order = Tensor(np.arange(self.character_len), dtype=ms.int64)
reading_order = mnp.repeat(reading_order[None, ...], enc_output.shape[0], 0) # (S,) -> (B, S)
reading_order = ops.repeat_interleave(reading_order[None, ...], enc_output.shape[0], 0) # (S,) -> (B, S)
reading_order = self.f0_embedding(reading_order) # b,max_len,512
# calculate attention
t = self.w0(reading_order.transpose((0, 2, 1))) # b,512,256
Expand Down
Loading