[英]How to element-wise subtract to in a keras Dense layer in tensorflow2?
Let say I'm at the Dense(2)
layer.假设我在
Dense(2)
层。 How to add layers to first log the whole tensor and then element-wise subtract the second column from the first column?如何添加层以首先记录整个张量,然后按元素从第一列中减去第二列? Thank you.
谢谢你。
array([[1,2],
[3,4],
[5,6]])
becomes
array([[log(2)-log(1)],
[log(4)-log(3)],
[log(6)-log(5)]])
I would do this:我会这样做:
input = tf.keras.layers.Input(shape=(2,), dtype=tf.float32)
x = tf.keras.layers.Dense(2)(input)
x = tf.math.log(x[-1][0]) - tf.math.log(x[-1][1])
model = tf.keras.Model(inputs=input, outputs=x)
Or you have to create a custom layer.或者你必须创建一个自定义层。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.