Keras:扩大图层输出blob的spartial维度的方法

mrg*_*oom 3 convolution deep-learning conv-neural-network keras keras-layer

可以使用哪些方法来扩大图层输出blob的spartial维度?

据我所知,从文档中可以看出:

  1. UpSampling2D 是否仅以2的幂进行上采样?它Repeats the rows and columns of the data by size[0] and size[1] respectively.也不是很聪明.
  2. Conv2DTranspose 它可以有任意输出大小(不是2的功能)吗?

    如何使用任意尺寸进行双线性插值高程(它可以是具有固定权重的Conv2DTranspose?)

    还有哪些其他选项可用于放大图层输出blob的spartial维度?

Kyl*_*ald 10

扩展y300答案,这是在Keras Lambda层中包装TensorFlow双线性图像大小的完整示例:

from keras import Sequential
from keras.layers import Lambda
import tensorflow as tf

def UpSampling2DBilinear(size):
    return Lambda(lambda x: tf.image.resize_bilinear(x, size, align_corners=True))

upsampler = Sequential([UpSampling2DBilinear((256, 256))])

upsampled = upsampler.predict(images)
Run Code Online (Sandbox Code Playgroud)

请注意,align_corners=True以获得类似的性能给其他双线性图像采样算法,如在这个岗位.

要使用双三次重采样,请创建一个新函数并替换resize_bilinearresize_bicubic.

对于与UpSampling2D更相似的实现,请尝试以下方法:

from keras import backend as K

def UpSampling2DBilinear(stride, **kwargs):
    def layer(x):
        input_shape = K.int_shape(x)
        output_shape = (stride * input_shape[1], stride * input_shape[2])
        return tf.image.resize_bilinear(x, output_shape, align_corners=True)
    return Lambda(layer, **kwargs)
Run Code Online (Sandbox Code Playgroud)

这将允许你使用name='',input_shape=''以及其他论据Lamba,并允许你传递一个整数跨度/上采样量.