Datasets:
Delete clips/eval.py
Browse files- clips/eval.py +0 -59
clips/eval.py
DELETED
|
@@ -1,59 +0,0 @@
|
|
| 1 |
-
import argparse
|
| 2 |
-
import json
|
| 3 |
-
from pathlib import Path
|
| 4 |
-
import sys
|
| 5 |
-
|
| 6 |
-
def point_in_xywh(px, py, x, y, w, h):
|
| 7 |
-
return (x <= px < x + w) and (y <= py < y + h)
|
| 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 clip"
|
| 15 |
-
)
|
| 16 |
-
|
| 17 |
-
args = parser.parse_args()
|
| 18 |
-
|
| 19 |
-
try:
|
| 20 |
-
with open("clips_gt.json", 'r', encoding='utf-8') as f:
|
| 21 |
-
clips_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 clip, annots in preds.items():
|
| 41 |
-
if clips_gt.get(clip, None) is None:
|
| 42 |
-
print(f'{clip} not present in GT')
|
| 43 |
-
continue
|
| 44 |
-
|
| 45 |
-
for frame, point in annots.items(): #point: (x,y)
|
| 46 |
-
if clips_gt[clip].get(frame, None) is None:
|
| 47 |
-
print(f'Frame {frame} in {clip} not present in GT')
|
| 48 |
-
continue
|
| 49 |
-
total+=1
|
| 50 |
-
GT_box = clips_gt[clip].get(frame)
|
| 51 |
-
if point_in_xywh(*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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|