@@ -330,7 +330,10 @@ def Predict_bbox_mp(Frames_data, Predicted_data, Processing_times):
330
330
Processing_times .put (time .time ())
331
331
332
332
if YOLO_FRAMEWORK == "tf" :
333
- pred_bbox = Yolo .predict (image_data )
333
+ if tf .__version__ > '2.4.0' :
334
+ pred_bbox = Yolo (image_data )
335
+ else :
336
+ pred_bbox = Yolo .predict (image_data )
334
337
elif YOLO_FRAMEWORK == "trt" :
335
338
batched_input = tf .constant (image_data )
336
339
result = Yolo (batched_input )
@@ -459,7 +462,10 @@ def detect_video(Yolo, video_path, output_path, input_size=416, show=False, CLAS
459
462
460
463
t1 = time .time ()
461
464
if YOLO_FRAMEWORK == "tf" :
462
- pred_bbox = Yolo .predict (image_data )
465
+ if tf .__version__ > '2.4.0' :
466
+ pred_bbox = Yolo (image_data , training = False )
467
+ else :
468
+ pred_bbox = Yolo .predict (image_data )
463
469
elif YOLO_FRAMEWORK == "trt" :
464
470
batched_input = tf .constant (image_data )
465
471
result = Yolo (batched_input )
@@ -505,17 +511,18 @@ def detect_video(Yolo, video_path, output_path, input_size=416, show=False, CLAS
505
511
# detect from webcam
506
512
def detect_realtime (Yolo , output_path , input_size = 416 , show = False , CLASSES = YOLO_COCO_CLASSES , score_threshold = 0.3 , iou_threshold = 0.45 , rectangle_colors = '' ):
507
513
times = []
508
- vid = cv2 .VideoCapture (0 )
514
+ vid = cv2 .VideoCapture (1 )
509
515
510
- # by default VideoCapture returns float instead of int
511
- width = int (vid .get (cv2 .CAP_PROP_FRAME_WIDTH ))
512
- height = int (vid .get (cv2 .CAP_PROP_FRAME_HEIGHT ))
513
- fps = int (vid .get (cv2 .CAP_PROP_FPS ))
514
- codec = cv2 .VideoWriter_fourcc (* 'XVID' )
515
- out = cv2 .VideoWriter (output_path , codec , fps , (width , height )) # output_path must be .mp4
516
+ if output_path :
517
+ # by default VideoCapture returns float instead of int
518
+ width = int (vid .get (cv2 .CAP_PROP_FRAME_WIDTH ))
519
+ height = int (vid .get (cv2 .CAP_PROP_FRAME_HEIGHT ))
520
+ fps = int (vid .get (cv2 .CAP_PROP_FPS ))
521
+ codec = cv2 .VideoWriter_fourcc (* 'XVID' )
522
+ out = cv2 .VideoWriter (output_path , codec , fps , (width , height )) # output_path must be .mp4
516
523
517
524
while True :
518
- _ , frame = vid .read ()
525
+ ret , frame = vid .read ()
519
526
520
527
try :
521
528
original_frame = cv2 .cvtColor (frame , cv2 .COLOR_BGR2RGB )
@@ -527,7 +534,12 @@ def detect_realtime(Yolo, output_path, input_size=416, show=False, CLASSES=YOLO_
527
534
528
535
t1 = time .time ()
529
536
if YOLO_FRAMEWORK == "tf" :
530
- pred_bbox = Yolo .predict (image_data )
537
+ if tf .__version__ > '2.4.0' :
538
+ pred_bbox = Yolo (image_data , training = False )
539
+ else :
540
+ pred_bbox = Yolo .predict (image_data )
541
+ # if True:
542
+ # pred_bbox = Yolo.predict(image_data)
531
543
elif YOLO_FRAMEWORK == "trt" :
532
544
batched_input = tf .constant (image_data )
533
545
result = Yolo (batched_input )
0 commit comments