Skip to content

Commit 2fdc403

Browse files
committed
blaze_detect_live.py: implement two versions of profiling (log & view).
1 parent 43e2a49 commit 2fdc403

File tree

5 files changed

+305
-65
lines changed

5 files changed

+305
-65
lines changed

blaze_detect_live.py

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,16 @@
5353
import re
5454
import sys
5555

56+
from datetime import datetime
5657
import 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+
5866
sys.path.append(os.path.abspath('blaze_common/'))
5967
sys.path.append(os.path.abspath('blaze_tflite/'))
6068
sys.path.append(os.path.abspath('blaze_pytorch/'))
@@ -157,8 +165,9 @@ def get_video_dev_by_name(src):
157165
ap.add_argument('-l', '--list' , default=False, action='store_true', help="List pipelines.")
158166
ap.add_argument('-d', '--debug' , default=False, action='store_true', help="Enable Debug mode. Default is off")
159167
ap.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

163172
args = ap.parse_args()
164173

@@ -171,7 +180,8 @@ def get_video_dev_by_name(src):
171180
print(' --list : ', args.list)
172181
print(' --debug : ', args.debug)
173182
print(' --withoutview : ', args.withoutview)
174-
print(' --profile : ', args.profile)
183+
print(' --profilelog : ', args.profilelog)
184+
print(' --profileview : ', args.profileview)
175185
print(' --fps : ', args.fps)
176186

177187

@@ -275,6 +285,15 @@ def get_video_dev_by_name(src):
275285

276286
output_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+
278297
if 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):
368387
print("\tPress 'e' to toggle scores image on/off")
369388
print("\tPress 'f' to toggle FPS display on/off")
370389
print("\tPress 'v' to toggle verbose on/off")
371-
print("\tPress 'z' to toggle profiling on/off")
390+
print("\tPress 'z' to toggle profiling log on/off")
391+
print("\tPress 'Z' to toggle profiling view on/off")
372392
print("================================================================")
373393

374394
bStep = False
@@ -380,7 +400,8 @@ def get_video_dev_by_name(src):
380400
bShowFPS = args.fps
381401
bVerbose = args.debug
382402
bViewOutput = not args.withoutview
383-
bProfile = args.profile
403+
bProfileLog = args.profilelog
404+
bProfileView = args.profileview
384405

385406
def 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()
786834
cv2.destroyAllWindows()

blaze_hailo/blaze_detect_live.py

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,16 @@
4444
import re
4545
import sys
4646

47+
from datetime import datetime
4748
import plotly.graph_objects as go
4849

50+
import getpass
51+
import socket
52+
user = getpass.getuser()
53+
host = socket.gethostname()
54+
user_host_descriptor = user+"@"+host
55+
print("[INFO] user@hosthame : ",user_host_descriptor)
56+
4957
sys.path.append(os.path.abspath('../blaze_common/'))
5058
from hailo_inference import HailoInference
5159
hailo_infer = HailoInference()
@@ -91,8 +99,9 @@ def get_video_dev_by_name(src):
9199
ap.add_argument('-n', '--model2', type=str, help='Path of blazehandlardmark model. Default is models/hand_landmark_lite.hef')
92100
ap.add_argument('-d', '--debug' , default=False, action='store_true', help="Enable Debug mode. Default is off")
93101
ap.add_argument('-w', '--withoutview', default=False, action='store_true', help="Disable Output viewing. Default is on")
94-
ap.add_argument('-z', '--profile' , default=False, action='store_true', help="Enable Profile mode. Default is off")
95-
ap.add_argument('-f', '--fps' , default=False, action='store_true', help="Enable Profile mode (FPS). Default is off")
102+
ap.add_argument('-z', '--profilelog' , default=False, action='store_true', help="Enable Profile Log (Latency). Default is off")
103+
ap.add_argument('-Z', '--profileview', default=False, action='store_true', help="Enable Profile View (Latency). Default is off")
104+
ap.add_argument('-f', '--fps' , default=False, action='store_true', help="Enable FPS display. Default is off")
96105

97106
args = ap.parse_args()
98107

@@ -104,7 +113,8 @@ def get_video_dev_by_name(src):
104113
print(' --model2 : ', args.model2)
105114
print(' --debug : ', args.debug)
106115
print(' --withoutview : ', args.withoutview)
107-
print(' --profile : ', args.profile)
116+
print(' --profilelog : ', args.profilelog)
117+
print(' --profileview : ', args.profileview)
108118
print(' --fps : ', args.fps)
109119

110120
nb_blaze_pipelines = 1
@@ -125,6 +135,15 @@ def get_video_dev_by_name(src):
125135

126136
output_dir = './captured-images'
127137

138+
profile_csv = './blaze_detect_live.csv'
139+
if os.path.isfile(profile_csv):
140+
f_profile_csv = open(profile_csv, "a")
141+
print("[INFO] Appending to existing profiling results file :",profile_csv)
142+
else:
143+
f_profile_csv = open(profile_csv, "w")
144+
print("[INFO] Creating new profiling results file :",profile_csv)
145+
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")
146+
128147
if not os.path.exists(output_dir):
129148
os.mkdir(output_dir) # Create the output directory if it doesn't already exist
130149

@@ -192,7 +211,8 @@ def get_video_dev_by_name(src):
192211
print("\tPress 'e' to toggle scores image on/off")
193212
print("\tPress 'f' to toggle FPS display on/off")
194213
print("\tPress 'v' to toggle verbose on/off")
195-
print("\tPress 'z' to toggle profiling on/off")
214+
print("\tPress 'z' to toggle profiling log on/off")
215+
print("\tPress 'Z' to toggle profiling view on/off")
196216
print("================================================================")
197217

198218
bStep = False
@@ -204,7 +224,8 @@ def get_video_dev_by_name(src):
204224
bShowFPS = args.fps
205225
bVerbose = args.debug
206226
bViewOutput = not args.withoutview
207-
bProfile = args.profile
227+
bProfileLog = args.profilelog
228+
bProfileView = args.profileview
208229

209230
def ignore(x):
210231
pass
@@ -251,7 +272,7 @@ def ignore(x):
251272
print("[ERROR] cap.read() FAILEd !")
252273
break
253274

254-
if bProfile:
275+
if bProfileLog or bProfileView:
255276
prof_title = ['']*nb_blaze_pipelines
256277
prof_resize = np.zeros(nb_blaze_pipelines)
257278
prof_detector_pre = np.zeros(nb_blaze_pipelines)
@@ -363,7 +384,7 @@ def ignore(x):
363384
cv2.imshow(app_main_title, output)
364385

365386
# Profiling
366-
if bProfile:
387+
if bProfileLog or bProfileView:
367388
prof_title[pipeline_id] = blaze_title
368389
prof_resize[pipeline_id] = profile_resize
369390
prof_detector_pre[pipeline_id] = blaze_detector.profile_pre
@@ -415,8 +436,31 @@ def ignore(x):
415436
profile_annotate
416437
))
417438

418-
419-
if bProfile:
439+
if bProfileLog:
440+
timestamp = datetime.now()
441+
pipeline_id = 0
442+
if True:
443+
csv_str = \
444+
str(timestamp)+","+\
445+
str(user)+","+\
446+
str(host)+","+\
447+
"blaze_hailo"+","+\
448+
str(prof_resize[pipeline_id])+","+\
449+
str(prof_detector_pre[pipeline_id])+","+\
450+
str(prof_detector_model[pipeline_id])+","+\
451+
str(prof_detector_post[pipeline_id])+","+\
452+
str(prof_extract_roi[pipeline_id])+","+\
453+
str(prof_landmark_pre[pipeline_id])+","+\
454+
str(prof_landmark_model[pipeline_id])+","+\
455+
str(prof_landmark_post[pipeline_id])+","+\
456+
str(prof_annotate[pipeline_id])+","+\
457+
str(prof_total[pipeline_id])+","+\
458+
str(prof_fps[pipeline_id])+"\n"
459+
#print("[LOG] ",csv_str)
460+
f_profile_csv.write(csv_str)
461+
462+
463+
if bProfileView:
420464
#
421465
# Latency
422466
#
@@ -553,10 +597,13 @@ def ignore(x):
553597
blaze_landmark.set_debug(debug=bVerbose)
554598

555599
if key == 122: # 'z'
556-
bProfile = not bProfile
557-
blaze_detector.set_profile(profile=bProfile)
558-
blaze_landmark.set_profile(profile=bProfile)
559-
if not bProfile:
600+
bProfileLog = not bProfileLog
601+
602+
if key == 90: # 'Z'
603+
bProfileView = not bProfileView
604+
blaze_detector.set_profile(profile=bProfileView)
605+
blaze_landmark.set_profile(profile=bProfileView)
606+
if not bProfileView:
560607
cv2.destroyWindow(profile_latency_title)
561608
cv2.destroyWindow(profile_fps_title)
562609

@@ -574,4 +621,5 @@ def ignore(x):
574621
rt_fps_count = 0
575622

576623
# Cleanup
624+
f_profile_csv.close()
577625
cv2.destroyAllWindows()

0 commit comments

Comments
 (0)