5353import re
5454import sys
5555
56+ from datetime import datetime
5657import plotly .graph_objects as go
5758
59+ import getpass
60+ import socket
61+ user = getpass .getuser ()
62+ host = socket .gethostname ()
63+ user_host_descriptor = user + "@" + host
64+ print ("[INFO] user@hosthame : " ,user_host_descriptor )
65+
5866sys .path .append (os .path .abspath ('blaze_common/' ))
5967sys .path .append (os .path .abspath ('blaze_tflite/' ))
6068sys .path .append (os .path .abspath ('blaze_pytorch/' ))
@@ -157,8 +165,9 @@ def get_video_dev_by_name(src):
157165ap .add_argument ('-l' , '--list' , default = False , action = 'store_true' , help = "List pipelines." )
158166ap .add_argument ('-d' , '--debug' , default = False , action = 'store_true' , help = "Enable Debug mode. Default is off" )
159167ap .add_argument ('-w' , '--withoutview' , default = False , action = 'store_true' , help = "Disable Output viewing. Default is on" )
160- ap .add_argument ('-z' , '--profile' , default = False , action = 'store_true' , help = "Enable Profile mode (Latency). Default is off" )
161- ap .add_argument ('-f' , '--fps' , default = False , action = 'store_true' , help = "Enable Profile mode (FPS). Default is off" )
168+ ap .add_argument ('-z' , '--profilelog' , default = False , action = 'store_true' , help = "Enable Profile Log (Latency). Default is off" )
169+ ap .add_argument ('-Z' , '--profileview' , default = False , action = 'store_true' , help = "Enable Profile View (Latency). Default is off" )
170+ ap .add_argument ('-f' , '--fps' , default = False , action = 'store_true' , help = "Enable FPS display. Default is off" )
162171
163172args = ap .parse_args ()
164173
@@ -171,7 +180,8 @@ def get_video_dev_by_name(src):
171180print (' --list : ' , args .list )
172181print (' --debug : ' , args .debug )
173182print (' --withoutview : ' , args .withoutview )
174- print (' --profile : ' , args .profile )
183+ print (' --profilelog : ' , args .profilelog )
184+ print (' --profileview : ' , args .profileview )
175185print (' --fps : ' , args .fps )
176186
177187
@@ -275,6 +285,15 @@ def get_video_dev_by_name(src):
275285
276286output_dir = './captured-images'
277287
288+ profile_csv = './blaze_detect_live.csv'
289+ if os .path .isfile (profile_csv ):
290+ f_profile_csv = open (profile_csv , "a" )
291+ print ("[INFO] Appending to existing profiling results file :" ,profile_csv )
292+ else :
293+ f_profile_csv = open (profile_csv , "w" )
294+ print ("[INFO] Creating new profiling results file :" ,profile_csv )
295+ f_profile_csv .write ("time,user,hostname,pipeline,resize,detector_pre,detector_model,detector_post,extract_roi,landmark_pre,landmark_model,landmark_post,annotate,total,fps\n " )
296+
278297if not os .path .exists (output_dir ):
279298 os .mkdir (output_dir ) # Create the output directory if it doesn't already exist
280299
@@ -368,7 +387,8 @@ def get_video_dev_by_name(src):
368387print ("\t Press 'e' to toggle scores image on/off" )
369388print ("\t Press 'f' to toggle FPS display on/off" )
370389print ("\t Press 'v' to toggle verbose on/off" )
371- print ("\t Press 'z' to toggle profiling on/off" )
390+ print ("\t Press 'z' to toggle profiling log on/off" )
391+ print ("\t Press 'Z' to toggle profiling view on/off" )
372392print ("================================================================" )
373393
374394bStep = False
@@ -380,7 +400,8 @@ def get_video_dev_by_name(src):
380400bShowFPS = args .fps
381401bVerbose = args .debug
382402bViewOutput = not args .withoutview
383- bProfile = args .profile
403+ bProfileLog = args .profilelog
404+ bProfileView = args .profileview
384405
385406def ignore (x ):
386407 pass
@@ -440,7 +461,7 @@ def ignore(x):
440461 print ("[ERROR] cap.read() FAILEd !" )
441462 break
442463
443- if bProfile :
464+ if bProfileLog or bProfileView :
444465 prof_title = ['' ]* nb_blaze_pipelines
445466 prof_resize = np .zeros (nb_blaze_pipelines )
446467 prof_detector_pre = np .zeros (nb_blaze_pipelines )
@@ -563,7 +584,7 @@ def ignore(x):
563584 cv2 .imshow (app_main_title , output )
564585
565586 # Profiling
566- if bProfile :
587+ if bProfileLog or bProfileView :
567588 prof_title [pipeline_id ] = blaze_title
568589 prof_resize [pipeline_id ] = profile_resize
569590 prof_detector_pre [pipeline_id ] = blaze_detector .profile_pre
@@ -615,8 +636,31 @@ def ignore(x):
615636 profile_annotate
616637 ))
617638
618-
619- if bProfile :
639+ if bProfileLog :
640+ timestamp = datetime .now ()
641+ for pipeline_id in range (nb_blaze_pipelines ):
642+ if blaze_pipelines [pipeline_id ]["supported" ] and blaze_pipelines [pipeline_id ]["selected" ]:
643+ csv_str = \
644+ str (timestamp )+ "," + \
645+ str (user )+ "," + \
646+ str (host )+ "," + \
647+ blaze_pipelines [pipeline_id ]["pipeline" ]+ "," + \
648+ str (prof_resize [pipeline_id ])+ "," + \
649+ str (prof_detector_pre [pipeline_id ])+ "," + \
650+ str (prof_detector_model [pipeline_id ])+ "," + \
651+ str (prof_detector_post [pipeline_id ])+ "," + \
652+ str (prof_extract_roi [pipeline_id ])+ "," + \
653+ str (prof_landmark_pre [pipeline_id ])+ "," + \
654+ str (prof_landmark_model [pipeline_id ])+ "," + \
655+ str (prof_landmark_post [pipeline_id ])+ "," + \
656+ str (prof_annotate [pipeline_id ])+ "," + \
657+ str (prof_total [pipeline_id ])+ "," + \
658+ str (prof_fps [pipeline_id ])+ "\n "
659+ #print("[LOG] ",csv_str)
660+ f_profile_csv .write (csv_str )
661+
662+
663+ if bProfileView :
620664 #
621665 # Latency
622666 #
@@ -762,10 +806,13 @@ def ignore(x):
762806 blaze_landmark .set_debug (debug = bVerbose )
763807
764808 if key == 122 : # 'z'
765- bProfile = not bProfile
766- blaze_detector .set_profile (profile = bProfile )
767- blaze_landmark .set_profile (profile = bProfile )
768- if not bProfile :
809+ bProfileLog = not bProfileLog
810+
811+ if key == 90 : # 'Z'
812+ bProfileView = not bProfileView
813+ blaze_detector .set_profile (profile = bProfileView )
814+ blaze_landmark .set_profile (profile = bProfileView )
815+ if not bProfileView :
769816 cv2 .destroyWindow (profile_latency_title )
770817 cv2 .destroyWindow (profile_fps_title )
771818
@@ -783,4 +830,5 @@ def ignore(x):
783830 rt_fps_count = 0
784831
785832# Cleanup
833+ f_profile_csv .close ()
786834cv2 .destroyAllWindows ()
0 commit comments