https://github.com/fangwei123456/pixelunshuffle-pytorch
PixelUnshuffle, inverse operation of PixelShuffle
https://github.com/fangwei123456/pixelunshuffle-pytorch
computer-vision machine-learning pytorch super-resolution
Last synced: about 1 year ago
JSON representation
PixelUnshuffle, inverse operation of PixelShuffle
- Host: GitHub
- URL: https://github.com/fangwei123456/pixelunshuffle-pytorch
- Owner: fangwei123456
- License: mit
- Created: 2019-08-27T08:13:22.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-07-30T07:07:57.000Z (almost 5 years ago)
- Last Synced: 2025-03-28T04:11:32.245Z (over 1 year ago)
- Topics: computer-vision, machine-learning, pytorch, super-resolution
- Language: Python
- Homepage:
- Size: 10.7 KB
- Stars: 21
- Watchers: 1
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PixelUnshuffle-pytorch
PyTorch has provided an official implement: https://pytorch.org/docs/stable/generated/torch.nn.PixelUnshuffle.html.
----------------------------------------------------
PixelUnshuffle, inverse operation of PixelShuffle.
| in pytorch | inverse in PixelUnshuffle |
| ---------------------------------------------------- | ------------------------------------------ |
| `nn.PixelShuffle(upscale_factor)` | `PixelUnshuffle(downscale_factor)` |
| `nn.functional.pixel_shuffle(input, upscale_factor)` | `pixel_unshuffle(input, downscale_factor)` |
**Installation:**
```
1.Clone this repo.
2.Copy "PixelUnshuffle" folder in your project.
```
**Example:**
```python
import PixelUnshuffle
import torch
import torch.nn as nn
import torch.nn.functional as F
x = torch.range(start=0, end=31).reshape([1, 8, 2, 2])
print('x:')
print(x.shape)
print(x)
y = F.pixel_shuffle(x, 2)
print('y:')
print(y.shape)
print(y)
x_ = PixelUnshuffle.pixel_unshuffle(y, 2)
print('x_:')
print(x_.shape)
print(x_)
```
output:
```python
x:
torch.Size([1, 8, 2, 2])
tensor([[[[ 0., 1.],
[ 2., 3.]],
[[ 4., 5.],
[ 6., 7.]],
[[ 8., 9.],
[10., 11.]],
[[12., 13.],
[14., 15.]],
[[16., 17.],
[18., 19.]],
[[20., 21.],
[22., 23.]],
[[24., 25.],
[26., 27.]],
[[28., 29.],
[30., 31.]]]])
y:
torch.Size([1, 2, 4, 4])
tensor([[[[ 0., 4., 1., 5.],
[ 8., 12., 9., 13.],
[ 2., 6., 3., 7.],
[10., 14., 11., 15.]],
[[16., 20., 17., 21.],
[24., 28., 25., 29.],
[18., 22., 19., 23.],
[26., 30., 27., 31.]]]])
x_:
torch.Size([1, 8, 2, 2])
tensor([[[[ 0., 1.],
[ 2., 3.]],
[[ 4., 5.],
[ 6., 7.]],
[[ 8., 9.],
[10., 11.]],
[[12., 13.],
[14., 15.]],
[[16., 17.],
[18., 19.]],
[[20., 21.],
[22., 23.]],
[[24., 25.],
[26., 27.]],
[[28., 29.],
[30., 31.]]]])
```
A neat way can be found here:
[pytorch/pytorch#2456](https://github.com/pytorch/pytorch/issues/2456)