Download evaluate.py from royguw/vsg_eval: direct link, hf CLI and curl.
- Browser
- Download file 1.56 kB
-
https://huggingface.co/datasets/royguw/vsg_eval/resolve/main/evaluate.py
- Command line
-
hf download hf://datasets/royguw/vsg_eval/evaluate.py
-
curl -L -o evaluate.py https://huggingface.co/datasets/royguw/vsg_eval/resolve/main/evaluate.py
1.56 kB
| import os | |
| from utils.io import load_json, save_json, list_json_files | |
| from metrics.object_recall import ObjectRecallMetric | |
| from metrics.attribute_recall import AttributeRecallMetric | |
| from metrics.object_precision import ObjectPrecisionMetric | |
| from metrics.attribute_precision import AttributePrecisionMetric | |
| METRICS = [ | |
| ObjectRecallMetric(), | |
| AttributeRecallMetric(), | |
| ObjectPrecisionMetric(), | |
| AttributePrecisionMetric(), | |
| ] | |
| def evaluate_all(gt_folder, pred_folder, output_path, api_key): | |
| results = {} | |
| files = list_json_files(gt_folder) | |
| for file in files: | |
| gt_data = load_json(os.path.join(gt_folder, file)) | |
| pred_data = load_json(os.path.join(pred_folder, file)) | |
| per_video_result = {} | |
| for metric in METRICS: | |
| score = metric.evaluate(gt_data, pred_data, api_key) | |
| per_video_result[metric.name] = score | |
| results[file] = per_video_result | |
| summary = { | |
| metric.name: sum(r[metric.name] for r in results.values()) / len(results) | |
| for metric in METRICS | |
| } | |
| results["summary"] = summary | |
| save_json(results, output_path) | |
| if __name__ == "__main__": | |
| import argparse | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--gt_folder", required=True) | |
| parser.add_argument("--pred_folder", required=True) | |
| parser.add_argument("--output", default="results/evaluation_results.json") | |
| parser.add_argument("--api_key", required=True) | |
| args = parser.parse_args() | |
| evaluate_all(args.gt_folder, args.pred_folder, args.output, args.api_key) |