ICNR is an initialization method for sub-pixel convolution.
Papar
Github or Gist
-
ICNR inizialization by catta202000 · Pull Request #5429 · pytorch/pytorch
-
pytorch/PixelShuffle.cpp at 517c7c98610402e2746586c78987c64c28e024aa · pytorch/pytorch
-
kostyaev/ICNR: Convolution NN resize initialization for subpixel convolutions
Python 3.6 or later
PyTorch 1.1.0 or later
For example, input Tensor with the sizes (64, 8, 32, 32) would be output as (64, 8, 64, 64) if you set upscale_factor to 2.
import torch
import torch.nn as nn
from icnr import ICNR
upscale_factor = 2
input = torch.randn(64, 3, 32, 32)
conv = nn.Conv2d(3, 3 * (upscale_factor ** 2), 3, 1, 1, bias=0)
pixelshuffle = nn.PixelShuffle(upscale_factor)
weight = ICNR(conv.weight, initializer=nn.init.kaiming_normal_,
upscale_factor=upscale_factor)
conv.weight.data.copy_(weight) # initialize conv.weight
output = conv(input) # (64, 12, 32, 32)
output = pixelshuffle(output) # (64, 3, 64, 64)See visualization.ipynb