1
1
from __future__ import annotations
2
2
3
- import numpy as np
4
3
import json
4
+ import time
5
+
6
+ import numpy as np
5
7
from cvias .image .detection .vllm_detection import VLLMDetection
6
8
7
9
from ns_vfs .automaton .video_automaton import VideoAutomaton
8
10
from ns_vfs .data .frame import FramesofInterest , VideoFrame
11
+ from ns_vfs .dataloader .longvideobench import LongVideoBench
9
12
from ns_vfs .model_checking .stormpy import StormModelChecker
10
13
from ns_vfs .percepter .single_vision_percepter import SingleVisionPercepter
11
14
from ns_vfs .validator import FrameValidator
12
- from ns_vfs .dataloader .longvideobench import LongVideoBench
13
- from ns_vfs .dataloader .nextqa import NextQA
14
15
15
16
16
17
def run_nsvs_nsvqa (
@@ -28,6 +29,7 @@ def run_nsvs_nsvqa(
28
29
desired_fps : int | None = None ,
29
30
custom_prompt : str | None = None ,
30
31
) -> None :
32
+ print (f"THE LTL FORMULA IS: { ltl_formula } " )
31
33
# Yolo model initialization
32
34
vllm_model = VLLMDetection (
33
35
api_key = api_key ,
@@ -52,11 +54,15 @@ def run_nsvs_nsvqa(
52
54
cv_models = vllm_model ,
53
55
)
54
56
55
- frame_validator = FrameValidator (ltl_formula = ltl_formula )
57
+ frame_validator = FrameValidator (
58
+ ltl_formula = ltl_formula ,
59
+ threshold_of_probability = 0.3 ,
60
+ )
56
61
frame_idx = 0
57
- model_checker_is_filter : bool = ( False ,)
58
- model_checker_type : str = ( " sparse_ma",)
62
+ model_checker_is_filter : bool = False
63
+ model_checker_type : str = "dtmc" # " sparse_ma"
59
64
for nsvqa_input in nsvqa_input_data :
65
+ start_time = time .time ()
60
66
sequence_of_frames = nsvqa_input ["frames" ]
61
67
detected_objects : dict = vision_percepter .perceive (
62
68
image = sequence_of_frames ,
@@ -73,6 +79,8 @@ def run_nsvs_nsvqa(
73
79
activity_of_interest = activity_of_interest ,
74
80
)
75
81
frame_idx += 1
82
+ end_time = time .time ()
83
+ print (f"Time taken to detect objects: { end_time - start_time } seconds" )
76
84
77
85
# 1. frame validation
78
86
if frame_validator .validate_frame (frame = frame ):
@@ -96,6 +104,15 @@ def run_nsvs_nsvqa(
96
104
print (frame_of_interest .foi_list )
97
105
# save result
98
106
if output_path :
107
+ if output_path .endswith ("/" ):
108
+ foi_output_path = f"{ output_path } frames_of_interest.txt"
109
+ else :
110
+ foi_output_path = f"{ output_path } /frames_of_interest.txt"
111
+ with open (foi_output_path , "w" ) as f :
112
+ f .write ("Detected frames of interest:\n " )
113
+ f .write ("--------------------------------\n " )
114
+ for frame in frame_of_interest .foi_list :
115
+ f .write (f"{ frame } \n " )
99
116
frame_of_interest .save (path = output_path )
100
117
print (f"\n Results saved in { output_path } " )
101
118
@@ -104,24 +121,28 @@ def run_nsvs_nsvqa(
104
121
105
122
if __name__ == "__main__" :
106
123
# input_data_path = "/nas/mars/experiment_result/nsvqa/1_puls/longvideobench/longvideobench-outputs-fixed-specs-v2.json"
107
- input_data_path = "/nas/mars/experiment_result/nsvqa/1_puls/next-dataset/nextqa-outputs.json"
108
- with open (input_data_path , 'r' , encoding = 'utf-8' ) as f :
124
+ # input_data_path = "/nas/mars/experiment_result/nsvqa/1_puls/next-dataset/nextqa-outputs.json"
125
+ # input_data_path = "/nas/mars/experiment_result/nsvqa/1_puls/longvideobench/longvideobench-run1.json"
126
+ input_data_path = "/nas/mars/experiment_result/nsvqa/1_puls/longvideobench/longvideobench-run2.json"
127
+
128
+ with open (input_data_path , "r" , encoding = "utf-8" ) as f :
109
129
data = json .load (f )
110
130
111
131
for sample in data :
112
132
# loader = LongVideoBench(sample["video_path"], sample["subtitle_path"])
113
- loader = NextQA (sample ["video_path" ], sample ["subtitle_path" ])
133
+ loader = LongVideoBench (sample ["video_path" ], sample ["subtitle_path" ])
114
134
nsvqa_input = loader .load_all ()
115
- extracted = sample ["video_path" ].split ('/' )[- 1 ].split ('.' )[0 ]
135
+ extracted = sample ["video_path" ].split ("/" )[- 1 ].split ("." )[0 ]
116
136
117
137
run_nsvs_nsvqa (
118
138
nsvqa_input_data = nsvqa_input ,
119
139
desired_interval_in_sec = None ,
140
+ api_base = "http://localhost:8002/v1" ,
120
141
desired_fps = 30 ,
121
142
proposition_set = sample ["proposition" ],
122
143
ltl_formula = sample ["specification" ],
123
144
output_path = f"/nas/mars/experiment_result/nsvqa/2_nsvs/longvideobench/{ extracted } /" ,
124
145
threshold_satisfaction_probability = 0.80 ,
125
146
frame_scale = None ,
126
- calibration_method = "temperature_scaling" ,
147
+ calibration_method = None , # "temperature_scaling",
127
148
)
0 commit comments