B
    )²ô`É
  ã               @   s<   d Z ddlmZ ddlmZ ddlmZ G dd„ deƒZdS )z3The TF2 version of the enum keras.losses.Reduction.é    )Úabsolute_import)Údivision)Úprint_functionc               @   s8   e Zd ZdZdZdZdZdZedd„ ƒZ	edd	„ ƒZ
d
S )ÚReductionV2a  Types of loss reduction.

  Contains the following values:

  * `AUTO`: Indicates that the reduction option will be determined by the usage
     context. For almost all cases this defaults to `SUM_OVER_BATCH_SIZE`. When
     used with `tf.distribute.Strategy`, outside of built-in training loops such
     as `tf.keras` `compile` and `fit`, we expect reduction value to be
     `SUM` or `NONE`. Using `AUTO` in that case will raise an error.
  * `NONE`: Weighted losses with one dimension reduced (axis=-1, or axis
     specified by loss function). When this reduction type used with built-in
     Keras training loops like `fit`/`evaluate`, the unreduced vector loss is
     passed to the optimizer but the reported loss will be a scalar value.
  * `SUM`: Scalar sum of weighted losses.
  * `SUM_OVER_BATCH_SIZE`: Scalar `SUM` divided by number of elements in losses.
     This reduction type is not supported when used with
     `tf.distribute.Strategy` outside of built-in training loops like `tf.keras`
     `compile`/`fit`.

     You can implement 'SUM_OVER_BATCH_SIZE' using global batch size like:
     ```
     with strategy.scope():
       loss_obj = tf.keras.losses.CategoricalCrossentropy(
           reduction=tf.keras.losses.Reduction.NONE)
       ....
       loss = tf.reduce_sum(loss_object(labels, predictions)) *
           (1. / global_batch_size)
     ```

  Please see the
  [custom training guide](https://www.tensorflow.org/tutorials/distribute/custom_training)  # pylint: disable=line-too-long
  for more details on this.
  ÚautoÚnoneÚsumZsum_over_batch_sizec             C   s   | j | j| j| jfS )N)ÚAUTOÚNONEÚSUMÚSUM_OVER_BATCH_SIZE)Úcls© r   úZ/home/dcms/DCMS/lib/python3.7/site-packages/tensorflow/python/ops/losses/loss_reduction.pyÚall=   s    zReductionV2.allc             C   s   ||   ¡ krtd| ƒ‚d S )NzInvalid Reduction Key %s.)r   Ú
ValueError)r   Úkeyr   r   r   ÚvalidateA   s    zReductionV2.validateN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   r
   r   r   Úclassmethodr   r   r   r   r   r   r      s   !r   N)r   Ú
__future__r   r   r   Úobjectr   r   r   r   r   Ú<module>   s   