MCPcopy Create free account
hub / github.com/OpenImagingLab/FlashVSR / score

Method score

diffsynth/extensions/ImageQualityMetric/clip.py:67–97  ·  view source on GitHub ↗

Score the images based on the prompt. Args: images (Union[str, List[str], Image.Image, List[Image.Image]]): Path(s) to the image(s) or PIL image(s). prompt (str): The prompt text. Returns: List[float]: List of CLIP scores for the images.

(self, images: Union[str, List[str], Image.Image, List[Image.Image]], prompt: str)

Source from the content-addressed store, hash-verified

65
66 @torch.no_grad()
67 def score(self, images: Union[str, List[str], Image.Image, List[Image.Image]], prompt: str) -> List[float]:
68 """Score the images based on the prompt.
69
70 Args:
71 images (Union[str, List[str], Image.Image, List[Image.Image]]): Path(s) to the image(s) or PIL image(s).
72 prompt (str): The prompt text.
73
74 Returns:
75 List[float]: List of CLIP scores for the images.
76 """
77 if isinstance(images, (str, Image.Image)):
78 # Single image
79 if isinstance(images, str):
80 image = self.preprocess_val(Image.open(images)).unsqueeze(0).to(device=self.device, non_blocking=True)
81 else:
82 image = self.preprocess_val(images).unsqueeze(0).to(device=self.device, non_blocking=True)
83 return [self._calculate_score(image, prompt)]
84 elif isinstance(images, list):
85 # Multiple images
86 scores = []
87 for one_images in images:
88 if isinstance(one_images, str):
89 image = self.preprocess_val(Image.open(one_images)).unsqueeze(0).to(device=self.device, non_blocking=True)
90 elif isinstance(one_images, Image.Image):
91 image = self.preprocess_val(one_images).unsqueeze(0).to(device=self.device, non_blocking=True)
92 else:
93 raise TypeError("The type of parameter images is illegal.")
94 scores.append(self._calculate_score(image, prompt))
95 return scores
96 else:
97 raise TypeError("The type of parameter images is illegal.")

Callers

nothing calls this directly

Calls 2

_calculate_scoreMethod · 0.95
toMethod · 0.45

Tested by

no test coverage detected