Skip to content

Commit 3919ce4

Browse files
authored
Add files via upload
Improved UI feedback during model downloads and conversions, which is slow the first time code is run.
1 parent f1fe7df commit 3919ce4

5 files changed

+64
-35
lines changed

AI2.py

+25-18
Original file line numberDiff line numberDiff line change
@@ -621,9 +621,6 @@ def main():
621621
yolo8OpenvinoVerification_Thread.__verifyConf__ = yoloVerifyConf
622622

623623
# *** setup and start Coral AI threads
624-
# Might consider moving this into the thread function.
625-
### Setup Coral AI
626-
# initialize the labels dictionary
627624
if nCoral is True:
628625
print("\n[INFO] starting Coral TPU AI Thread ...")
629626
client.publish("AI/Status", "Starting Coral TPU thread.", 2, True)
@@ -643,11 +640,13 @@ def main():
643640
while Coral_TPU_Thread.__Thread__ is False:
644641
sleepCount+=1
645642
time.sleep(1.0)
646-
if sleepCount >= 15:
643+
client.publish("AI/Status", "Coral TPU Thread is starting " + str(sleepCount), 2, True)
644+
if sleepCount >= 30:
647645
client.publish("AI/Status", "[ERROR] Coral_TPU_Thread failed to start, exiting...", 2, True)
648646
print('[ERROR] Coral_TPU_Thread failed to start, exiting...')
649647
QUIT = True
650-
client.publish("AI/Status", "Coral TPU thread is running.", 2, True)
648+
if not QUIT:
649+
client.publish("AI/Status", "Coral TPU thread is running.", 2, True)
651650

652651
# ** setup and start openvino CPU AI thread.
653652
if nCPUthreads is True:
@@ -680,16 +679,18 @@ def main():
680679
client.publish("AI/Status", "Converting MobilenetSSD_v2 working...", 2, True)
681680
else:
682681
client.publish("AI/Status", "Converting MobilenetSSD_v2 still working...", 2, True)
683-
toggle = (toggle+1)%2
682+
toggle = (toggle+1)%2
683+
client.publish("AI/Status", "OpenVINO CPU Thread is starting " + str(sleepCount), 2, True)
684684
if sleepCount >= 30:
685685
client.publish("AI/Status", "[ERROR] OpenVINO_SSD_Thread failed to start, exiting...", 2, True)
686686
print('[ERROR] OpenVINO_SSD_Thread failed to start, exiting...')
687687
QUIT = True
688-
client.publish("AI/Status", "OpenVINO MobilenetSSD_v2 thread is running.", 2, True)
688+
if not QUIT:
689+
client.publish("AI/Status", "OpenVINO MobilenetSSD_v2 thread is running.", 2, True)
689690

690691

691692
if OVyolo8_verify:
692-
# Start dopenvino yolo8 thread
693+
# Start openvino yolo8 thread
693694
print("\n[INFO] OpenVINO yolo_v8 verification thread is starting ... ")
694695
client.publish("AI/Status", "Starting OpenVINO yolo8 verification thread.", 2, True)
695696
yolo8ov=list()
@@ -700,6 +701,7 @@ def main():
700701
while yolo8OpenvinoVerification_Thread.__Thread__ is False:
701702
sleepCount+=1
702703
time.sleep(1.0)
704+
client.publish("AI/Status", "OpenVINO yolo8 verification thread starting " + str(sleepCount), 2, True)
703705
while yolo8OpenvinoVerification_Thread.__CONVERTING__ is True:
704706
if sleepCount == 1:
705707
print('Downloading and converting yolo8 openvino model, be patient!')
@@ -711,13 +713,15 @@ def main():
711713
client.publish("AI/Status", "Converting openvino yolo8 working...", 2, True)
712714
else:
713715
client.publish("AI/Status", "Converting openvino yolo8 still working...", 2, True)
714-
toggle = (toggle+1)%2
716+
toggle = (toggle+1)%2
717+
client.publish("AI/Status", "OpenVINO yolo8 verification starting " + str(sleepCount), 2, True)
715718
if sleepCount >= 30:
716719
print('[ERROR] OpenVINO yolo8 thread failed to start, exiting...')
717720
client.publish("AI/Status", "[ERROR] OpenVINO yolo8 thread failed to start, exiting...", 2, True)
718721
QUIT = True
719-
print("[INFO] OpenVINO yolo_v8 verification thread is running. ")
720-
client.publish("AI/Status", "OpenVINO yolo8 verification thread is running.", 2, True)
722+
if not QUIT:
723+
print("[INFO] OpenVINO yolo_v8 verification thread is running. ")
724+
client.publish("AI/Status", "OpenVINO yolo8 verification thread is running.", 2, True)
721725

722726

723727
if yolo8_verify or TPUyolo8_verify:
@@ -747,7 +751,8 @@ def main():
747751
client.publish("AI/Status", "Converting yolo8 model working...", 2, True)
748752
else:
749753
client.publish("AI/Status", "Converting yolo8 still working...", 2, True)
750-
toggle = (toggle+1)%2
754+
toggle = (toggle+1)%2
755+
client.publish("AI/Status", "Yolo8 verification thread starting " + str(sleepCount), 2, True)
751756
if sleepCount >= 30:
752757
if TPUyolo8_verify:
753758
client.publish("AI/Status", "[ERROR] TPU yolo8 thread failed to start, exiting...", 2, True)
@@ -756,12 +761,14 @@ def main():
756761
client.publish("AI/Status", "[ERROR] CUDA yolo8 thread failed to start, exiting...", 2, True)
757762
print('[ERROR] CUDA yolo8 thread failed to start, exiting...')
758763
QUIT = True
759-
if TPUyolo8_verify:
760-
client.publish("AI/Status", "Ultralytics TPU yolo8 verification thread is running.", 2, True)
761-
else:
762-
# Start Ultralytics yolo8 verification thread
763-
client.publish("AI/Status", "Ultralytics CUDA yolo8 verification thread is running.", 2, True)
764-
print("[INFO] Ultralytics yolo_v8 verification thread is running. ")
764+
if not QUIT:
765+
if TPUyolo8_verify:
766+
client.publish("AI/Status", "Ultralytics TPU yolo8 verification thread is running.", 2, True)
767+
print("[INFO] Ultralytics TPU yolo_v8 verification thread is running. ")
768+
else:
769+
# Start Ultralytics yolo8 verification thread
770+
client.publish("AI/Status", "Ultralytics CUDA yolo8 verification thread is running.", 2, True)
771+
print("[INFO] Ultralytics CUDA yolo_v8 verification thread is running. ")
765772

766773

767774

Coral_TPU_Thread.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424

2525
global model
2626

27+
global QUIT
28+
QUIT = False
29+
2730
try:
2831
from pycoral.adapters.common import input_size
2932
from pycoral.adapters.detect import get_objects
@@ -44,14 +47,19 @@
4447
'''
4548
def threadInit():
4649
global model
47-
50+
global QUIT
51+
4852
try:
4953
print('Edgetpu_api version: ' + edgetpu_version)
5054
# list installed tpus, and figure out if any are M.2 (pci)
5155
pci_tpu = list()
5256
usb_tpu = list()
5357
tpus = list_edge_tpus()
5458
print(tpus)
59+
if len(tpus) ==0:
60+
print('[Error] No Coral TPUs found! Did you forget to plug it in?')
61+
print(' Or did you forget to do the apex driver installation for M.2 TPUs?')
62+
return
5563
for i in range(len(tpus)):
5664
if tpus[i]['type'] == 'pci': pci_tpu.append(i)
5765
if tpus[i]['type'] == 'usb': usb_tpu.append(i)
@@ -71,7 +79,7 @@ def threadInit():
7179
except Exception as e:
7280
print(e)
7381
print("[ERROR] Couldn't instance TPU model! Exiting ...")
74-
quit()
82+
QUIT = True
7583
return
7684

7785

@@ -144,6 +152,7 @@ def AI_thread(results, inframe, cameraLock, nextCamera, Ncameras,
144152
global __DEBUG__
145153
global __Color__
146154
global model
155+
global QUIT
147156

148157
aiStr=dnnStr
149158
waits=0
@@ -164,7 +173,7 @@ def AI_thread(results, inframe, cameraLock, nextCamera, Ncameras,
164173

165174
__Thread__ = True
166175
cfps = FPS().start()
167-
while __Thread__ is True:
176+
while __Thread__ is True and not QUIT:
168177
cameraLock.acquire()
169178
cq=nextCamera
170179
nextCamera = (nextCamera+1)%Ncameras

OpenVINO_SSD_Thread.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
__Color__ = (0, 200, 200)
3232

3333
global __CONVERTING__
34-
__CONVERTING__ = True
34+
__CONVERTING__ = False
35+
36+
global QUIT
37+
QUIT = False
3538

3639
## *** OpenVINO 2024 CPU SSD AI Thread ***
3740
#******************************************************************************************************************
@@ -42,6 +45,8 @@ def AI_thread(resultsQ, inframe, cameraLock, nextCamera, Ncameras,
4245
global __VERIY_DIMS__
4346
global __Color__
4447
global __CONVERTING__
48+
global QUIT
49+
4550
fcnt=0
4651
waits=0
4752
dcnt=0
@@ -58,15 +63,14 @@ def AI_thread(resultsQ, inframe, cameraLock, nextCamera, Ncameras,
5863
MO_2021 = True
5964
model_path = 'mobilenet_ssd_v2/MobilenetSSDv2cocoIR10.xml' # my IR10 conversion done with openvino 2021.3
6065
aiStr = dnnTarget
61-
__CONVERTING__ = False
6266
else:
6367
aiStr = 'ovCPU'
6468
MO_2021 = False
6569
if os.path.exists('mobilenet_ssd_v2/ssd_mobilenet_v2_coco_2018_03_29.xml'): # ov converted and saved model from 2018
6670
model_path = 'mobilenet_ssd_v2/ssd_mobilenet_v2_coco_2018_03_29.xml'
67-
__CONVERTING__ = False
6871
else:
6972
if os.path.exists('../ssd_mobilenet_v2_coco_2018_03_29'):
73+
__CONVERTING__ = True
7074
print('[INFO] Converting downloaded ssd_mobilenet_v2_coco_2018_03_29 model, be patient ...')
7175
model = ov.convert_model('../ssd_mobilenet_v2_coco_2018_03_29/frozen_inference_graph.pb')
7276
print('[INFO] Saving converted mode, so this step can be skipped on the next program run.')
@@ -81,8 +85,7 @@ def AI_thread(resultsQ, inframe, cameraLock, nextCamera, Ncameras,
8185
print('tar -zxf ssd_mobilenet_v2_coco_2018_03_29.tar.gz')
8286
print(' Exiting...')
8387
__CONVERTING__ = False
84-
quit()
85-
88+
QUIT = True
8689

8790
device_name = 'CPU'
8891
__VERIFY_DIMS__ = PREPROCESS_DIMS
@@ -112,7 +115,8 @@ def AI_thread(resultsQ, inframe, cameraLock, nextCamera, Ncameras,
112115

113116
if len(model.inputs) != 1:
114117
log.error('Supports only single input topologies.')
115-
return -1
118+
QUIT = True
119+
return -1 # I don't think this error handling is very clean, but shouldn't happen
116120
'''
117121
if len(model.outputs) != 1:
118122
log.error('Supports only single output topologies')
@@ -167,7 +171,7 @@ def AI_thread(resultsQ, inframe, cameraLock, nextCamera, Ncameras,
167171
__Thread__ = True
168172
print("[INFO] OpenVINO CPU MobilenetSSD AI thread using " + aiStr + " is running...")
169173
cfps = FPS().start()
170-
while __Thread__:
174+
while __Thread__ and not QUIT:
171175
cameraLock.acquire()
172176
cq=nextCamera
173177
nextCamera = (nextCamera+1)%Ncameras

yolo8OpenvinoVerification_Thread.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,25 @@
3434
__verifyConf__ = 0.75
3535

3636
global __y8modelSTR__
37-
__y8modelSTR__ = 'yolov8l'
37+
__y8modelSTR__ = 'yolov8m'
3838

3939
global model
4040

4141
global __CONVERTING__
42-
__CONVERTING__ = True
42+
__CONVERTING__ = False
4343

44+
global QUIT
45+
QUIT = False
4446

4547
def yolo8ov_thread(resultsQ, yoloQ):
4648
global __Thread__
4749
global __verifyConf__
4850
global model
4951
global __y8modelSTR__
5052
global __CONVERTING__
53+
global QUIT
5154

52-
print("Starting Yolo v8 verification thread...\n")
55+
print("Starting yolo8ov_thread...")
5356
if yoloQ is None:
5457
print( "ERROR! no yolo Queue!")
5558
return -1
@@ -65,11 +68,13 @@ def yolo8ov_thread(resultsQ, yoloQ):
6568
res = det_model('TestDetection.jpg', conf=__verifyConf__-0.001, verbose=False) #Dummy inference to initialize object, better way? But this works!
6669
# object detection model export to OpenVINO format
6770
det_model_path = models_dir / f"{__y8modelSTR__}_openvino_model/{__y8modelSTR__}.xml"
71+
###print(det_model_path)
6872
if not det_model_path.exists():
73+
__CONVERTING__ = True
6974
print('\n[INFO] Exporting yolo model to OpenVINO format...')
7075
det_model.export(format="openvino", dynamic=True, half=True)
7176
__CONVERTING__ = False
72-
print('\n[INFO] Using OpenVINO: ' + ov.__version__)
77+
print('[INFO] Using OpenVINO: ' + ov.__version__)
7378
core = ov.Core()
7479
ov_config = {}
7580
det_ov_model = core.read_model(det_model_path)

yolo8_verification_Thread.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@
3939
__useTPU__ = False
4040

4141
global __CONVERTING__
42-
__CONVERTING__ = True
42+
__CONVERTING__ = False
4343

44+
global QUIT
45+
QUIT = False
4446
'''
4547
one time code to run when thread is launched.
4648
'''
@@ -49,6 +51,7 @@ def threadInit():
4951
global __y8modelSTR__
5052
global __useTPU__
5153
global __CONVERTING__
54+
global QUIT
5255

5356
models_dir = Path("./yolo8")
5457
models_dir.mkdir(exist_ok=True)
@@ -70,6 +73,7 @@ def threadInit():
7073
# test if model has been converted, if not convert it
7174
det_model_path = models_dir / f"yolov8s_saved_model/yolov8s_full_integer_quant_edgetpu.tflite"
7275
if not det_model_path.exists():
76+
__CONVERTING__ = True
7377
# load and convert ultralytics yolo8 model
7478
print('[INFO] Converting yolov8s model to edgetpu format.')
7579
model = YOLO('yolo8/yolov8s')
@@ -129,7 +133,7 @@ def yolov8_thread(results, yoloQ):
129133
global __verifyConf__
130134
global __Color__
131135
global __useTPU__
132-
136+
global QUIT
133137
print("Starting Yolo v8 verification thread...")
134138
if yoloQ is None:
135139
print( "ERROR! no yolo Queue!")
@@ -147,7 +151,7 @@ def yolov8_thread(results, yoloQ):
147151
print("Yolo v8 CUDA verification thread is running...")
148152
__Thread__ = True
149153

150-
while __Thread__ is True:
154+
while __Thread__ is True and not QUIT:
151155
try:
152156
# ssd_frame is full camera resolution with SSD detection box overlaid
153157
# yolo_frame is "zoomed in" on the SSD detection box and resized to 608x608 for darknet yolo4 inference

0 commit comments

Comments
 (0)