File size: 1,407 Bytes
e5e4b98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Copyright (c) Meta Platforms, Inc. and affiliates. All Rights Reserved

"""Simple script to run the CGF1 evaluator given a prediction file and GT file(s).

Usage: python standalone_cgf1.py --pred_file <path_to_prediction_file> --gt_files <path_to_gt_file1> <path_to_gt_file2> ...
"""

import argparse

from sam3.eval.cgf1_eval import CGF1Evaluator


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--pred_file",
        type=str,
        required=True,
        help="Path to the prediction file in COCO format.",
    )
    parser.add_argument(
        "--gt_files",
        type=str,
        nargs="+",
        required=True,
        help="Paths to the ground truth files in COCO format.",
    )
    args = parser.parse_args()
    if len(args.gt_files) == 0:
        raise ValueError("At least one GT file must be provided.")

    is_gold = args.gt_files[0].split("_")[-1].startswith("gold_")
    if is_gold and len(args.gt_files) < 3:
        print(
            "WARNING: based on the name, it seems you are using gold GT files. Typically, there should be 3 GT files for gold subsets (a, b, c)."
        )

    evaluator = CGF1Evaluator(
        gt_path=args.gt_files, verbose=True, iou_type="segm"
    )  # change to bbox if you want detection performance

    results = evaluator.evaluate(args.pred_file)

    print(results)


if __name__ == "__main__":
    main()