mirror of
https://github.com/iperov/DeepFaceLab.git
synced 2025-08-21 22:13:20 -07:00
tf2
This commit is contained in:
parent
39601603ef
commit
6a68dd5e59
2 changed files with 14 additions and 18 deletions
|
@ -1,5 +1,6 @@
|
||||||
from core.leras import nn
|
from core.leras import nn
|
||||||
tf = nn.tf
|
tf = nn.tf
|
||||||
|
tf2 = nn.tf2
|
||||||
|
|
||||||
class MsSsim(nn.LayerBase):
|
class MsSsim(nn.LayerBase):
|
||||||
default_power_factors = (0.0448, 0.2856, 0.3001, 0.2363, 0.1333)
|
default_power_factors = (0.0448, 0.2856, 0.3001, 0.2363, 0.1333)
|
||||||
|
@ -20,15 +21,7 @@ class MsSsim(nn.LayerBase):
|
||||||
y_true_t = tf.transpose(tf.cast(y_true, tf.float32), [0, 2, 3, 1])
|
y_true_t = tf.transpose(tf.cast(y_true, tf.float32), [0, 2, 3, 1])
|
||||||
y_pred_t = tf.transpose(tf.cast(y_pred, tf.float32), [0, 2, 3, 1])
|
y_pred_t = tf.transpose(tf.cast(y_pred, tf.float32), [0, 2, 3, 1])
|
||||||
|
|
||||||
|
loss = tf2.image.ssim_multiscale(y_true_t, y_pred_t, max_val, power_factors=self.power_factors)
|
||||||
def assign_device(op):
|
return (1.0 - loss) / 2.0
|
||||||
if op.type != 'Assert' or op.type != 'ListDiff':
|
|
||||||
return '/gpu:0'
|
|
||||||
else:
|
|
||||||
return '/cpu:0'
|
|
||||||
|
|
||||||
with tf.device(assign_device):
|
|
||||||
loss = tf.image.ssim_multiscale(y_true_t, y_pred_t, max_val, power_factors=self.power_factors)
|
|
||||||
return (1.0 - loss) / 2.0
|
|
||||||
|
|
||||||
nn.MsSsim = MsSsim
|
nn.MsSsim = MsSsim
|
||||||
|
|
|
@ -31,6 +31,7 @@ class nn():
|
||||||
current_DeviceConfig = None
|
current_DeviceConfig = None
|
||||||
|
|
||||||
tf = None
|
tf = None
|
||||||
|
tf2 = None
|
||||||
tf_sess = None
|
tf_sess = None
|
||||||
tf_sess_config = None
|
tf_sess_config = None
|
||||||
tf_default_device = None
|
tf_default_device = None
|
||||||
|
@ -86,6 +87,8 @@ class nn():
|
||||||
|
|
||||||
if tf_version[0] == '2':
|
if tf_version[0] == '2':
|
||||||
tf = tensorflow.compat.v1
|
tf = tensorflow.compat.v1
|
||||||
|
tf2 = tensorflow
|
||||||
|
nn.tf2 = tf2
|
||||||
else:
|
else:
|
||||||
tf = tensorflow
|
tf = tensorflow
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue