我正在Keras中创建一个模型。我有一个x_1层,带有64个输出通道,我想将全局平均值最低的16个通道设置为0,这样他就不会将它们用作下一层的输入(以减少乘法的数量)。这段代码有效:
x_2 = GlobalAveragePooling2D()(x_1)
temp = Lambda(lambda x: K.sum(K.cast(x[:, :, np.newaxis] <= x[:, np.newaxis, :], np.int16), 1) >= 17)(x_2)
temp = Lambda(lambda x: x[:,np.newaxis,np.newaxis,:])(temp)
temp = Lambda(lambda x: K.cast(x, np.float32))(temp)
x_1 = Multiply()([x_1,temp])
现在,我想修改代码,以便他从4个通道的每组中选择一个通道设置为0。
x_2 = GlobalAveragePooling2D()(x_1)
temp1 = Lambda(lambda x: K.sum(K.cast(x[:, :, np.newaxis] <= x[:, np.newaxis, :], np.int16), 1) >= 2)(x_2[:, 0:4])
temp2 = Lambda(lambda x: K.sum(K.cast(x[:, :, np.newaxis] <= x[:, np.newaxis, :], np.int16), 1) >= 2)(x_2[:, 4:8])
temp3 = Lambda(lambda x: K.sum(K.cast(x[:, :, np.newaxis] <= x[:, np.newaxis, :], np.int16), 1) >= 2)(x_2[:, 8:12])
temp4 = Lambda(lambda x: K.sum(K.cast(x[:, :, np.newaxis] <= x[:, np.newaxis, :], np.int16), 1) >= 2)(x_2[:, 12:16])
temp5 = Lambda(lambda x: K.sum(K.cast(x[:, :, np.newaxis] <= x[:, np.newaxis, :], np.int16), 1) >= 2)(x_2[:, 16:20])
temp6 = Lambda(lambda x: K.sum(K.cast(x[:, :, np.newaxis] <= x[:, np.newaxis, :], np.int16), 1) >= 2)(x_2[:, 20:24])
temp7 = Lambda(lambda x: K.sum(K.cast(x[:, :, np.newaxis] <= x[:, np.newaxis, :], np.int16), 1) >= 2)(x_2[:, 24:28])
temp8 = Lambda(lambda x: K.sum(K.cast(x[:, :, np.newaxis] <= x[:, np.newaxis, :], np.int16), 1) >= 2)(x_2[:, 28:32])
temp9 = Lambda(lambda x: K.sum(K.cast(x[:, :, np.newaxis] <= x[:, np.newaxis, :], np.int16), 1) >= 2)(x_2[:, 32:36])
temp10 = Lambda(lambda x: K.sum(K.cast(x[:, :, np.newaxis] <= x[:, np.newaxis, :], np.int16), 1) >= 2)(x_2[:, 36:40])
temp11 = Lambda(lambda x: K.sum(K.cast(x[:, :, np.newaxis] <= x[:, np.newaxis, :], np.int16), 1) >= 2)(x_2[:, 40:44])
temp12 = Lambda(lambda x: K.sum(K.cast(x[:, :, np.newaxis] <= x[:, np.newaxis, :], np.int16), 1) >= 2)(x_2[:, 44:48])
temp13 = Lambda(lambda x: K.sum(K.cast(x[:, :, np.newaxis] <= x[:, np.newaxis, :], np.int16), 1) >= 2)(x_2[:, 48:52])
temp14 = Lambda(lambda x: K.sum(K.cast(x[:, :, np.newaxis] <= x[:, np.newaxis, :], np.int16), 1) >= 2)(x_2[:, 52:56])
temp15 = Lambda(lambda x: K.sum(K.cast(x[:, :, np.newaxis] <= x[:, np.newaxis, :], np.int16), 1) >= 2)(x_2[:, 56:60])
temp16 = Lambda(lambda x: K.sum(K.cast(x[:, :, np.newaxis] <= x[:, np.newaxis, :], np.int16), 1) >= 2)(x_2[:, 60:64])
temp = Lambda(lambda x: K.concatenate([x[0], x[1], x[2], x[3], x[4], x[5], x[6], x[7], x[8], x[9], x[10], x[11], x[12], x[13], x[14], x[15]],axis=-1))([temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8, temp9, temp10, temp11, temp12, temp13, temp14, temp15, temp16])
temp = Lambda(lambda x: x[:,np.newaxis,np.newaxis,:])(temp)
temp = Lambda(lambda x: K.cast(x, np.float32))(temp)
x_1 = Multiply()([x_1,temp])
这不起作用,当我更改时也不起作用
temp = Lambda(lambda x: K.concatenate([x[0], x[1], x[2], x[3], x[4], x[5], x[6], x[7], x[8], x[9], x[10], x[11], x[12], x[13], x[14], x[15]],axis=-1))([temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8, temp9, temp10, temp11, temp12, temp13, temp14, temp15, temp16])
进入
temp = Concatenate(axis=-1)([temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8, temp9, temp10, temp11, temp12, temp13, temp14, temp15, temp16])
我总是会收到错误:
AttributeError: 'NoneType' object has no attribute '_inbound_nodes'
有人看到我在做什么错吗?预先感谢!