          a loss value from the results of function(y_pred - y_true)
  
      Example:
          a=1.0, x>>c , c=1.0/255.0 will give a smoothly differentiable version of L1 / MAE loss
          a=1.999999 (lim as a->2), c=1.0/255.0 will give L2 / RMSE loss
      """
      var_x = y_pred - y_true
      loss = (K.abs(2.0-var_a)/var_a) * (K.pow(K.pow(var_x/cnst, 2.0)/K.abs(2.0-var_a) + 1.0,
                                               (var_a/2.0)) - 1.0)
      return K.mean(loss, axis=-1) * cnst
 
</s> remove     var_x = y_pred - y_true
    loss = (K.abs(2.0-var_a)/var_a) * (K.pow(K.pow(var_x/cnst, 2.0)/K.abs(2.0-var_a) + 1.0,
                                             (var_a/2.0)) - 1.0)
    return K.mean(loss, axis=-1) * cnst
 </s> add     diff = y_pred - y_true
    second = (K.pow(K.pow(diff/beta, 2.) / K.abs(2.-alpha) + 1., (alpha/2.)) - 1.)
    loss = (K.abs(2.-alpha)/alpha) * second
    loss = K.mean(loss, axis=-1) * beta
    return loss </s> remove         a: penalty factor. larger number give larger weight to large deviations
        c: scale factor used to adjust to the input scale (i.e. inputs of mean 1e-4 or 256)

 </s> add         alpha: penalty factor. larger number give larger weight to large deviations
        beta: scale factor used to adjust to the input scale (i.e. inputs of mean 1e-4 or 256 ) </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 def generalized_loss_function(y_true, y_pred, var_a=1.0, cnst=1.0/255.0):
 </s> add def generalized_loss(y_true, y_pred, alpha=1.0, beta=1.0/255.0): </s> remove 
    def diff_x(var_x):
        xleft = var_x[:, :, 1, :] - var_x[:, :, 0, :]
        xinner = tf.unstack(var_x[:, :, 2:, :] - var_x[:, :, :-2, :], axis=2)
        xright = var_x[:, :, -1, :] - var_x[:, :, -2, :]
        xout = [xleft] + xinner + [xright]
        xout = tf.stack(xout, axis=2)
        return xout * 0.5

    def diff_y(var_x):
        xtop = var_x[:, 1, :, :] - var_x[:, 0, :, :]
        xinner = tf.unstack(var_x[:, 2:, :, :] - var_x[:, :-2, :, :], axis=1)
        xbot = var_x[:, -1, :, :] - var_x[:, -2, :, :]
        xout = [xtop] + xinner + [xbot]
        xout = tf.stack(xout, axis=1)
        return xout * 0.5

    def diff_xx(var_x):
        xleft = var_x[:, :, 1, :] + var_x[:, :, 0, :]
        xinner = tf.unstack(var_x[:, :, 2:, :] + var_x[:, :, :-2, :], axis=2)
        xright = var_x[:, :, -1, :] + var_x[:, :, -2, :]
        xout = [xleft] + xinner + [xright]
        xout = tf.stack(xout, axis=2)
        return xout - 2.0 * var_x

    def diff_yy(var_x):
        xtop = var_x[:, 1, :, :] + var_x[:, 0, :, :]
        xinner = tf.unstack(var_x[:, 2:, :, :] + var_x[:, :-2, :, :], axis=1)
        xbot = var_x[:, -1, :, :] + var_x[:, -2, :, :]
        xout = [xtop] + xinner + [xbot]
        xout = tf.stack(xout, axis=1)
        return xout - 2.0 * var_x

    def diff_xy(var_x):
        # xout1
        top_left = var_x[:, 1, 1, :]+var_x[:, 0, 0, :]
        inner_left = tf.unstack(var_x[:, 2:, 1, :]+var_x[:, :-2, 0, :], axis=1)
        bot_left = var_x[:, -1, 1, :]+var_x[:, -2, 0, :]
        x_left = [top_left] + inner_left + [bot_left]
        x_left = tf.stack(x_left, axis=1)

        top_mid = var_x[:, 1, 2:, :]+var_x[:, 0, :-2, :]
        mid_mid = tf.unstack(var_x[:, 2:, 2:, :]+var_x[:, :-2, :-2, :], axis=1)
        bot_mid = var_x[:, -1, 2:, :]+var_x[:, -2, :-2, :]
        x_mid = [top_mid] + mid_mid + [bot_mid]
        x_mid = tf.stack(x_mid, axis=1)

        top_right = var_x[:, 1, -1, :]+var_x[:, 0, -2, :]
        inner_right = tf.unstack(var_x[:, 2:, -1, :]+var_x[:, :-2, -2, :], axis=1)
        bot_right = var_x[:, -1, -1, :]+var_x[:, -2, -2, :]
        x_right = [top_right] + inner_right + [bot_right]
        x_right = tf.stack(x_right, axis=1)

        x_mid = tf.unstack(x_mid, axis=2)
        xout1 = [x_left] + x_mid + [x_right]
        xout1 = tf.stack(xout1, axis=2)

        # xout2
        top_left = var_x[:, 0, 1, :]+var_x[:, 1, 0, :]
        inner_left = tf.unstack(var_x[:, :-2, 1, :]+var_x[:, 2:, 0, :], axis=1)
        bot_left = var_x[:, -2, 1, :]+var_x[:, -1, 0, :]
        x_left = [top_left] + inner_left + [bot_left]
        x_left = tf.stack(x_left, axis=1)

        top_mid = var_x[:, 0, 2:, :]+var_x[:, 1, :-2, :]
        mid_mid = tf.unstack(var_x[:, :-2, 2:, :]+var_x[:, 2:, :-2, :], axis=1)
        bot_mid = var_x[:, -2, 2:, :]+var_x[:, -1, :-2, :]
        x_mid = [top_mid] + mid_mid + [bot_mid]
        x_mid = tf.stack(x_mid, axis=1)

        top_right = var_x[:, 0, -1, :]+var_x[:, 1, -2, :]
        inner_right = tf.unstack(var_x[:, :-2, -1, :]+var_x[:, 2:, -2, :], axis=1)
        bot_right = var_x[:, -2, -1, :]+var_x[:, -1, -2, :]
        x_right = [top_right] + inner_right + [bot_right]
        x_right = tf.stack(x_right, axis=1)

        x_mid = tf.unstack(x_mid, axis=2)
        xout2 = [x_left] + x_mid + [x_right]
        xout2 = tf.stack(xout2, axis=2)

        return (xout1 - xout2) * 0.25

    loss += tv_weight * (generalized_loss_function(diff_x(y_true),
                                                   diff_x(y_pred),
                                                   var_a=1.999999) +
                         generalized_loss_function(diff_y(y_true),
                                                   diff_y(y_pred),
                                                   var_a=1.999999))

    loss += tv2_weight * (generalized_loss_function(diff_xx(y_true),
                                                    diff_xx(y_pred),
                                                    var_a=1.999999) +
                          generalized_loss_function(diff_yy(y_true),
                                                    diff_yy(y_pred),
                                                    var_a=1.999999) +
                          2.0 * generalized_loss_function(diff_xy(y_true),
                                                          diff_xy(y_pred),
                                                          var_a=1.999999))

    return loss / (tv_weight + tv2_weight)
 </s> add     loss += tv_weight * (generalized_loss(diff_x(y_true), diff_x(y_pred), alpha=1.9999) +
                         generalized_loss(diff_y(y_true), diff_y(y_pred), alpha=1.9999))
    loss += tv2_weight * (generalized_loss(diff_xx(y_true), diff_xx(y_pred), alpha=1.9999) +
                          generalized_loss(diff_yy(y_true), diff_yy(y_pred), alpha=1.9999) +
                          generalized_loss(diff_xy(y_true), diff_xy(y_pred), alpha=1.9999) * 2.)
    loss = loss / (tv_weight + tv2_weight)
    # TODO simplify to use MSE instead
    return loss
        a=1.999999 (lim as a->2), beta=1.0/255.0 will give L2 / RMSE loss
          a loss value from the results of function(y_pred - y_true)
  
      Example:
          a=1.0, x>>c , c=1.0/255.0 will give a smoothly differentiable version of L1 / MAE loss
        a=1.999999 (lim as a->2), beta=1.0/255.0 will give L2 / RMSE loss
      """
      var_x = y_pred - y_true
      loss = (K.abs(2.0-var_a)/var_a) * (K.pow(K.pow(var_x/cnst, 2.0)/K.abs(2.0-var_a) + 1.0,
                                               (var_a/2.0)) - 1.0)
      return K.mean(loss, axis=-1) * cnst
keep keep keep keep 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