helios.metrics.functional ========================= .. py:module:: helios.metrics.functional Functions --------- .. autoapisummary:: helios.metrics.functional.calculate_psnr helios.metrics.functional.calculate_psnr_torch helios.metrics.functional.calculate_ssim helios.metrics.functional.calculate_ssim_torch helios.metrics.functional.calculate_mAP helios.metrics.functional.calculate_mae helios.metrics.functional.calculate_mae_torch helios.metrics.functional.calculate_accuracy helios.metrics.functional.calculate_precision helios.metrics.functional.calculate_recall helios.metrics.functional.calculate_f1 helios.metrics.functional.calculate_rmse Module Contents --------------- .. py:function:: calculate_psnr(img: numpy.typing.NDArray, img2: numpy.typing.NDArray, crop_border: int, input_order: str = 'HWC', test_y_channel: bool = False) -> float Calculate PSNR (Peak Signal-to-Noise Ratio). Implementation follows: ``__ :param img: Images with range :math:`[0, 255]`. :param img2: Images with range :math:`[0, 255]`. :param crop_border: Cropped pixels in each edge of an image. These pixels are not involved in the calculation. :param input_order: (optional) whether the input order is ``"HWC"`` or ``"CHW"``. :param test_y_channel: (optional) if true, test on Y channel of YCbCr. :returns: PSNR value. .. py:function:: calculate_psnr_torch(img: torch.Tensor, img2: torch.Tensor, crop_border: int, test_y_channel: bool = False) -> float Calculate PSNR (Peak Signal-to-Noise Ratio). Implementation follows: ``__ :param img: Images with range :math:`[0, 255]`. :param img2: Images with range :math:`[0, 255]`. :param crop_border: Cropped pixels in each edge of an image. These pixels are not involved in the calculation. :param test_y_channel: (optional) if true, test on Y channel of YCbCr. :returns: PSNR value. .. py:function:: calculate_ssim(img: numpy.typing.NDArray, img2: numpy.typing.NDArray, crop_border: int, input_order: str = 'HWC', test_y_channel: bool = False) -> float 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 ``__. For three-channel images, SSIM is calculated for each channel and then averaged. :param img: Images with range :math:`[0, 255]`. :param img2: Images with range :math:`[0, 255]`. :param crop_border: Cropped pixels in each edge of an image. These pixels are not involved in the calculation. :param input_order: (optional) whether the input order is ``"HWC"`` or ``"CHW"``. :param test_y_channel: (optional) if true, test on Y channel of YCbCr. :returns: SSIM. .. py:function:: calculate_ssim_torch(img: torch.Tensor, img2: torch.Tensor, crop_border: int, test_y_channel: bool = False) -> float 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 ``__. For three-channel images, SSIM is calculated for each channel and then averaged. :param img: Images with range :math:`[0, 255]`. :param img2: Images with range :math:`[0, 255]`. :param crop_border: Cropped pixels in each edge of an image. These pixels are not involved in the calculation. :param test_y_channel: (optional) if true, test on Y channel of YCbCr. :returns: SSIM. .. py:function:: calculate_mAP(targs: numpy.typing.NDArray, preds: numpy.typing.NDArray) -> float Calculate the mAP (Mean Average Precision). Implementation follows: ``__ :param targs: target (inferred) labels in range :math:`[0, 1]`. :param preds: predicate labels in range :math:`[0, 1]`. :returns: The mAP score .. py:function:: calculate_mae(pred: numpy.typing.NDArray, gt: numpy.typing.NDArray, scale: float = 1.0) -> float Compute the MAE (Mean-Average Precision) score. Implementation follows: ``__. The scale argument is used in the event that the input arrays are not in the range :math:`[0, 1]` but instead have been scaled to be in the range :math:`[0, N]` where :math:`N` is the factor. For example, if the arrays are images in the range :math:`[0, 255]`, then the scaling factor should be set to 255. If the arrays are already in the range :math:`[0, 1]`, then the scale can be omitted. :param pred: predicate (inferred) array :param gt: ground-truth array :param scale: (optional) scaling factor that was used on the input arrays. :returns: The MAE score. .. py:function:: calculate_mae_torch(pred: torch.Tensor, gt: torch.Tensor, scale: float = 1.0) -> float Compute the MAE (Mean-Average Precision) score. Implementation follows: ``__. The scale argument is used in the event that the input arrays are not in the range :math:`[0, 1]` but instead have been scaled to be in the range :math:`[0, N]` where :math:`N` is the factor. For example, if the arrays are images in the range :math:`[0, 255]`, then the scaling factor should be set to 255. If the arrays are already in the range :math:`[0, 1]`, then the scale can be omitted. :param pred: predicate (inferred) tensor :param gt: ground-truth tensor :param scale: (optional) scaling factor that was used on the input tensors. :returns: The MAE score. .. py:function:: calculate_accuracy(predictions: torch.Tensor, targets: torch.Tensor, top_k: int = 1) -> float Calculate top-k accuracy. Implementation follows: ``__. :param predictions: predicted logits or scores of shape :math:`(N, C)` where :math:`C` is the number of classes. :param targets: ground-truth class indices of shape :math:`(N,)`. :param top_k: (optional) number of top predictions to consider. :returns: Top-k accuracy in :math:`[0, 1]`. .. py:function:: calculate_precision(predictions: torch.Tensor, targets: torch.Tensor) -> float Calculate macro-averaged precision across classes. Implementation follows: ``__. :param predictions: predicted logits or scores of shape :math:`(N, C)`, or predicted class indices of shape :math:`(N,)`. :param targets: ground-truth class indices of shape :math:`(N,)`. :returns: Macro-averaged precision in range :math:`[0, 1]`. .. py:function:: calculate_recall(predictions: torch.Tensor, targets: torch.Tensor) -> float Calculate macro-averaged recall across classes. Implementation follows: ``__. :param predictions: predicted logits or scores of shape :math:`(N, C)`, or predicted class indices of shape :math:`(N,)`. :param targets: ground-truth class indices of shape :math:`(N,)`. :returns: Macro-averaged recall in range :math:`[0, 1]`. .. py:function:: calculate_f1(predictions: torch.Tensor, targets: torch.Tensor) -> float Calculate macro-averaged F1 score. Computed from the macro precision and recall. Implementation follows: ``__. :param predictions: predicted logits or scores of shape :math:`(N, C)`, or predicted class indices of shape :math:`(N,)`. :param targets: ground-truth class indices of shape :math:`(N,)`. :returns: Macro-averaged F1 score in range :math:`[0, 1]`. .. py:function:: calculate_rmse(predictions: torch.Tensor, targets: torch.Tensor) -> float Calculate root mean squared error (RMSE). Implementation follows: ``__. :param predictions: predicted values tensor. :param targets: ground-truth values tensor. :returns: RMSE score.