Skip to content

Commit f87d5cc

Browse files
Kevin Chenfacebook-github-bot
authored andcommitted
Fix first reshape in pixel_shuffle conversion (#21486)
Summary: When converting pixel_shuffle to reshape + transpose + reshape, the first reshape should be: [N, C * r^2, H, W] => [N, C, r, r, H, W] in order to match pytorch's implementation (see ATen PixelShuffle.cpp). This previously wasn't caught by the test case, since it uses C = r = 4. Updated test case to have C = 2, r = 4. Pull Request resolved: #21486 Reviewed By: houseroad Differential Revision: D15700945 Pulled By: houseroad fbshipit-source-id: 47019691fdc20e152e867c7f6fd57da104a12948
1 parent fc3f702 commit f87d5cc

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

test/onnx/test_pytorch_onnx_caffe2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,7 @@ def test_instance_norm(self):
11121112

11131113
def test_pixel_shuffle(self):
11141114
underlying = nn.PixelShuffle(4)
1115-
shape = (1, 64, 5, 5)
1115+
shape = (1, 32, 5, 5)
11161116
input = Variable(torch.randn(*shape),
11171117
requires_grad=True)
11181118
self.run_model_test(underlying, train=False, input=(input),

torch/onnx/symbolic_opset9.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,8 +1248,8 @@ def pixel_shuffle(g, self, upscale_factor):
12481248
if len(dims) != 4:
12491249
return _unimplemented("pixel_shuffle", "only support 4d input")
12501250
output_channel = dims[1] // upscale_factor // upscale_factor
1251-
after_view = view(g, self, [-1, upscale_factor, upscale_factor,
1252-
output_channel, dims[2], dims[3]])
1251+
after_view = view(g, self, [-1, output_channel, upscale_factor, upscale_factor,
1252+
dims[2], dims[3]])
12531253
after_transpose = g.op("Transpose", after_view, perm_i=[0, 1, 4, 2, 5, 3])
12541254
return view(g, after_transpose,
12551255
[-1, output_channel, dims[2] * upscale_factor, dims[3] *

0 commit comments

Comments
 (0)