这是我的自定义填充层:
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)
在docinstantiates 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)]
应使用
keras.backend.concatenate
而不是keras.layers.concatenate
:没什么不对的。你知道吗
如果你能用
axis=-1
连接起来,你可以确定所有的三个第一维度是相等的。你知道吗现在,在tensorflow和/或keras中可能有一些内在的怪癖,也许是为了让事情变得更快,也许是为了让它们灵活地适应不同的尺寸。没什么大不了的。你知道吗
如果想要得到当前值的真实形状,需要计算(
K.eval()
)张量K.shape(x)
。但评估不能在层内进行。必须像做预测一样去做。你知道吗错误消息
您使用的是连接层。你应该使用
keras.backend.concatenate([...], axis=-1)
相关问题 更多 >
编程相关推荐