Skip to content

The compute Method

The compute method calculate the suite of metrics in the opensr-test framework. This method includes three mandatory parameters, and one optional parameter:

  • lr (torch.Tensor): The Low Resolution (LR) image tensor. The shape of the tensor should be (channel, height/n, width/n). Where n is the scaling factor of the Super-Resolution (SR) image.
  • sr (torch.Tensor): The Super-Resolved (SR) image tensor generated by the model under evaluation. The shape of the tensor should be (channel, height, width).
  • hr (torch.Tensor): The High Resolution (HR) image tensor (ground truth). The shape of the tensor should be (channel, height, width).
  • gradient_threshold (default=0.01): Ignore the pixels with distances below this threshold. This parameter is used to filter out pixels with insignificant differences between the SR, HR, and LR images. The default value is set to "auto75". The "auto75" value is calculated as 75-percentile of the gradient values between the LR and HR images. As the distance, between the LR and HR images, is always constant, we ensure that the threshold is the same independently of the SR model. If you want to use a different threshold, you can set it manually by passing a value between 0 and 100, i.e., gradient_threshold="auto90". Manual thresholding is also supported, i.e., gradient_threshold=0.01.

Below is an example that demonstrates the usage of the compute method with the aforementioned parameters:

# Import necessary libraries
import torch
import opensr_test
import matplotlib.pyplot as plt

# Generate sample LR, HR, and SR images
lr = torch.rand(4, 32, 32)  # Low Resolution image
hr = torch.rand(4, 256, 256)  # High Resolution image
sr = torch.rand(4, 256, 256)  # Super Resolution image

# Initialize the Metrics object
metrics = opensr_test.Metrics()

# Compute the metrics with specified parameters
metrics.compute( 
    lr=lr, sr=sr, hr=hr, gradient_threshold="auto90"
)
Back to top