File size: 481 Bytes
4f41410
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
from pathlib import Path
from typing import Dict

import t2v_metrics

class VQAMetric:
    def __init__(self):
        self.metric = t2v_metrics.VQAScore(model="clip-flant5-xxl")
    
    @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()}