Move GSL to a separate function

This commit is contained in:
igv
2020-05-11 16:15:35 +03:00
parent 85c1912989
commit aef9256d75
4 changed files with 15 additions and 17 deletions
+2 -5
View File
@@ -1,4 +1,5 @@
import tensorflow as tf
from utils import gradient_sensitive_loss, tf_ms_ssim
class Model(object):
@@ -56,8 +57,4 @@ class Model(object):
return conv
def loss(self, Y, X):
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)
return gradient_sensitive_loss(Y, X)
+2 -6
View File
@@ -1,5 +1,5 @@
import tensorflow as tf
from utils import tf_ssim
from utils import gradient_sensitive_loss, tf_ms_ssim
class Model(object):
@@ -52,8 +52,4 @@ class Model(object):
return tf.nn.relu(_x) - alphas * tf.nn.relu(-_x)
def loss(self, Y, X):
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)
return gradient_sensitive_loss(Y, X)
+2 -6
View File
@@ -1,5 +1,5 @@
import tensorflow as tf
from utils import tf_ssim
from utils import gradient_sensitive_loss, tf_ms_ssim
class Model(object):
@@ -86,8 +86,4 @@ class Model(object):
return tf.nn.relu(_x) - alphas * tf.nn.relu(-_x)
def loss(self, Y, X):
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)
return gradient_sensitive_loss(Y, X)
+9
View File
@@ -258,6 +258,15 @@ def array_image_save(array, image_path):
image.save(image_path)
print("Saved image: {}".format(image_path))
def gradient_sensitive_loss(img1, img2):
dY = tf.image.sobel_edges(img1) / 4.
dX = tf.image.sobel_edges(img2) / 4.
M = tf.sqrt(tf.square(dY[:,:,:,:,0]) + tf.square(dY[:,:,:,:,1]))
#dY = tf.image.sobel_edges(img1 * M)
#dX = tf.image.sobel_edges(img2 * M)
return tf.losses.absolute_difference(dY, dX) \
+ tf.losses.absolute_difference((1.0 - M) * img1, (1.0 - M) * img2, weights=2.0)
def _tf_fspecial_gauss(size, sigma):
"""Function to mimic the 'fspecial' gaussian MATLAB function
"""