vsg_eval / metrics /attribute_precision.py
royguw's picture
Add files using upload-large-folder tool
e3e1f6e verified
Raw History Blame Contribute Delete
846 Bytes
from metrics.base import SceneGraphMetric
from utils.prompts import build_attribute_precision_prompt
from utils.gpt import query_yes_no
class AttributePrecisionMetric(SceneGraphMetric):
def __init__(self):
super().__init__("attribute_precision")
def evaluate(self, gt_data, pred_data, api_key):
gt_map = {obj["label"]: [f'{a["name"]}: {a["value"]}' for a in obj["attributes"]] for obj in gt_data}
results = []
for obj in pred_data:
obj_name = obj["object"]
for attr in obj["attributes"]:
gt_attrs = gt_map.get(obj_name, [])
prompt = build_attribute_precision_prompt(obj_name, attr, gt_attrs)
result = query_yes_no(prompt, api_key)
results.append(result)
return sum(results) / len(results) if results else 0.0