class_docstr: Wrapper converting a loss function into a `Loss` object.
  
  This is to reuse logic of sample-weighted loss computation in `Loss` base
  class.
  
  Attributes:
    loss_fn: Underlying loss function.
    weight: Weight of this loss term in total loss. Should be applied outside
      of this class, e.g. `total_loss += loss.weight * loss(y_true, y_pred)`.
    batch_size_reduction: Whether to perform `SUM_OVER_BATCH_SIZE` reduction.
      This field is set in lieu of having `reduction=SUM_OVER_BATCH_SIZE`,
      because the latter is not supported when using with
      `tf.distribute.Strategy`.
code: def __init__(self, loss_fn, name, weight):
      reduction = getattr(loss_fn, "reduction", None)
      if reduction in (
          None,
          tf.losses.Reduction.SUM_OVER_BATCH_SIZE,
          tf.compat.v2.losses.Reduction.AUTO,
      ):
          reduction = tf.losses.Reduction.NONE
          self.batch_size_reduction = True
      else:
          self.batch_size_reduction = False
      super(_LossWrapper, self).__init__(name=name, reduction=reduction)
      self.weight = weight
      if (
          isinstance(loss_fn, tf.keras.losses.Loss)
          and self.batch_size_reduction
      ):
          self.loss_fn = loss_fn.__class__.from_config(
              loss_fn.get_config()
          )
          self.loss_fn.reduction = tf.losses.Reduction.NONE
      else:
          self.loss_fn = loss_fn
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  import functools
  import types
  import attr
  import neural_structured_learning.configs
  from neural_structured_learning.lib import adversarial_neighbor
  import six
  import tensorflow
label_desc: Use image node_id 1 to create a new _LossWrapper object from inherited base classes: tf.keras.losses with example: obj = _LossWrapper(loss_fn, name, weight)