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 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
11 changes: 9 additions & 2 deletions onnxconverter_common/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1147,12 +1147,15 @@ def _process_transpose_unsqueeze(node, node_list, node_transpose_pass_name, cur_
if unsqueeze_axes is None:
attrs = {}
else:
unsqueeze_axes = [idx_ + 1 for idx_ in unsqueeze_axes]
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]
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 +1226,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