在Keras层中使用np.newaxis进行运算:乘法与串联

时间:2019-11-07 07:56:11

标签: python keras concatenation

我对Keras中的np.newaxis有疑问。我有一个尺寸为[None,64]的x_6,可以将其扩展为4个尺寸

temp = Lambda(lambda x: x[:,np.newaxis,np.newaxis,:])(x_6)

将x_1层的大小(无,无,无,64)相乘会起作用

x_1 = Multiply()([x_1,temp])

但是由于形状不匹配,因此无法将它们两者串联在一起

x_1 = Concatenate(axis=-1)([x_1,temp])

有人看到问题出在哪里吗? 错误消息是

ValueError: A 'Concatenate' layer requires inputs with matching shapes excpet for the concat axis. Got input shapes: [(None,None,None,64),(None,1,1,64)]

通过None更改np.newaxis会出现相同的问题。

另一种无效的窍门

temp = Lambda(lambda x: K.expand_dims(x,axis=1))(x_6)
temp = Lambda(lambda x: K.expand_dims(x,axis=1))(temp)

0 个答案:

没有答案
相关问题