将2D图层裁剪到错误的尺寸

时间:2019-09-02 07:31:52

标签: python arrays tensorflow keras crop

我有一个1920 x 1153 x 3 keras张量,需要裁剪为1920 x 1080。但是,创建裁剪图层并传递形状差异会导致尺寸错误。这种方法使张量的形状为1920 x 1920。

代码:

        def crop(x, size):
            shape = K.int_shape(x)
            shape_diff = shape[1] - size[1], shape[2] - size[2]
            print(shape_diff)
            y = tf.keras.layers.Cropping2D(shape_diff)(x)
            return y

model.summary和shape_diff的部分输出:

Shape_diff: (0,72)

model.summary:

conv2d_transpose_4 (Conv2DTr (None, 1920, 1152, 3)     195       
_________________________________________________________________
cropping2d (Cropping2D)      (None, 1920, 1008, 3)     0         
=================================================================

1 个答案:

答案 0 :(得分:0)

由于Keras文档声明,将边数除以2可解决此问题:

  

如果元组为2个整数,则解释为高度和宽度的两个不同的对称裁剪值。