如何使用 TF 在 ops 计算中使用未知维度
How to use unknown dimension in ops calculations with TF
例如 > 我有一个有效的 Theano 代码 (T == Theano):
N = input.shape[0] # input has shape wrt TF (?, num)
mse = T.sum(T.square(ytarg - ypred)) / N
如果是未知维度,我真的不知道如何在 TF op 的计算中使用变量 N。
在 Tensorflow 中,您不需要知道在图形执行期间要处理的元素数量。您必须使用 tf.reduce_*
操作将此任务委派给 tensorflow。
Reduction
TensorFlow provides several operations that you can use to perform common math computations that reduce various dimensions of a tensor.
您在Theano中定义的MSE函数可以很容易地在Tensorlow中定义;
mse = tf.reduce_mean(tf.pow(tf.sub(ytarg, ytarg), 2.0))
例如 > 我有一个有效的 Theano 代码 (T == Theano):
N = input.shape[0] # input has shape wrt TF (?, num)
mse = T.sum(T.square(ytarg - ypred)) / N
如果是未知维度,我真的不知道如何在 TF op 的计算中使用变量 N。
在 Tensorflow 中,您不需要知道在图形执行期间要处理的元素数量。您必须使用 tf.reduce_*
操作将此任务委派给 tensorflow。
Reduction
TensorFlow provides several operations that you can use to perform common math computations that reduce various dimensions of a tensor.
您在Theano中定义的MSE函数可以很容易地在Tensorlow中定义;
mse = tf.reduce_mean(tf.pow(tf.sub(ytarg, ytarg), 2.0))