擅长:python、mysql、java
<p>应使用<code>keras.backend.concatenate</code>而不是<code>keras.layers.concatenate</code>:</p>
<pre><code>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):
res = K.concatenate([x, K.zeros_like(x)], axis=-1)
return res
def compute_output_shape(self, input_shape):
output_shape = list(input_shape)
output_shape[-1] = output_shape[-1] * 2
output_shape = tuple(output_shape)
return output_shape
</code></pre>