Revert "replaced PenalizedLoss function with keras alternative"
diff --git a/lib/model/losses.py b/lib/model/losses.py
index 439096fb4b..66b6873310 100644
--- a/lib/model/losses.py
+++ b/lib/model/losses.py
@@ -167,17 +167,47 @@ def extract_image_patches(self, x, ksizes, ssizes, padding='same',
             patches = K.permute_dimensions(patches, [0, 1, 2, 4, 5, 3])
         return patches
 
-
 # <<< START: from Dfaker >>> #
-def PenalizedLoss(mask, loss_func, mask_prop=1.0):
+class PenalizedLoss():  # pylint: disable=too-few-public-methods
     """ Penalized Loss
         from: https://github.com/dfaker/df """
-    mask_as_k_inv_prop = 1 - mask_prop
-    mask = mask * mask_prop + mask_as_k_inv_prop
-    mask = K.repeat_elements(mask, 3, axis=3)
-    def inner_loss(y_true, y_pred):
-        return loss_func(y_true * mask, y_pred * mask)
-    return inner_loss
+    def __init__(self, mask, loss_func, mask_prop=1.0):
+        self.mask = mask
+        self.loss_func = loss_func
+        self.mask_prop = mask_prop
+        self.mask_as_k_inv_prop = 1-mask_prop
+
+    def __call__(self, y_true, y_pred):
+        # pylint: disable=invalid-name
+        tro, tgo, tbo = tf.split(y_true, 3, 3)
+        pro, pgo, pbo = tf.split(y_pred, 3, 3)
+
+        tr = tro
+        tg = tgo
+        tb = tbo
+
+        pr = pro
+        pg = pgo
+        pb = pbo
+        m = self.mask
+
+        m = m * self.mask_prop
+        m += self.mask_as_k_inv_prop
+        tr *= m
+        tg *= m
+        tb *= m
+
+        pr *= m
+        pg *= m
+        pb *= m
+
+        y = tf.concat([tr, tg, tb], 3)
+        p = tf.concat([pr, pg, pb], 3)
+
+        # yo = tf.stack([tro,tgo,tbo],3)
+        # po = tf.stack([pro,pgo,pbo],3)
+
+        return self.loss_func(y, p)
 # <<< END: from Dfaker >>> #
 
 

Reverts deepfakes/faceswap#665

This implementation of Keras Penalized Loss leads to the following tensorflow errors:

```2019-03-30 23:22:04.305508: E tensorflow/core/grappler/optimizers/dependency_optimizer.cc:666] Iteration = 0, topological sort failed with message: The graph couldn't be sorted in topological order.
2019-03-30 23:22:04.325095: E tensorflow/core/grappler/optimizers/dependency_optimizer.cc:666] Iteration = 1, topological sort failed with message: The graph couldn't be sorted in topological order.
2019-03-30 23:22:04.485177: E tensorflow/core/grappler/optimizers/dependency_optimizer.cc:666] Iteration = 0, topological sort failed with message: The graph couldn't be sorted in topological order.
2019-03-30 23:22:04.499192: E tensorflow/core/grappler/optimizers/dependency_optimizer.cc:666] Iteration = 1, topological sort failed with message: The graph couldn't be sorted in topological order.
```

