Spaces:
Running
Running
File size: 735 Bytes
4f41410 2c50826 199a7d9 2c50826 199a7d9 2c50826 199a7d9 2c50826 4f41410 2c50826 4f41410 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
from pathlib import Path
from typing import Dict
import t2v_metrics
import torch
class VQAMetric:
def __init__(self):
self.device = torch.device(
"cuda"
if torch.cuda.is_available()
else "mps"
if torch.backends.mps.is_available()
else "cpu"
)
self.metric = t2v_metrics.VQAScore(
model="clip-flant5-xxl", device=str(self.device)
)
@property
def name(self) -> str:
return "vqa_score"
def compute_score(
self,
image_path: Path,
prompt: str,
) -> Dict[str, float]:
score = self.metric(images=[str(image_path)], texts=[prompt])
return {"vqa": score[0][0].item()}
|