  
  
  def gradient_loss(y_true, y_pred):
      """
      Calculates the first and second order gradient difference between pixels of an image in the
      x and y dimensions. These gradients are then compared between the ground truth and the
      predicted image and the difference is taken. The difference used is a smooth L1 norm
      (approximate to MAE but differable at zero) When used as a loss, its minimization will result
      in predicted images approaching the samelevel of sharpness / blurriness as the ground truth.
  
      TV+TV2 Regularization with Nonconvex Sparseness-Inducing Penalty for Image Restoration,
      Chengwu Lu & Hua Huang, 2014 (http://downloads.hindawi.com/journals/mpe/2014/790547.pdf)
  
      Parameters:
 
</s> remove     TV+TV2 Regularization with Nonconvex Sparseness-Inducing Penalty for Image Restoration,
    Chengwu Lu & Hua Huang, 2014 (http://downloads.hindawi.com/journals/mpe/2014/790547.pdf)
 </s> add     TV+TV2 Regularization with Nonconvex Sparseness-Inducing Penalty
    for Image Restoration, Chengwu Lu & Hua Huang, 2014
    (http://downloads.hindawi.com/journals/mpe/2014/790547.pdf) </s> remove         y_true: The predicted frames at each scale.
 </s> add         y_true: The predicted frames at each scale </s> remove def staircase_loss(y_true, y_pred, var_a=16.0, cnst=1.0/255.0):
    """ Keras Staircase Loss """
    height = cnst
    width = cnst
    var_x = K.clip(K.abs(y_true - y_pred) - 0.5 * cnst, 0.0, 1.0)
    loss = height*(K.tanh(var_a*((var_x/width)-tf.floor(var_x/width)-0.5)) /
                   (2.0*K.tanh(var_a/2.0)) + 0.5 + tf.floor(var_x/width))
    loss += 1e-10
    return K.mean(loss, axis=-1)
 </s> add def l_p_norm(y_true, y_pred, p_norm=np.inf):
    """
    Calculate the L-p norm as a loss function,
    valid choics of p are [0,1,no.inf]
    """
    diff = y_true - y_pred
    loss = tf.norm(diff, ord=p_norm, axis=-1)
    return loss


def l_inf_norm(y_true, y_pred):
    """ Calculate the L-inf norm as a loss function """
    diff = K.abs(y_true - y_pred)
    max_loss = K.max(diff, axis=(1, 2), keepdims=True)
    loss = K.mean(max_loss, axis=-1)
    return loss </s> remove             x: First set of images.
            y: Second set of images.
 </s> add             img1: First set of images.
            img2: Second set of images. </s> remove               For non-covolutional version, this is usually tf.reduce_mean(x, [1, 2]),
 </s> add               For non-covolutional version, this is usually tf.reduce_mean(img1, [1, 2]),
    Calculates the first and second order gradient difference between pixels of
    an image in the x and y dimensions. These gradients are then compared between
    the ground truth and the predicted image and the difference is taken. When
    used as a loss, its minimization will result in predicted images approaching
    the same level of sharpness / blurriness as the ground truth.
  
  
  def gradient_loss(y_true, y_pred):
      """
    Calculates the first and second order gradient difference between pixels of
    an image in the x and y dimensions. These gradients are then compared between
    the ground truth and the predicted image and the difference is taken. When
    used as a loss, its minimization will result in predicted images approaching
    the same level of sharpness / blurriness as the ground truth.
    Calculates the first and second order gradient difference between pixels of
    an image in the x and y dimensions. These gradients are then compared between
    the ground truth and the predicted image and the difference is taken. When
    used as a loss, its minimization will result in predicted images approaching
    the same level of sharpness / blurriness as the ground truth.
    Calculates the first and second order gradient difference between pixels of
    an image in the x and y dimensions. These gradients are then compared between
    the ground truth and the predicted image and the difference is taken. When
    used as a loss, its minimization will result in predicted images approaching
    the same level of sharpness / blurriness as the ground truth.
    Calculates the first and second order gradient difference between pixels of
    an image in the x and y dimensions. These gradients are then compared between
    the ground truth and the predicted image and the difference is taken. When
    used as a loss, its minimization will result in predicted images approaching
    the same level of sharpness / blurriness as the ground truth.
    Calculates the first and second order gradient difference between pixels of
    an image in the x and y dimensions. These gradients are then compared between
    the ground truth and the predicted image and the difference is taken. When
    used as a loss, its minimization will result in predicted images approaching
    the same level of sharpness / blurriness as the ground truth.
  
      TV+TV2 Regularization with Nonconvex Sparseness-Inducing Penalty for Image Restoration,
      Chengwu Lu & Hua Huang, 2014 (http://downloads.hindawi.com/journals/mpe/2014/790547.pdf)
  
      Parameters:
keep keep keep keep replace replace replace replace replace keep keep keep keep keep
 documentation, pep8, style, clarity updates  - Prep for Segmentation (#812)

* documentation, pep8, style, clarity updates

* Update cli.py

* Update _config.py

remove extra mask and coverage

mask type as dropdown

* Update training_data.py

move coverage / LR to global
cut down on loss description

style change
losses working in PR

* simpler logging

* legacy update 
lib/model/losses.py