Skip to content

Commit af3749d

Browse files
committed
some minor changes to work with new tf version
1 parent 91d6bd9 commit af3749d

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.pyc
2+
model_data
3+
configs.py

requirements.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ numpy>=1.18.2
22
scipy>=1.4.1
33
wget>=3.2
44
seaborn>=0.10.0
5-
tensorflow==2.3.1
6-
tensorflow-gpu==2.3.1
7-
opencv-python==4.1.2.30
5+
tensorflow
6+
opencv-python==4.4.0.46
87
tqdm==4.43.0
98
pandas
109
awscli

yolov3/utils.py

+23-11
Original file line numberDiff line numberDiff line change
@@ -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
506512
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=''):
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

Comments
 (0)