-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo_inference_TS.py
64 lines (49 loc) · 1.53 KB
/
video_inference_TS.py
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
60
61
62
63
64
import os
import json
from tqdm import tqdm
import operator
from test_yolo_data_cluster import YOLOCustom
# format json {
# "project" : "project_name",
# "output": [
# { "frame": 1,
# "predictions": []
# },
# { "frame": 2,
# "predictions": []
# },
# { "frame": 5000,
# "predictions": []
# }
# ]
# }
if __name__ == "__main__":
folder_path = "/work/vita/nmuenger_trinca/annotations/"
folder = "video_frames/"
dirs = os.listdir(folder_path + folder)
model_path = "our_retrained_models/yolov8x_tsd.pt"
model = YOLOCustom(model = model_path)
#dirs = dirs[:2]
output = []
for img in tqdm(dirs):
#img.replace(folder_path, "")
#os.path.normpath(img).split(os.path.sep)
#img = breakpoint()
frame = int(img[-8:-4])
#breakpoint()
pred = model(folder + img)[0]
boxes = []
for box in pred.boxes:
boxes.append({"cls" :str(pred.names[box.cls.item()]),
"x" :box.xywh[0][0].item(),
"y" :box.xywh[0][1].item(),
"w" :box.xywh[0][2].item(),
"h" :box.xywh[0][3].item()})
output.append({"frame":frame, "prediction":boxes})
output_sorted = sorted(output, key=operator.itemgetter('frame'))
#breakpoint()
aDict = {"project": "TSD_group47", "output":output_sorted}
jsonString = json.dumps(aDict)
jsonFile = open("video_prediction_test1_cut.json", "w")
jsonFile.write(jsonString)
jsonFile.close()