Skip to content

Instantly share code, notes, and snippets.

@davidaknowles
Created August 20, 2019 19:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidaknowles/6e95a643adaf3960d1648a6b369e9d0b to your computer and use it in GitHub Desktop.
Save davidaknowles/6e95a643adaf3960d1648a6b369e9d0b to your computer and use it in GitHub Desktop.
torch currently only supports 2d pixel shuffle from https://arxiv.org/abs/1609.05158. This is the 1d version.
def pixel_shuffle_1d(x, upscale_factor):
batch_size, channels, steps = x.size()
channels //= upscale_factor
input_view = x.contiguous().view(batch_size, channels, upscale_factor, steps)
shuffle_out = input_view.permute(0, 1, 3, 2).contiguous()
return shuffle_out.view(batch_size, channels, steps * upscale_factor)
@myhub
Copy link

myhub commented Aug 21, 2019

Thanks, this version works ok

@davidaknowles
Copy link
Author

Thanks for noticing the bug in the PR implementation! Would probably have just used that code otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment