@@ -330,7 +330,10 @@ def Predict_bbox_mp(Frames_data, Predicted_data, Processing_times):
330330 Processing_times .put (time .time ())
331331
332332 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 )
334337 elif YOLO_FRAMEWORK == "trt" :
335338 batched_input = tf .constant (image_data )
336339 result = Yolo (batched_input )
@@ -459,7 +462,10 @@ def detect_video(Yolo, video_path, output_path, input_size=416, show=False, CLAS
459462
460463 t1 = time .time ()
461464 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 )
463469 elif YOLO_FRAMEWORK == "trt" :
464470 batched_input = tf .constant (image_data )
465471 result = Yolo (batched_input )
@@ -505,17 +511,18 @@ def detect_video(Yolo, video_path, output_path, input_size=416, show=False, CLAS
505511# detect from webcam
506512def detect_realtime (Yolo , output_path , input_size = 416 , show = False , CLASSES = YOLO_COCO_CLASSES , score_threshold = 0.3 , iou_threshold = 0.45 , rectangle_colors = '' ):
507513 times = []
508- vid = cv2 .VideoCapture (0 )
514+ vid = cv2 .VideoCapture (1 )
509515
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
516523
517524 while True :
518- _ , frame = vid .read ()
525+ ret , frame = vid .read ()
519526
520527 try :
521528 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_
527534
528535 t1 = time .time ()
529536 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)
531543 elif YOLO_FRAMEWORK == "trt" :
532544 batched_input = tf .constant (image_data )
533545 result = Yolo (batched_input )
0 commit comments