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

[ONNX] Fix ShuffleNetV2 model export issue. #3158

Merged
merged 6 commits into from
Dec 12, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
11 changes: 11 additions & 0 deletions test/test_onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,17 @@ def test_keypoint_rcnn(self):
dynamic_axes={"images_tensors": [0, 1, 2]},
tolerate_small_mismatch=True)

def test_shufflenet_v2_dynamic_axes(self):
model = models.shufflenet_v2_x0_5(pretrained=True)
dummy_input = torch.randn(1, 3, 224, 224, requires_grad=True)
test_inputs = torch.cat([dummy_input, dummy_input, dummy_input], 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a particular reason to concatenate dummy_input to test_inputs? Can I use test_inputs = torch.randn(3, 3, 224, 224, requires_grad=True)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fatcat-z any thoughts on this? Is it so that we can compare the output by passing dummy_input and test_inputs (as they are equal on both dimensions)?


self.run_model(model, [(dummy_input,), (test_inputs,)],
input_names=["input_images"],
output_names=["output"],
dynamic_axes={"input_images": {0: 'batch_size'}, "output": {0: 'batch_size'}},
tolerate_small_mismatch=True)


if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion torchvision/models/shufflenetv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


def channel_shuffle(x: Tensor, groups: int) -> Tensor:
batchsize, num_channels, height, width = x.data.size()
batchsize, num_channels, height, width = x.shape[0], x.shape[1], x.shape[2], x.shape[3]
fatcat-z marked this conversation as resolved.
Show resolved Hide resolved
channels_per_group = num_channels // groups

# reshape
Expand Down