Tensorflow具有以下功能:
tf.matmul
它将两个向量相乘并产生一个标量。
但是,我需要做以下事情:
# dense dim: (?,227)
dense_part = tf.nn.relu(some stuff here)
# softmax matrix dim: (?,227,19) or (?,19,227) or (?,227,227), where I
# ....can slice the last dim down to (?,227,19)
softmax_matrix = tf.matmul(dense_part,softmax_weight_variable)
但是,为了通过矩阵乘法实现这一点,我无法设置softmax_weight_variable。我需要使用“Tensor Product”(也称为“Outer Product”......),但这个功能似乎没有实现。
如何在TensorFlow中实现Hadamard(逐元素)乘法和外积?
答案 0 :(得分:7)
x
和y
的元素乘法仅为tf.mul(x, y)
。这也是supports NumPy-style broadcasting,如果需要,您应该可以使用它来获得外部产品。
答案 1 :(得分:0)
它是Tensorflow 1.11中的tf.multiply
。该函数提供具有相等形状的两个张量的Hadamard乘积。
答案 2 :(得分:0)
在 Tensorflow 2.4.1 版本中,这个函数似乎被命名为 tf.math.multiply
。