Keras 中的线性插值

Linear interpolation in Keras

如何在 Keras 中添加线性插值层?

我有沙漏网络 ("channel_first"),在解码器部分的某个时刻,我必须在我的 relu 层之后进行从大小 (32,128,152) 到 (32,128,256) 的线性插值。

我尝试了 conv2DTranspose 和 Upsampling2D none,其中允许分数上采样率。 Reshape 和 Imageresize 也不起作用。 (我的输入不是图像,它是原始数据矩阵大小 64*2462)

您可以使用tf.image.resize,因为它是二维数据的插值。有几种可能的插值,包括"bilinear"、"bicubic"等:https://www.tensorflow.org/api_docs/python/tf/image/resize

为了首先解决渠道问题,您可以简单地重新排序您的维度:

model.add(Permute((2,3,1))) #brings the channels to the last position
model.add(Lambda(lambda x: tf.image.resize(x, size)))

#if you wish to go back to channels first:
model.add(Permute((3,1,2)))

老实说,Keras 倾向于在其函数中最后使用通道(轴通常假设为 -1,某些激活和损失将用于轴 -1,等等)

毫无疑问,我会最后使用频道。即使我先保留数据通道但添加 Permute 作为模型的第一层。但这当然是个人喜好。