Image Quality Metrics
LPIPSMetric
Bases: BaseImageQualityMetric
LPIPS Metric to compute the Learned Perceptual Image Patch Similarity (LPIPS) score between two images. LPIPS essentially computes the similarity between the activations of two image patches for some pre-defined network. This measure has been shown to match human perception well. A low LPIPS score means that image patches are perceptual similar.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lpips_net_type |
str
|
The network type to use for computing LPIPS. One of "alex", "vgg", or "squeeze". |
'alex'
|
image_size |
Tuple[int, int]
|
The size to which images will be resized before computing LPIPS. |
(512, 512)
|
name |
str
|
The name of the metric. |
'alexnet_learned_perceptual_image_patch_similarity'
|
Source code in hemm/metrics/image_quality/lpips.py
PSNRMetric
Bases: BaseImageQualityMetric
PSNR Metric to compute the Peak Signal-to-Noise Ratio (PSNR) between two images.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
psnr_data_range |
Optional[Union[float, Tuple[float, float]]]
|
The data range of the input image (min, max). If None, the data range is determined from the image data type. |
None
|
psnr_base |
float
|
The base of the logarithm in the PSNR formula. |
10.0
|
image_size |
Tuple[int, int]
|
The size to which images will be resized before computing PSNR. |
(512, 512)
|
name |
str
|
The name of the metric. |
'peak_signal_noise_ratio'
|
Source code in hemm/metrics/image_quality/psnr.py
SSIMMetric
Bases: BaseImageQualityMetric
SSIM Metric to compute the Structural Similarity Index Measure (SSIM) between two images.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ssim_gaussian_kernel |
bool
|
Whether to use a Gaussian kernel for SSIM computation. |
True
|
ssim_sigma |
float
|
The standard deviation of the Gaussian kernel. |
1.5
|
ssim_kernel_size |
int
|
The size of the Gaussian kernel. |
11
|
ssim_data_range |
Optional[Union[float, Tuple[float, float]]]
|
The data range of the input image (min, max). If None, the data range is determined from the image data type. |
None
|
ssim_k1 |
float
|
The constant used to stabilize the SSIM numerator. |
0.01
|
ssim_k2 |
float
|
The constant used to stabilize the SSIM denominator. |
0.03
|
image_size |
Tuple[int, int]
|
The size to which images will be resized before computing SSIM. |
(512, 512)
|
name |
str
|
The name of the metric. |
'structural_similarity_index_measure'
|
Source code in hemm/metrics/image_quality/ssim.py
BaseImageQualityMetric
Bases: ABC
Source code in hemm/metrics/image_quality/base.py
__call__(prompt, ground_truth_image, model_output)
Compute the metric for the given images. This method is used as the scorer
function for weave.Evaluation
in the evaluation pipelines.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt |
str
|
Prompt for the image generation. |
required |
ground_truth_image |
str
|
Ground truth image in base64 format. |
required |
model_output |
Dict[str, Any]
|
Model output containing the generated image. |
required |
Returns:
Type | Description |
---|---|
Union[float, Dict[str, float]]
|
Union[float, Dict[str, float]]: Metric score. |
Source code in hemm/metrics/image_quality/base.py
__init__(name)
Base class for Image Quality Metrics.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
Name of the metric. |
required |
compute_metric(ground_truth_pil_image, generated_pil_image, prompt)
abstractmethod
Compute the metric for the given images. This is an abstract method and must be overriden by the child class implementation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ground_truth_pil_image |
Image
|
Ground truth image in PIL format. |
required |
generated_pil_image |
Image
|
Generated image in PIL format. |
required |
prompt |
str
|
Prompt for the image generation. |
required |
Returns:
Name | Type | Description |
---|---|---|
ComputeMetricOutput |
ComputeMetricOutput
|
Output containing the metric score and ground truth image. |