Datasets:

Modalities:
Image
Text
Formats:
webdataset
ArXiv:
Libraries:
Datasets
WebDataset
License:
niranjangaurav17's picture
Upload clips eval script
472a66a verified
raw
history blame
1.55 kB
import argparse
import json
from pathlib import Path
import sys
def point_in_xywh(px, py, x, y, w, h):
return (x <= px < x + w) and (y <= py < y + h)
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_xywh(*point, *GT_box):
hits+=1
print(f"Total: {total}, hits: {hits}")
print(f'Pointwise-Acc: {hits/total:.3f}')
if __name__ == "__main__":
main()