[英]How to element-wise subtract to in a keras Dense layer in tensorflow2?
假設我在Dense(2)
層。 如何添加層以首先記錄整個張量,然后按元素從第一列中減去第二列? 謝謝你。
array([[1,2],
[3,4],
[5,6]])
becomes
array([[log(2)-log(1)],
[log(4)-log(3)],
[log(6)-log(5)]])
我會這樣做:
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)
或者你必須創建一個自定義層。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.