helios.metrics.functional

Functions

calculate_psnr(→ float)

Calculate PSNR (Peak Signal-to-Noise Ratio).

calculate_psnr_torch(→ float)

Calculate PSNR (Peak Signal-to-Noise Ratio).

calculate_ssim(→ float)

Calculate SSIM (structural similarity).

calculate_ssim_torch(→ float)

Calculate SSIM (structural similarity).

calculate_mAP(→ float)

Calculate the mAP (Mean Average Precision).

calculate_mae(→ float)

Compute the MAE (Mean-Average Precision) score.

calculate_mae_torch(→ float)

Compute the MAE (Mean-Average Precision) score.

calculate_accuracy(→ float)

Calculate top-k accuracy.

calculate_precision(→ float)

Calculate macro-averaged precision across classes.

calculate_recall(→ float)

Calculate macro-averaged recall across classes.

calculate_f1(→ float)

Calculate macro-averaged F1 score.

calculate_rmse(→ float)

Calculate root mean squared error (RMSE).

Module Contents

helios.metrics.functional.calculate_psnr(img: numpy.typing.NDArray, img2: numpy.typing.NDArray, crop_border: int, input_order: str = 'HWC', test_y_channel: bool = False) float[source]

Calculate PSNR (Peak Signal-to-Noise Ratio).

Implementation follows: https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio

Parameters:
  • img – Images with range \([0, 255]\).

  • img2 – Images with range \([0, 255]\).

  • crop_border – Cropped pixels in each edge of an image. These pixels are not involved in the calculation.

  • input_order – (optional) whether the input order is "HWC" or "CHW".

  • test_y_channel – (optional) if true, test on Y channel of YCbCr.

Returns:

PSNR value.

helios.metrics.functional.calculate_psnr_torch(img: torch.Tensor, img2: torch.Tensor, crop_border: int, test_y_channel: bool = False) float[source]

Calculate PSNR (Peak Signal-to-Noise Ratio).

Implementation follows: https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio

Parameters:
  • img – Images with range \([0, 255]\).

  • img2 – Images with range \([0, 255]\).

  • crop_border – Cropped pixels in each edge of an image. These pixels are not involved in the calculation.

  • test_y_channel – (optional) if true, test on Y channel of YCbCr.

Returns:

PSNR value.

helios.metrics.functional.calculate_ssim(img: numpy.typing.NDArray, img2: numpy.typing.NDArray, crop_border: int, input_order: str = 'HWC', test_y_channel: bool = False) float[source]

Calculate SSIM (structural similarity).

Implementation follows: ‘Image quality assesment: From error visibility to structural similarity’. Results are identical to those of the official MATLAB code in https://ece.uwaterloo.ca/~z70wang/research/ssim/. For three-channel images, SSIM is calculated for each channel and then averaged.

Parameters:
  • img – Images with range \([0, 255]\).

  • img2 – Images with range \([0, 255]\).

  • crop_border – Cropped pixels in each edge of an image. These pixels are not involved in the calculation.

  • input_order – (optional) whether the input order is "HWC" or "CHW".

  • test_y_channel – (optional) if true, test on Y channel of YCbCr.

Returns:

SSIM.

helios.metrics.functional.calculate_ssim_torch(img: torch.Tensor, img2: torch.Tensor, crop_border: int, test_y_channel: bool = False) float[source]

Calculate SSIM (structural similarity).

Implementation follows: ‘Image quality assesment: From error visibility to structural similarity’. Results are identical to those of the official MATLAB code in https://ece.uwaterloo.ca/~z70wang/research/ssim/. For three-channel images, SSIM is calculated for each channel and then averaged.

Parameters:
  • img – Images with range \([0, 255]\).

  • img2 – Images with range \([0, 255]\).

  • crop_border – Cropped pixels in each edge of an image. These pixels are not involved in the calculation.

  • test_y_channel – (optional) if true, test on Y channel of YCbCr.

Returns:

SSIM.

helios.metrics.functional.calculate_mAP(targs: numpy.typing.NDArray, preds: numpy.typing.NDArray) float[source]

Calculate the mAP (Mean Average Precision).

Implementation follows: https://en.wikipedia.org/wiki/Evaluation_measures_(information_retrieval)#Mean_average_precision

Parameters:
  • targs – target (inferred) labels in range \([0, 1]\).

  • preds – predicate labels in range \([0, 1]\).

Returns:

The mAP score

helios.metrics.functional.calculate_mae(pred: numpy.typing.NDArray, gt: numpy.typing.NDArray, scale: float = 1.0) float[source]

Compute the MAE (Mean-Average Precision) score.

Implementation follows: https://en.wikipedia.org/wiki/Mean_absolute_error. The scale argument is used in the event that the input arrays are not in the range \([0, 1]\) but instead have been scaled to be in the range \([0, N]\) where \(N\) is the factor. For example, if the arrays are images in the range \([0, 255]\), then the scaling factor should be set to 255. If the arrays are already in the range \([0, 1]\), then the scale can be omitted.

Parameters:
  • pred – predicate (inferred) array

  • gt – ground-truth array

  • scale – (optional) scaling factor that was used on the input arrays.

Returns:

The MAE score.

helios.metrics.functional.calculate_mae_torch(pred: torch.Tensor, gt: torch.Tensor, scale: float = 1.0) float[source]

Compute the MAE (Mean-Average Precision) score.

Implementation follows: https://en.wikipedia.org/wiki/Mean_absolute_error. The scale argument is used in the event that the input arrays are not in the range \([0, 1]\) but instead have been scaled to be in the range \([0, N]\) where \(N\) is the factor. For example, if the arrays are images in the range \([0, 255]\), then the scaling factor should be set to 255. If the arrays are already in the range \([0, 1]\), then the scale can be omitted.

Parameters:
  • pred – predicate (inferred) tensor

  • gt – ground-truth tensor

  • scale – (optional) scaling factor that was used on the input tensors.

Returns:

The MAE score.

helios.metrics.functional.calculate_accuracy(predictions: torch.Tensor, targets: torch.Tensor, top_k: int = 1) float[source]

Calculate top-k accuracy.

Implementation follows: https://en.wikipedia.org/wiki/Evaluation_measures_(information_retrieval).

Parameters:
  • predictions – predicted logits or scores of shape \((N, C)\) where \(C\) is the number of classes.

  • targets – ground-truth class indices of shape \((N,)\).

  • top_k – (optional) number of top predictions to consider.

Returns:

Top-k accuracy in \([0, 1]\).

helios.metrics.functional.calculate_precision(predictions: torch.Tensor, targets: torch.Tensor) float[source]

Calculate macro-averaged precision across classes.

Implementation follows: https://en.wikipedia.org/wiki/Precision_and_recall.

Parameters:
  • predictions – predicted logits or scores of shape \((N, C)\), or predicted class indices of shape \((N,)\).

  • targets – ground-truth class indices of shape \((N,)\).

Returns:

Macro-averaged precision in range \([0, 1]\).

helios.metrics.functional.calculate_recall(predictions: torch.Tensor, targets: torch.Tensor) float[source]

Calculate macro-averaged recall across classes.

Implementation follows: https://en.wikipedia.org/wiki/Precision_and_recall.

Parameters:
  • predictions – predicted logits or scores of shape \((N, C)\), or predicted class indices of shape \((N,)\).

  • targets – ground-truth class indices of shape \((N,)\).

Returns:

Macro-averaged recall in range \([0, 1]\).

helios.metrics.functional.calculate_f1(predictions: torch.Tensor, targets: torch.Tensor) float[source]

Calculate macro-averaged F1 score.

Computed from the macro precision and recall. Implementation follows: https://en.wikipedia.org/wiki/F-score.

Parameters:
  • predictions – predicted logits or scores of shape \((N, C)\), or predicted class indices of shape \((N,)\).

  • targets – ground-truth class indices of shape \((N,)\).

Returns:

Macro-averaged F1 score in range \([0, 1]\).

helios.metrics.functional.calculate_rmse(predictions: torch.Tensor, targets: torch.Tensor) float[source]

Calculate root mean squared error (RMSE).

Implementation follows: https://en.wikipedia.org/wiki/Root_mean_square_deviation.

Parameters:
  • predictions – predicted values tensor.

  • targets – ground-truth values tensor.

Returns:

RMSE score.