深度学习之上采样方法PixelShuffle时间:2022-11-01 16:59:23 import numpy as npx = np.array([1,2,3,4])# 放大因子倍数scale = 4x = x[...,None]x = np.repeat(x,scale,axis=1)# (4,4)print(x.shape)c1,c2 = np.split(x,indices_or_sections=2,axis=1)c = np.stack([c1,c2],axis=2)# (4,2,2)print(c.shape)# print(x[...,None])print(c.shape)c = c.reshape([2,2,2,2])c = np.transpose(c,[2,0,3,1])# 相当于把numpy中的c均分给w,h上print(c.shape)c = c.reshape([4,4])print(c) 针对一张图片形状为(c,h,w),batch_size 常常用于训练,这里省略为1.通过卷积神经网络,我们往往可以得到一张卷积特征图(c2,h,w)。通过对像素的重新排列,来实现图像的超分辨率,这是ESPCN中对于PixelShuffle的应用。简单理解,就是将c2中的像素,通过混洗在图片的w,h维度进行拓张。 假设我们的原始图像为: image = np.array([[[1 1] [1 1]] [[2 2] [2 2]] [[3 3] [3 3]] [[4 4] [4 4]]]) 通过对通道层面,像素重排列。我们得到的结果将会是: [[1 2 1 2] [3 4 3 4] [1 2 1 2] [3 4 3 4]]