回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>这是我的自定义填充层:</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):
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
</code></pre>
<p>出于某种原因:</p>
<p><code>K.int_shape(x) (None, 128, 128, 7)</code></p>
<p>但是</p>
<p><code>K.int_shape(K.zeros_like(x)) (None, None, None, 7)</code></p>
<p>在<a href="https://keras.io/backend/#zeros_like" rel="nofollow noreferrer">doc</a><code>instantiates an all-zeros variable of the same shape as another tensor</code>中,有什么问题吗?你知道吗</p>
<p><strong>更新:</strong></p>
<p>串联不起作用的问题:</p>
<pre><code>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)]
</code></pre>