tensorflow - 使用层的输出在 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)
解决方案
推荐阅读
- sql-server - 无法在 SQL Server 2019 上更改表或运行 sp_changedbowner,以 SA 身份登录
- php - 如何使我的 PHP 脚本返回到我的原始 HTML 页面?
- c# - 我想使用 Azure Graph 获取令牌并执行 Teams API(C#)
- html - 如何将 2 个 div 并排居中
- c# - 奇怪的版本冲突:“NCrontab.Signed,Version=3.2.20120.0”和“NCrontab,Version=3.2.20120.0”中都存在“CrontabSchedule”类型
- python - 为什么这个打印第一索引?
- jmeter - 如何在 JMeter / Load Runner 中处理 TPS
- c# - 具有相同类名的元素的 XPath
- r - 如何操作数据?
- winforms - 当我设置单元格值时,WinForms DataGridView 清除 SelectedRows?