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 clip" ) args = parser.parse_args() try: with open("clips_gt.json", 'r', encoding='utf-8') as f: clips_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 clip, annots in preds.items(): if clips_gt.get(clip, None) is None: print(f'{clip} not present in GT') continue for frame, point in annots.items(): #point: (x,y) if clips_gt[clip].get(frame, None) is None: print(f'Frame {frame} in {clip} not present in GT') continue total+=1 GT_box = clips_gt[clip].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()