Datasets:

Modalities:
Image
Text
Formats:
webdataset
ArXiv:
Libraries:
Datasets
WebDataset
License:
File size: 1,580 Bytes
a5ab8f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
50
51
52
53
54
55
56
57
58
59
import argparse
import json
from pathlib import Path
import sys

def point_in_box(px, py, x_min, y_min, x_max, y_max):
    return (x_min <= px < x_max) and (y_min <= py < y_max)

def main():

    parser = argparse.ArgumentParser()

    parser.add_argument(
        "--predictions", type=str, required=True, help="Path to json file with predictions for each video"
    )

    args = parser.parse_args()

    try:
        with open("videos_gt.json", 'r', encoding='utf-8') as f:
            videos_gt = json.load(f)

        with open(args.predictions, 'r', encoding='utf-8') as f:
            preds = json.load(f)
    except FileNotFoundError as e:
        print(f"File not found: {e.filename}")
        sys.exit(1)

    except json.JSONDecodeError as e:
        print(f"Invalid JSON in file: {e}")
        sys.exit(1)

    except Exception as e:
        print(f"Unexpected error: {e}")
        sys.exit(1)

    total = 0
    hits = 0

    for video, annots in preds.items():
        if videos_gt.get(video, None) is None:
            print(f'{video} not present in GT')
            continue

        for frame, point in annots.items():  #point: (x,y)
            if videos_gt[video].get(frame, None) is None:
                print(f'Frame {frame} in {video} not present in GT')
                continue
            total+=1
            GT_box = videos_gt[video].get(frame)
            if point_in_box(*point, *GT_box):
                hits+=1

    print(f"Total: {total}, hits: {hits}")
    print(f'Pointwise-Acc: {hits/total:.3f}')

if __name__ == "__main__":
    main()