例如>我有一个Theano代码,它可以工作(T == Theano):
N = input.shape[0] # input has shape wrt TF (?, num)
mse = T.sum(T.square(ytarg - ypred)) / N
如果变量 N 的维度未知,我真的不知道如何在 TF op 的计算中使用变量 N。
最佳答案
在 Tensorflow 中,您不需要知道在图形执行期间要处理的元素数量。您必须使用tf.reduce_*
将此任务委托(delegate)给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))
关于machine-learning - 如何使用 TF 在操作计算中使用未知维度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39316440/