I have seen a few different mean squared error loss functions in various posts for regression models in Tensorflow:loss = tf.reduce_sum(tf.pow(prediction - Y,2))/(n_instances)loss = tf.reduce_mean(tf.squared_difference(prediction, Y))loss = tf.nn.l2_loss(prediction - Y)What are the differences between these? 解决方案 I would say that the third equation is different, while the 1st and 2nd are formally the same but behave differently due to numerical concerns.I think that the 3rd equation (using l2_loss) is just returning 1/2 of the squared Euclidean norm, that is, the sum of the element-wise square of the input, which is x=prediction-Y. You are not dividing by the number of samples anywhere. Thus, if you have a very large number of samples, the computation may overflow (returning Inf).The other two are formally the same, computing the mean of the element-wise squared x tensor. However, while the documentation does not specify it explicitly, it is very likely that reduce_mean uses an algorithm adapted to avoid overflowing with very large number of samples. In other words, it likely does not try to sum everything first and then divide by N, but use some kind of rolling mean that can adapt to an arbitrary number of samples without necessarily causing an overflow. 这篇关于Tensorflow均方误差损失函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-27 19:48