您当前的位置:首页 > IT编程 > Keras
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch |

自学教程:keras 张量点积计算

51自学网 2020-11-29 10:43:51
  Keras
这篇教程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)大全
51自学网,即我要自学网,自学EXCEL、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。
京ICP备13026421号-1