代码拉取完成,页面将自动刷新
import tensorflow as tf
import cv2
from configuration import test_video_dir, temp_frame_dir, CATEGORY_NUM, save_model_dir
from test_on_single_image import single_image_inference
from yolo.yolo_v3 import YOLOV3
def frame_detection(frame, model):
cv2.imwrite(filename=temp_frame_dir, img=frame)
frame = single_image_inference(image_dir=temp_frame_dir, model=model)
return frame
if __name__ == '__main__':
# GPU settings
gpus = tf.config.experimental.list_physical_devices('GPU')
if gpus :
for gpu in gpus:
tf.config.experimental.set_memory_growth(gpu, True)
# load model
yolo_v3 = YOLOV3(out_channels=3 * (CATEGORY_NUM + 5))
yolo_v3.load_weights(filepath=save_model_dir+"epoch-75")
capture = cv2.VideoCapture(test_video_dir)
fps = capture.get(cv2.CAP_PROP_FPS)
while True:
ret, frame = capture.read()
if ret:
new_frame = frame_detection(frame, yolo_v3)
cv2.namedWindow("detect result", flags=cv2.WINDOW_NORMAL)
cv2.imshow("detect result", new_frame)
cv2.waitKey(1)
else:
break
capture.release()
cv2.destroyAllWindows()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。