mirror of
https://github.com/igv/FSRCNN-TensorFlow.git
synced 2026-08-18 00:57:28 +08:00
Move GSL to a separate function
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user