使用layer的输出在Keras中创建卷积内核

时间:2019-03-09 19:19:39

标签: tensorflow keras conv-neural-network cross-product

如何通过我的网络的两个输出的叉积来创建适当大小的内核,然后矩阵(张量)将成为下一层的卷积内核。即

def CrossMult(inputs):
    x0, x1 = inputs
    #x0 = tf.keras.backend.transpose(x0)
    x1 = tf.keras.backend.transpose(x1)
    # you apply layer operations to layers
    C = keras.layers.dot(axis=-1)(x0,x1)
    return C

def Conv1d(inputs):
    x, kernel = inputs
    Recon = keras.backend.conv1d(x, kernel, strides=1, padding='same', 
    dilation_rate=1)
    return Recon

input0 = input(...
x0 = ConvLayer2(x0)
x1 = ConvLayer2(x1)

layer_conv_kernel = Lambda(Conv1d)
layer_cross_prod = Lambda(CrossMult)

#kernel = keras.layers.Multiply()([x0, x1])

Kernel = layer_cross_prod([x0, x1])
#The Kernelis the cross-convolution between two output vectors and this matrix will be the convolutional kernel in the later layer.

Recon = layer_conv_kernel([input0, kKernel])

# This line raises an error!
# the size of Kernel will be (None, M,N)(error)
Recon = keras.backend.conv1d(input1, Kernel, strides=1, padding='same', dilation_rate=1)
# This line raises another error!
Recon = Conv1D(1, width, strides=1, activation='relu', padding='same')(Recon)

0 个答案:

没有答案
相关问题