Download metrics/attribute_precision.py from royguw/vsg_eval: direct link, hf CLI and curl.
- Browser
- Download file 846 Bytes
-
https://huggingface.co/datasets/royguw/vsg_eval/resolve/main/metrics/attribute_precision.py
- Command line
-
hf download hf://datasets/royguw/vsg_eval/metrics/attribute_precision.py
-
curl -L -o attribute_precision.py https://huggingface.co/datasets/royguw/vsg_eval/resolve/main/metrics/attribute_precision.py
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 |