treex.losses.Reduction
Types of loss reduction.
Contains the following values:
* 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.
Source code in treex/losses/loss.py
class Reduction(Enum):
"""
Types of loss reduction.
Contains the following values:
* `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.
"""
# AUTO = "auto"
NONE = "none"
SUM = "sum"
SUM_OVER_BATCH_SIZE = "sum_over_batch_size"
@classmethod
def all(cls):
return (
# cls.AUTO,
cls.NONE,
cls.SUM,
cls.SUM_OVER_BATCH_SIZE,
)
@classmethod
def validate(cls, key):
if key not in cls.all():
raise ValueError("Invalid Reduction Key %s." % key)