pyiqa.archs.fgresq_arch

FGResQ metric implementation.

Reference:

Sheng, X., Pan, X., Yang, Z., Chen, P., and Li, L. Fine-grained Image Quality Assessment for Perceptual Image Restoration. AAAI 2026.

Reference URL:

https://github.com/sxfly99/FGResQ

Module Contents

pyiqa.archs.fgresq_arch.default_model_urls[source]
pyiqa.archs.fgresq_arch.load_checkpoint(model_path)[source]

Load and normalize a checkpoint state dict.

Parameters:

model_path (str) – Path to the checkpoint file.

Returns:

Cleaned state dict.

Return type:

dict

pyiqa.archs.fgresq_arch.get_pooler_output(model, x)[source]

Extract pooled CLIP visual features.

Parameters:
  • model (CLIPVisionModel) – CLIP vision backbone.

  • x (torch.Tensor) – Input tensor.

Returns:

Pooled feature tensor.

Return type:

torch.Tensor

class pyiqa.archs.fgresq_arch.FGResQ(clip_model='openai/clip-vit-base-patch16', task_clip_model='openai/clip-vit-base-patch16', clip_freeze=True, pretrained=True, pretrained_model_path=None, degradation_model_path=None, input_size=224, resize_size=256, default_mean=OPENAI_CLIP_MEAN, default_std=OPENAI_CLIP_STD, score_scale=0.3)[source]

Bases: torch.nn.Module

FGResQ no-reference image quality model.

Parameters:
  • clip_model (str) – HuggingFace CLIP vision backbone id.

  • task_clip_model (str) – CLIP backbone for the degradation-aware branch.

  • clip_freeze (bool) – Whether to freeze the main CLIP backbone.

  • pretrained (bool) – Whether to load official pretrained weights.

  • pretrained_model_path (str | None) – Optional local checkpoint path for the main FGResQ weights.

  • degradation_model_path (str | None) – Optional local checkpoint path for the degradation branch weights.

  • input_size (int) – Final center crop size.

  • resize_size (int) – Resize size before center crop.

  • given (The network returns a single quality score when only x0 is)

:param : :param and returns quality0: :param quality1: :param rank: :param and rank_prob: :param when both x0 and x1 are provided.: :param default_mean: Input normalization mean. :type default_mean: tuple[float, float, float] :param default_std: Input normalization std. :type default_std: tuple[float, float, float] :param score_scale: Scale factor used before the sigmoid output head. :type score_scale: float

load_degradation_weights(model_path)[source]

Load degradation-branch weights.

Parameters:

model_path (str) – Path to the degradation checkpoint.

load_pretrained_weights(model_path)[source]

Load main FGResQ weights.

Parameters:

model_path (str) – Path to the FGResQ checkpoint.

preprocess(x)[source]

Preprocess an input image tensor.

Parameters:

x (torch.Tensor) – Input tensor with shape (N, C, H, W).

Returns:

Preprocessed tensor.

Return type:

torch.Tensor

get_quality_features(x)[source]

Extract FGResQ quality features.

Parameters:

x (torch.Tensor) – Preprocessed image tensor.

Returns:

Concatenated quality features.

Return type:

torch.Tensor

forward_single(x)[source]

Predict single-image quality.

Parameters:

x (torch.Tensor) – Preprocessed image tensor.

Returns:

Predicted quality score.

Return type:

torch.Tensor

forward_pair(x0, x1)[source]

Predict pairwise quality and comparison logits.

Parameters:
  • x0 (torch.Tensor) – First preprocessed image tensor.

  • x1 (torch.Tensor) – Second preprocessed image tensor.

Returns:

Single-image scores for both inputs and pairwise comparison logits.

Return type:

tuple[torch.Tensor, torch.Tensor, torch.Tensor]

get_pair_rank(compare_logits)[source]

Convert comparison logits to a discrete rank label.

Parameters:

compare_logits (torch.Tensor) – Pairwise comparison logits.

Returns:

Rank tensor with shape (N, 1) where 0=image2_better, 1=image1_better, and 2=similar_quality.

Return type:

torch.Tensor

get_pair_result(quality0, quality1, compare_logits)[source]

Format pairwise prediction outputs.

Parameters:
  • quality0 (torch.Tensor) – Quality of the first image.

  • quality1 (torch.Tensor) – Quality of the second image.

  • compare_logits (torch.Tensor) – Pairwise comparison logits.

Returns:

quality0, quality1, rank, and rank_prob.

Return type:

tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]

forward(x0, x1=None)[source]

Forward pass for FGResQ.

Parameters:
  • x0 (torch.Tensor) – First input tensor.

  • x1 (torch.Tensor | None) – Optional second input tensor.

Returns:

Output depends on whether x1 is given.

Return type:

torch.Tensor | tuple