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 axes and perm in _process_transpose_unsqueeze #99

Merged
merged 3 commits into from
Apr 30, 2020
Merged
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
26 changes: 15 additions & 11 deletions onnxconverter_common/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1120,11 +1120,8 @@ def _process_transpose_pad(node, node_list, node_transpose_pass_name, cur_perm_m
def _process_transpose_squeeze(node, node_list, node_transpose_pass_name, cur_perm_map):
cur_perm = cur_perm_map[node.get_precedence_by_idx(0).unique_name]
squeeze_axes = node.get_attribute('axes')
if squeeze_axes is None:
attrs = {}
else:
squeeze_axes = [cur_perm[idx_] for idx_ in squeeze_axes]
attrs = {'axes': squeeze_axes}
squeeze_axes = [cur_perm[idx_] for idx_ in squeeze_axes]
attrs = {'axes': squeeze_axes}
temp_perm = cur_perm.copy()
sub_list = [0] * len(cur_perm)
for axis in squeeze_axes:
Expand All @@ -1144,15 +1141,18 @@ def _process_transpose_squeeze(node, node_list, node_transpose_pass_name, cur_pe

def _process_transpose_unsqueeze(node, node_list, node_transpose_pass_name, cur_perm_map):
unsqueeze_axes = node.get_attribute('axes')
if unsqueeze_axes is None:
attrs = {}
else:
unsqueeze_axes = [idx_ + 1 for idx_ in unsqueeze_axes]
attrs = {'axes': unsqueeze_axes}
assert len(unsqueeze_axes) == 1
attrs = {'axes': unsqueeze_axes}
new_node_name = node.origin.name + '_unsqueeze_' + str(PushTransposeSolution.transpose_number)
node.origin = helper.make_node('Unsqueeze', node.origin.input, node.origin.output, new_node_name, **attrs)
PushTransposeSolution.transpose_number += 1
cur_perm_map[node.unique_name] = [0, 2, 3, 1]
prev_perm = cur_perm_map[node.precedence[0].unique_name]
cur_axes = unsqueeze_axes[0]
if cur_axes < 0:
cur_axes += len(prev_perm)
prev_perm_adjust = [idx_ + 1 if idx_ >= cur_axes else idx_ for idx_ in prev_perm]
target_perm = prev_perm_adjust[0:cur_axes] + [cur_axes] + prev_perm_adjust[cur_axes:]
cur_perm_map[node.unique_name] = target_perm
return cur_perm_map


Expand Down Expand Up @@ -1223,6 +1223,10 @@ def apply(self, node_list):
success = _check_transpose_pass_broadcast(node, node_list, node_transpose_pass_name, cur_perm_map)
if not success:
return None, False
elif node.origin.op_type == 'Unsqueeze':
unsqueeze_axes = node.get_attribute('axes')
if unsqueeze_axes and len(unsqueeze_axes) > 1:
return None, False

for node_pair_ in node_transpose_pass:
(node, prev) = node_pair_
Expand Down