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

据我从文档中看到它可以是:

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

    如何完成具有任意维度的双线性插值升级(它可以是具有固定权重的 Conv2DTranspose?)

    还有哪些其他选项可用于扩大层输出 blob 的局部维度?
  • 最佳答案

    扩展 answer from 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)
    

    请注意, align_corners=True 可以获得与其他双线性图像上采样算法相似的性能,如 this post 中所述。

    要使用双三次重采样,请创建一个新函数并将 resize_bilinear 替换为 resize_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)
    

    这将允许您使用 name=''input_shape=''Lamba 的其他参数,并允许您传递整数步幅/上采样量。

    关于deep-learning - Keras:扩大层输出 blob 空间维度的方法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44186042/

    10-12 19:31