Datasets:
zxooh46@uni-tuebingen.de
commited on
Commit
·
a5ab8f0
1
Parent(s):
fd7d805
Add video eval
Browse files
evaluation/videos/eval.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
import json
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
import sys
|
| 5 |
+
|
| 6 |
+
def point_in_box(px, py, x_min, y_min, x_max, y_max):
|
| 7 |
+
return (x_min <= px < x_max) and (y_min <= py < y_max)
|
| 8 |
+
|
| 9 |
+
def main():
|
| 10 |
+
|
| 11 |
+
parser = argparse.ArgumentParser()
|
| 12 |
+
|
| 13 |
+
parser.add_argument(
|
| 14 |
+
"--predictions", type=str, required=True, help="Path to json file with predictions for each video"
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
args = parser.parse_args()
|
| 18 |
+
|
| 19 |
+
try:
|
| 20 |
+
with open("videos_gt.json", 'r', encoding='utf-8') as f:
|
| 21 |
+
videos_gt = json.load(f)
|
| 22 |
+
|
| 23 |
+
with open(args.predictions, 'r', encoding='utf-8') as f:
|
| 24 |
+
preds = json.load(f)
|
| 25 |
+
except FileNotFoundError as e:
|
| 26 |
+
print(f"File not found: {e.filename}")
|
| 27 |
+
sys.exit(1)
|
| 28 |
+
|
| 29 |
+
except json.JSONDecodeError as e:
|
| 30 |
+
print(f"Invalid JSON in file: {e}")
|
| 31 |
+
sys.exit(1)
|
| 32 |
+
|
| 33 |
+
except Exception as e:
|
| 34 |
+
print(f"Unexpected error: {e}")
|
| 35 |
+
sys.exit(1)
|
| 36 |
+
|
| 37 |
+
total = 0
|
| 38 |
+
hits = 0
|
| 39 |
+
|
| 40 |
+
for video, annots in preds.items():
|
| 41 |
+
if videos_gt.get(video, None) is None:
|
| 42 |
+
print(f'{video} not present in GT')
|
| 43 |
+
continue
|
| 44 |
+
|
| 45 |
+
for frame, point in annots.items(): #point: (x,y)
|
| 46 |
+
if videos_gt[video].get(frame, None) is None:
|
| 47 |
+
print(f'Frame {frame} in {video} not present in GT')
|
| 48 |
+
continue
|
| 49 |
+
total+=1
|
| 50 |
+
GT_box = videos_gt[video].get(frame)
|
| 51 |
+
if point_in_box(*point, *GT_box):
|
| 52 |
+
hits+=1
|
| 53 |
+
|
| 54 |
+
print(f"Total: {total}, hits: {hits}")
|
| 55 |
+
print(f'Pointwise-Acc: {hits/total:.3f}')
|
| 56 |
+
|
| 57 |
+
if __name__ == "__main__":
|
| 58 |
+
main()
|
| 59 |
+
|
evaluation/videos/random_preds.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
evaluation/videos/videos_gt.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|