codecamp

TensorFlow函数教程:tf.keras.backend.batch_dot

tf.keras.backend.batch_dot函数

tf.keras.backend.batch_dot(
    x,
    y,
    axes=None
)

定义在:tensorflow/python/keras/backend.py。

批量化的点积。

当x和y是批量数据时,batch_dot用于计算x和y的点积,即shape为(batch_size,:)。 batch_dot产生维度小于输入的张量或变量。如果维度数减少到1,我们使用expand_dims确保ndim至少为2。

参数:

  • x:ndim >= 2的Keras张量或变量。
  • y:ndim >= 2的Keras张量或变量。
  • axes:具有目标维度的(或单个)int列表。axes[0]和axes[1]的长度应该是相同的。

返回:

A tensor with shape equal to the concatenation of `x`'s shape
(less the dimension that was summed over) and `y`'s shape
(less the batch dimension and the dimension that was summed over).
If the final rank is 1, we reshape it to `(batch_size, 1)`.

例子:假设x = [[1, 2], [3, 4]],y = [[5, 6], [7, 8]] ,其中batch_dot(x, y, axes=1) = [[17, 53]]是x.dot(y.T)的主对角线,虽然我们没有必要计算非对角线元素。

Shape inference:
Let `x`'s shape be `(100, 20)` and `y`'s shape be `(100, 30, 20)`.
If `axes` is (1, 2), to find the output shape of resultant tensor,
    loop through each dimension in `x`'s shape and `y`'s shape:

* `x.shape[0]` : 100 : append to output shape
* `x.shape[1]` : 20 : do not append to output shape,
    dimension 1 of `x` has been summed over. (`dot_axes[0]` = 1)
* `y.shape[0]` : 100 : do not append to output shape,
    always ignore first dimension of `y`
* `y.shape[1]` : 30 : append to output shape
* `y.shape[2]` : 20 : do not append to output shape,
    dimension 2 of `y` has been summed over. (`dot_axes[1]` = 2)
`output_shape` = `(100, 30)`
    >>> x_batch = K.ones(shape=(32, 20, 1))
    >>> y_batch = K.ones(shape=(32, 30, 20))
    >>> xy_batch_dot = K.batch_dot(x_batch, y_batch, axes=[1, 2])
    >>> K.int_shape(xy_batch_dot)
    (32, 1, 30)
TensorFlow函数教程:tf.keras.backend.backend
TensorFlow函数教程:tf.keras.backend.batch_flatten
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

TensorFlow 函数介绍

TensorFlow 函数模块:tf

TensorFlow的image模块

TensorFlow使用之tf.io

TensorFlow使用之tf.keras

TensorFlow函数教程:tf.keras.applications

TensorFlow函数教程:tf.keras.backend

TensorFlow使用之tf.metrics

TensorFlow使用之tf.nn

TensorFlow使用之tf.python_io

TensorFlow 功能函数

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }