【发布时间】:2017-07-11 07:36:12
【问题描述】:
我试图在Tensorflow 中从Caffe 复制EuclideanLoss。我找到了一个名为:tf.nn.l2_loss 的函数,根据文档计算如下:
output = sum(t ** 2) / 2
当查看 Python 版本的 caffe 中的 EuclideanLoss 时,它会说:
def forward(self, bottom, top):
self.diff[...] = bottom[0].data - bottom[1].data
top[0].data[...] = np.sum(self.diff**2) / bottom[0].num / 2.
在原始文档中它说:
对我来说,这是完全相同的计算。但是,我在 Tensorflow 中对同一网络的损失值约为 3000,而在 Caffe 中约为 300。那么差异在哪里?
【问题讨论】:
-
我会说你还需要除以批量大小(10?),或者更好的是,使用
tf.mean()来计算批量的平均损失。 -
嗯更好的不是我要求的。我要求完全相同的损失?! @ManoloSantos
-
同样的损失。
tf.reduce_mean(x) / 2. == tf.sum(x) / x.shape[0] / 2. -
好的,你能回答这个问题并写下要使用的确切张量流损失吗?我有点困惑。 @ManoloSantos
标签: python tensorflow caffe euclidean-distance