def add_loss(graph):
    embedding = graph.get_tensor_by_name(tensor_names['embedding'])
    fg = graph.get_tensor_by_name(tensor_names['fg'])
    gt_labels = graph.get_tensor_by_name(tensor_names['gt_labels'])
    gt_fg = tf.greater(gt_labels, 0, name='gt_fg')
    shape = tuple(fg.get_shape().as_list())
    maxima = tf.nn.pool(tf.reshape(fg, ((1, 1) + shape)), [10, 10], 'MAX', 'SAME', strides=[1, 1], data_format='NCHW')
    maxima = tf.reshape(tf.equal(fg, maxima), shape, name='maxima')
    embedding = tf.reshape(embedding, ((1,) + tuple(embedding.get_shape().as_list())))
    embedding = tf.transpose(embedding, perm=[1, 0, 2, 3])
    (um_loss, emst, edges_u, edges_v, _) = ultrametric_loss_op(embedding, gt_labels, mask=maxima, coordinate_scale=0.01)
    assert (emst.name == emst_name)
    assert (edges_u.name == edges_u_name)
    assert (edges_v.name == edges_v_name)
    fg_loss = tf.losses.mean_squared_error(gt_fg, fg)
    loss = (um_loss + (10 * fg_loss))
    opt = tf.train.AdamOptimizer(learning_rate=5e-06, beta1=0.95, beta2=0.999, epsilon=1e-08)
    optimizer = opt.minimize(loss)
    return (loss, optimizer)
def add_loss(graph):
    embedding = graph.get_tensor_by_name(tensor_names['embedding'])
    fg = graph.get_tensor_by_name(tensor_names['fg'])
    gt_labels = graph.get_tensor_by_name(tensor_names['gt_labels'])
    gt_fg = tf.greater(gt_labels, 0, name='gt_fg')
    shape = tuple(fg.get_shape().as_list())
    maxima = tf.nn.pool(tf.reshape(fg, ((1, 1) + shape)), [10, 10], 'MAX', 'SAME', strides=[1, 1], data_format='NCHW')
    maxima = tf.reshape(tf.equal(fg, maxima), shape, name='maxima')
    embedding = tf.reshape(embedding, ((1,) + tuple(embedding.get_shape().as_list())))
    embedding = tf.transpose(embedding, perm=[1, 0, 2, 3])
    (um_loss, emst, edges_u, edges_v, _) = ultrametric_loss_op(embedding, gt_labels, mask=maxima, coordinate_scale=0.01)
    assert (emst.name == emst_name)
    assert (edges_u.name == edges_u_name)
    assert (edges_v.name == edges_v_name)
    fg_loss = tf.losses.mean_squared_error(gt_fg, fg)
    loss = (um_loss + (10 * fg_loss))
    opt = tf.train.AdamOptimizer(learning_rate=5e-06, beta1=0.95, beta2=0.999, epsilon=1e-08)
    optimizer = opt.minimize(loss)
    return (loss, optimizer)