首页 > 解决方案 > 使用层的输出在 Keras 中制作卷积核

问题描述

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

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)

标签: tensorflowkerasconv-neural-networkcross-product

解决方案


推荐阅读