55import torch
66import torch .nn as nn
77import torch .nn .functional as F
8- from torch .multiprocessing import Process , Queue
8+ import torch .multiprocessing as mp
99import time
1010from PIL import Image
1111import numpy as np
1212import cv2
1313
14- import lib .transform_cv2 as T
14+ import lib .data . transform_cv2 as T
1515from lib .models import model_factory
1616from configs import set_cfg_from_file
1717
@@ -40,7 +40,7 @@ def get_model():
4040
4141
4242# fetch frames
43- def get_func (inpth , in_q ):
43+ def get_func (inpth , in_q , done ):
4444 cap = cv2 .VideoCapture (args .input )
4545 width = cap .get (cv2 .CAP_PROP_FRAME_WIDTH ) # type is float
4646 height = cap .get (cv2 .CAP_PROP_FRAME_HEIGHT ) # type is float
@@ -59,7 +59,8 @@ def get_func(inpth, in_q):
5959 in_q .put (frame )
6060
6161 in_q .put ('quit' )
62- while not in_q .empty (): continue
62+ done .wait ()
63+
6364 cap .release ()
6465 time .sleep (1 )
6566 print ('input queue done' )
@@ -105,14 +106,15 @@ def infer_batch(frames):
105106
106107
107108if __name__ == '__main__' :
108- torch . multiprocessing .set_start_method ('spawn' )
109+ mp .set_start_method ('spawn' )
109110
110- in_q = Queue (1024 )
111- out_q = Queue (1024 )
111+ in_q = mp .Queue (1024 )
112+ out_q = mp .Queue (1024 )
113+ done = mp .Event ()
112114
113- in_worker = Process (target = get_func ,
114- args = (args .input , in_q ))
115- out_worker = Process (target = save_func ,
115+ in_worker = mp . Process (target = get_func ,
116+ args = (args .input , in_q , done ))
117+ out_worker = mp . Process (target = save_func ,
116118 args = (args .input , args .output , out_q ))
117119
118120 in_worker .start ()
@@ -133,6 +135,7 @@ def infer_batch(frames):
133135 infer_batch (frames )
134136
135137 out_q .put ('quit' )
138+ done .set ()
136139
137140 out_worker .join ()
138141 in_worker .join ()
0 commit comments