shadow.losses module

shadow.losses.accuracy(y_pred, y)[source]

Classification accuracy.

Parameters
  • y_pred (array_like) – Predicted labels.

  • y (array_like) – True labels.

Returns

Classification accuracy percentage.

Return type

float

shadow.losses.mse_regress_loss(y_pred, y_true, reduction='sum')[source]

Measures the element-wise mean squared error (squared L2 norm) between two model outputs.

Directly passes y_pred, y_true, and reduction to torch.nn.function.mse_loss. mse_regress_loss differs from softmax_mse_loss in that it does not compute the softmax and therefore makes it applicable to regression tasks.

Parameters
  • y_pred (torch.Tensor) – The predicted labels.

  • y_true (torch.Tensor) – The target labels.

  • reduction (string, optional) – The reduction parameter passed to torch.nn.functional.mse_loss. Defaults to ‘sum’.

Returns

Mean squared error.

Return type

torch.Tensor

shadow.losses.softmax_kl_loss(input_logits, target_logits, reduction='sum')[source]

Apply softmax and compute KL divergence between two model outputs.

Parameters
  • input_logits (torch.Tensor) – The input unnormalized log probabilities.

  • target_logits (torch.Tensor) – The target unnormalized log probabilities.

  • reduction (string, optional) – The reduction parameter passed to torch.nn.functional.kl_div. Defaults to ‘sum’.

Returns

KL divergence.

Return type

torch.Tensor

shadow.losses.softmax_mse_loss(input_logits, target_logits, reduction='sum')[source]

Apply softmax and compute mean square error between two model outputs.

Parameters
  • input_logits (torch.Tensor) – The input unnormalized log probabilities.

  • target_logits (torch.Tensor) – The target unnormalized log probabilities.

  • reduction (string, optional) – The reduction parameter passed to torch.nn.functional.mse_loss. Defaults to ‘sum’.

Returns

Softmax mean squared error.

Return type

torch.Tensor