我正在尝试使用两个图像之间的 SSD 作为我的网络的损失函数。
# h_fc2 is my output layer, y_ is my label image.
ssd = tf.reduce_sum(tf.square(y_ - h_fc2))
train_step = tf.train.GradientDescentOptimizer(0.01).minimize(ssd)
问题是,权重然后发散,我得到了错误
ReluGrad input is not finite. : Tensor had Inf values
为什么?我确实尝试了一些其他的东西,比如通过图像大小规范化 ssd(不起作用)或将输出值裁剪为 1(不再崩溃,但我仍然需要对此进行评估):
ssd_min_1 = tf.reduce_sum(tf.square(y_ - tf.minimum(h_fc2, 1)))
train_step = tf.train.GradientDescentOptimizer(0.01).minimize(ssd_min_1)
我的观察结果符合预期吗?
编辑:@mdaoust 的建议被证明是正确的。要点是按批次大小进行标准化。这可以通过使用此代码独立于批量大小来完成
squared_diff_image = tf.square(label_image - output_img)
# Sum over all dimensions except the first (the batch-dimension).
ssd_images = tf.reduce_sum(squared_diff_image, [1, 2, 3])
# Take mean ssd over batch.
error_images = tf.reduce_mean(ssd_images)
通过这种变化,只需要稍微降低学习率(至 0.0001)。