这篇教程keras 张量点积计算写得很实用,希望能帮到您。
I hope to calculate a vector wise dot product in Keras. In detail, I mean if I have two tensor A and B, both with shape (None, 30, 100), I want to calculate the result C with shape (None, 30, 1) which would satisfy
C[:,:,i] = dot(A[:,:,i], B[:,:,i]).
I wonder if that is possible, since the batch_dot() function in the backend would only return the shape (None, 30, 30) and only have the relationship
C[:,i,j] = dot(A[:,:,i], B[:,:,j])
But that is not what I want.
Thank you! 解决方案
You can try something like:
import keras.backend as K
C = K.sum(A * B,axis=-1,keepdims=True) Lambda layer 的应用 Keras 的应用模块(keras.applications)大全 |