mindscience.common.MTLWeightedLoss

class mindscience.common.MTLWeightedLoss(num_losses, bound_param=0.0)[source]

Compute the MTL strategy weighted multi-task losses automatically. For more information, please refer to MTL weighted losses .

Parameters
  • num_losses (int) – The number of multi-task losses, should be positive integer.

  • bound_param (float, optional) – The square addition to weight and regularization when the mere bound is higher than certain constant given. Default: 0.0.

Inputs:
  • input (tuple[Tensor]) - The input data.

Outputs:
  • output (Tensor) - Losses for MTL weighted strategy.

Examples

>>> import numpy as np
>>> from mindscience.common import MTLWeightedLoss
>>> import mindspore
>>> from mindspore import Tensor
>>> net = MTLWeightedLoss(num_losses=2)
>>> input1 = Tensor(1.0, mindspore.float32)
>>> input2 = Tensor(0.8, mindspore.float32)
>>> output = net((input1, input2))
>>> print(output)
2.2862945