code: def register_loss(loss_fn=None, *, name=None):
      """Registers a class definition or Callable as an ivis loss function.
      A mapping will be created between the name and the loss function passed.
      If a class definition is provided, an instance will be created, passing the name
      as an argument.
  
      If no name is provided to this function, the name of the passed function will be used
      as a key.
  
      The loss function must have two parameters, (y_true, y_pred)
      and calculates the loss for a batch of triplet inputs (y_pred).
      y_pred is expected to be of shape: (3, batch_size, embedding_dims).
  
      Usage:
          .. code-block:: python
  
              @register_loss
              def custom_loss(y_true, y_pred):
                  pass
              model = Ivis(distance='custom_loss')"""
  
      if loss_fn is None:
          return functools.partial(register_loss, name=name)
  
      key = name or loss_fn.__name__
      if isinstance(loss_fn, type):
          loss_dict[key] = loss_fn(name=key)
      else:
          loss_dict[key] = loss_fn
      return loss_fn
  
imports: import functools
  from tensorflow.keras import backend
  import tensorflow
  from tensorflow import keras
  import numpy
  from .distances import euclidean_distance, manhattan_distance, chebyshev_distance, cosine_distance
label_desc: Use image node_id 1 for calling a global function with example usage: register_loss(loss_fn) and returns: loss_fn, functools