這是我的自定義填充層: class CustomZeroPadding2D(Layer): def __init__(self, **kwargs): super(CustomZeroPadding2D, self).__init__(**kwargs) def build(self, input_shape): super(CustomZeroPadding2D, self).build(input_shape) def call(self, x): print('K.int_shape(x)', K.int_shape(x)) print('K.int_shape(K.zeros_like(x))', K.int_shape(K.zeros_like(x))) res = concatenate([x, K.zeros_like(x)], axis=-1) return res def compute_output_shape(self, input_shape): output_shape = (input_shape[0], input_shape[1], input_shape[2]*2) return output_shape因為某些原因:K.int_shape(x) (None, 128, 128, 7)但K.int_shape(K.zeros_like(x)) (None, None, None, 7)在doc 中 instantiates an all-zeros variable of the same shape as another tensor,有什么問題?更新:連接不起作用的問題:ValueError: A `Concatenate` layer requires inputs with matching shapes except for the concat axis. Got inputs shapes: [(None, 128, 128, 7), (None, None, None, 7)]
K.zeros_like(x) 的 K.int_shape
慕田峪9158850
2021-09-14 20:29:14