PixelShuffleLayer come from [Real-Time\_Single\_Image](https://www.cv-foundation.org/openaccess/content_cvpr_2016/papers/Shi_Real-Time_Single_Image_CVPR_2016_paper.pdf).

[![enter image description here](https://i.stack.imgur.com/bMcYK.png)](https://i.stack.imgur.com/bMcYK.png)

Firstly, a $C\times H\times W$ image, after a convolution, now $f^2\cdot C \times H\times W$, then sub-pix, finally get a $ C \times fH\times fW$ image.

Let me take a $3\times 4\times 3$ image with $f=2$ as an example:

```
SeedRandom[42]
afterConv=RandomReal[1,{2^2*3,4,3}];
ArrayFlatten[Transpose[ArrayReshape[#,{2,2,4,3}],{3,4,1,2}],2]&/@Partition[afterConv,4]

```

If we do a step decomposition:

```
MatrixForm/@(m1a=First@Partition[afterConv,4])
MatrixForm[m1b=ArrayReshape[m1a,{2,2,4,3}]]
MatrixForm[m1c=Transpose[m1b,{3,4,1,2}]]
MatrixForm[m1d=ArrayFlatten[m1c,2]]

```

[![enter image description here](https://i.stack.imgur.com/W7HYQ.png)](https://i.stack.imgur.com/W7HYQ.png)

But `NetChain` can't receive the functions above, it can only use Layers.

So how do I define a `PixelShuffleLayer[f_Integer]`?

---

Update-20180920:
----------------

Notice that that the color channel, the width and height of the picture are variable.

I tried to decompile the MXNet diagram definition to find how MXNet can do this.

```
{
    MXNetLink`Symbol`PackagePrivate`mxSymbolCreator["Reshape", {"shape" -> "(0, -4, -1, 4, 0, 0)"}],
    MXNetLink`Symbol`PackagePrivate`mxSymbolCreator["Reshape", {"shape" -> "(0, 0, -4, 2, 2, 0, 0)"}],
    MXNetLink`Symbol`PackagePrivate`mxSymbolCreator["transpose", {"axes" -> "(0, 1, 4, 2, 5, 3)"}],
    MXNetLink`Symbol`PackagePrivate`mxSymbolCreator["Reshape", {"shape" -> "(0, 0, -3, -3)"}]
}

```

While `ReshapeLayer` only accept a list of positive integers.

So try `NeuralNetworks`MXLayer` or `NeuralNetworks`DefineLayer`.