From 1aa11ab0e1fc12741fdb84cef31da5619a478670 Mon Sep 17 00:00:00 2001 From: igv Date: Thu, 20 Sep 2018 12:53:17 +0300 Subject: [PATCH] Switch to Gradient Sensitive Loss --- ESPCN.py | 6 +++++- FSRCNN.py | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ESPCN.py b/ESPCN.py index 520272b..6150ca3 100644 --- a/ESPCN.py +++ b/ESPCN.py @@ -52,4 +52,8 @@ def prelu(self, _x, i): return tf.nn.relu(_x) - alphas * tf.nn.relu(-_x) def loss(self, Y, X): - return tf.reduce_mean(tf.sqrt(tf.square(X - Y) + 1e-6)) + (1.0 - tf_ssim(Y, X)) * 0.5 + dY = tf.image.sobel_edges(Y) + dX = tf.image.sobel_edges(X) + M = tf.sqrt(tf.square(dY[:,:,:,:,0]) + tf.square(dY[:,:,:,:,1])) + return tf.losses.absolute_difference(dY, dX) \ + + tf.losses.absolute_difference((1.0 - M) * Y, (1.0 - M) * X, weights=2.0) diff --git a/FSRCNN.py b/FSRCNN.py index 7aa7994..f12435f 100644 --- a/FSRCNN.py +++ b/FSRCNN.py @@ -85,4 +85,8 @@ def prelu(self, _x, i): return tf.nn.relu(_x) - alphas * tf.nn.relu(-_x) def loss(self, Y, X): - return tf.reduce_mean(tf.sqrt(tf.square(X - Y) + 1e-6)) + (1.0 - tf_ssim(Y, X)) * 0.5 + dY = tf.image.sobel_edges(Y) + dX = tf.image.sobel_edges(X) + M = tf.sqrt(tf.square(dY[:,:,:,:,0]) + tf.square(dY[:,:,:,:,1])) + return tf.losses.absolute_difference(dY, dX) \ + + tf.losses.absolute_difference((1.0 - M) * Y, (1.0 - M) * X, weights=2.0)