1010import time
1111import pickle
1212
13- from utils .configloader import PATH_TO_CLASSIFIER , TIME_WINDOW
13+ from utils .configloader import PATH_TO_CLASSIFIER , TIME_WINDOW , FRAMERATE
1414from experiments .custom .featureextraction import (
1515 SimbaFeatureExtractor ,
1616 SimbaFeatureExtractorStandard14bp ,
@@ -117,6 +117,7 @@ def classify(self, features):
117117 Adapted from BSOID; https://github.com/YttriLab/B-SOID
118118 """
119119 labels_fslow = []
120+ # TODO: adapt to pure version of BSOID Classifier
120121 for i in range (0 , len (features )):
121122 labels = self ._classifier .predict (features [i ].T )
122123 labels_fslow .append (labels )
@@ -183,21 +184,26 @@ def simba_feat_classifier_pool_run(input_q: mp.Queue, output_q: mp.Queue):
183184
184185
185186def bsoid_feat_classifier_pool_run (input_q : mp .Queue , output_q : mp .Queue ):
186- feature_extractor = BsoidFeatureExtractor (TIME_WINDOW )
187+ feature_extractor = BsoidFeatureExtractor ()
187188 classifier = BsoidClassifier () # initialize classifier
188189 while True :
189190 skel_time_window = None
190191 feature_id = 0
191192 if input_q .full ():
192193 skel_time_window , feature_id = input_q .get ()
193194 if skel_time_window is not None :
194- start_time = time .time ()
195+ start_time_feat = time .time ()
195196 features = feature_extractor .extract_features (skel_time_window )
197+ end_time_feat = time .time ()
198+ start_time_clf = time .time ()
196199 last_prob = classifier .classify (features )
197200 output_q .put ((last_prob , feature_id ))
198201 end_time = time .time ()
199- # print("Classification time: {:.2f} msec".format((end_time-start_time)*1000))
200- # print("Feature ID: "+ feature_id)
202+ print ("Feature Extraction time: {:.2f} msec" .format ((end_time_feat - start_time_feat ) * 1000 ))
203+ print ("Classification time: {:.2f} msec" .format ((end_time - start_time_clf )* 1000 ))
204+ print ("Total time: {:.2f} msec" .format ((end_time - start_time_feat )* 1000 ))
205+ print ("Current motif: " , * last_prob )
206+ print ("Feature ID: " + str (feature_id ))
201207 else :
202208 pass
203209
@@ -275,6 +281,8 @@ def pass_time_window(self, skel_time_window: tuple, debug: bool = False):
275281 :param debug bool: reporting of process + feature id to identify discrepancies in processing sequence
276282 """
277283 for process in self ._process_pool :
284+ #if the process is not already busy, feed it some new input and break the loop
285+ #this should only be valid the first time the process is fed.
278286 if not process ["running" ]:
279287 if process ["input" ].empty ():
280288 process ["input" ].put (skel_time_window )
@@ -287,6 +295,8 @@ def pass_time_window(self, skel_time_window: tuple, debug: bool = False):
287295 )
288296 break
289297
298+ #if the process is busy but finished (has output), feed it some new input.
299+ #this should be the normal case
290300 elif process ["input" ].empty () and process ["output" ].full ():
291301 process ["input" ].put (skel_time_window )
292302 if debug :
@@ -306,7 +316,12 @@ def get_result(self, debug: bool = False):
306316 """
307317 result = (None , 0 )
308318 for process in self ._process_pool :
319+ #check if process is finished
309320 if process ["output" ].full ():
321+ #take result and break the loop. This way two simultaneously finished processes are emptied in sequence
322+ #rather then overwriting the results of each other
323+ #the disadvantage is that the result won't be the latest classification but in the next in sequential order (to the last).
324+ #the advantage is that we won't miss any results this way and have "consistent" latency, which is the intended behavior.
310325 result = process ["output" ].get ()
311326 if debug :
312327 print ("Output" , process ["process" ].name , "ID: " + str (result [1 ]))
@@ -381,13 +396,15 @@ def simba_classifier_run(input_q: mp.Queue, output_q: mp.Queue):
381396
382397
383398def bsoid_classifier_run (input_q : mp .Queue , output_q : mp .Queue ):
399+ #takes features from input and feeds them into classifier. Outputs classification
384400 classifier = BsoidClassifier () # initialize classifier
385401 while True :
386402 features = None
387403 if input_q .full ():
388404 features = input_q .get ()
389405 if features is not None :
390406 start_time = time .time ()
407+ #last prob is a missleading name that comes from a binary classifier. B-SOID's output is a cluster id rather then the probability.
391408 last_prob = classifier .classify (features )
392409 output_q .put ((last_prob ))
393410 end_time = time .time ()
0 commit comments