Community
cancel
Showing results for 
Search instead for 
Did you mean: 
idata
Community Manager
372 Views

Use two processes to run two different graph on one stick

Hi @Tome_at_Intel !

 

I plan to run two different graph on a stick for face detection and face recognition respectively.

 

Each graph runs in its own different sub processes. However, it is always blocked at write_elem ().

 

Debug information as follows:

 

 

D : [ 0] ncFifoWriteElem:2630 No layout conversion is needed 0 D : [ 0] convertDataTypeAndLayout:170 src data type 1 dst data type 0 D : [ 0] convertDataTypeAndLayout:172 SRC: w 300 h 300 c 3 w_s 12 h_s 3600 c_s 4 D : [ 0] convertDataTypeAndLayout:174 DST: w 300 h 300 c 3 w_s 6 h_s 1800 c_s 2

 

When I use the mp.set_start_method ('forkserver') or mp.set_start_method ('spawn'), will throw the following exception:

 

Traceback (most recent call last): File "/home/sdu/PycharmProjects/test/multi_process.py", line 253, in <module> main() File "/home/sdu/PycharmProjects/test/multi_process.py", line 233, in main detect_process.start() File "/usr/lib/python3.5/multiprocessing/process.py", line 105, in start self._popen = self._Popen(self) File "/usr/lib/python3.5/multiprocessing/context.py", line 212, in _Popen return _default_context.get_context().Process._Popen(process_obj) File "/usr/lib/python3.5/multiprocessing/context.py", line 281, in _Popen return Popen(process_obj) File "/usr/lib/python3.5/multiprocessing/popen_forkserver.py", line 36, in __init__ super().__init__(process_obj) File "/usr/lib/python3.5/multiprocessing/popen_fork.py", line 20, in __init__ self._launch(process_obj) File "/usr/lib/python3.5/multiprocessing/popen_forkserver.py", line 48, in _launch reduction.dump(process_obj, buf) File "/usr/lib/python3.5/multiprocessing/reduction.py", line 59, in dump ForkingPickler(file, protocol).dump(obj) ValueError: ctypes objects containing pointers cannot be pickled

 

The following is my code, and I hope to get some advice.

 

Looking forward to your reply.

 

Zachary

 

 

_CODE_

 

 

! ! def detect_camera_func(data_queue, device, graph1, in_fifo1, out_fifo1): ! cap = cv2.VideoCapture(0) ! cv2.namedWindow('capture', cv2.WINDOW_AUTOSIZE) ! while True: ! ret, frame = cap.read() ! img_resized = cv2.resize(frame, (300, 300)) ! image1 = image_preprocess.detect_img_preprocess(img_resized) ! in_fifo1.write_elem(image1.astype(np.float32), 'input_detect') ! graph1.queue_inference(in_fifo1, out_fifo1) ! out2, uob2 = out_fifo1.read_elem() ! print(uob2) ! print(out2.shape) ! face_boxes, face_images = ssd_detect_output_parse(frame, out2) ! print('face_images', len(face_images)) ! # for img in face_images: ! for (x1, y1, x2, y2), image_array in zip(face_boxes, face_images): ! print('have face :', len(face_boxes)) ! cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0), 2) ! img = cv2.resize(image_array, (160, 160)) ! img1_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) ! image1 = image_preprocess.prewhiten(img1_rgb) ! data_queue.put((frame, image1.astype(np.float32))) ! cv2.imshow('capture', frame) ! cv2.waitKey(1) !

 

 

 

 

! ! def reco_func(data_queue, device, graph2, in_fifo2, out_fifo2): ! sleep(5) ! while True: ! frame, pred_data = data_queue.get() ! in_fifo2.write_elem(pred_data, 'input_recognition') ! graph2.queue_inference(in_fifo2, out_fifo2) ! out1, uob1 = out_fifo2.read_elem() ! print(out1.shape) !

 

 

 

 

! ! def main(graph_path_detect, graph_path_recognition): ! # mp.set_start_method('forkserver') ! q = Queue(20) ! ! mvncapi.global_set_option(mvncapi.GlobalOption.RW_LOG_LEVEL, mvncapi.LogLevel.DEBUG) ! devices = mvncapi.enumerate_devices() ! print(devices) ! ! if len(devices) == 0: ! print('no have device') ! exit(1) ! ! device_ = mvncapi.Device(devices[0]) ! device_.open() ! ! graph1 = mvncapi.Graph('graph1') ! with open(graph_path1, 'rb') as f1: ! graph_buffer1 = f1.read() ! graph1.allocate(device_, graph_buffer1) ! ! graph2 = mvncapi.Graph('graph2') ! with open(graph_path2, 'rb') as f2: ! graph_buffer2 = f2.read() ! graph2.allocate(device_, graph_buffer2) ! ! in_fifo1 = mvncapi.Fifo('input_detect', mvncapi.FifoType.HOST_WO) ! out_fifo1 = mvncapi.Fifo('output_detect', mvncapi.FifoType.HOST_RO) ! input_descriptor_1 = graph1.get_option(mvncapi.GraphOption.RO_INPUT_TENSOR_DESCRIPTORS) ! output_descriptor_1 = graph1.get_option(mvncapi.GraphOption.RO_OUTPUT_TENSOR_DESCRIPTORS) ! in_fifo1.allocate(device_, input_descriptor_1[0], 5) ! out_fifo1.allocate(device_, output_descriptor_1[0], 5) ! ! in_fifo2 = mvncapi.Fifo('input_recognition', mvncapi.FifoType.HOST_WO) ! out_fifo2 = mvncapi.Fifo('output_recognition', mvncapi.FifoType.HOST_RO) ! input_descriptor_2 = graph2.get_option(mvncapi.GraphOption.RO_INPUT_TENSOR_DESCRIPTORS) ! output_descriptor_2 = graph2.get_option(mvncapi.GraphOption.RO_OUTPUT_TENSOR_DESCRIPTORS) ! in_fifo2.allocate(device_, input_descriptor_2[0], 30) ! out_fifo2.allocate(device_, output_descriptor_2[0], 30) ! ! detect_process = Process(target=detect_camera_func, args=(q, device_, graph1, in_fifo1, out_fifo1), name='detect') ! reco_process = Process(target=reco_func, args=(q, device_, graph2, in_fifo2, out_fifo2), name='face') ! ! detect_process.start() ! reco_process.start() ! detect_process.join() ! reco_process.join() !

 

 

 

 

! ! if __name__ == '__main__': ! graph_path_detect = 'datas/facenet_celeb_ncs/face2.08.graph' ! graph_path_recognition = 'datas/detection_model/detect.2.08.graph' ! main(graph_path_detect, graph_path_recognition) !

 

0 Kudos
4 Replies
idata
Community Manager
109 Views

@Zachary Hi I'm trying to reproduce your issue. What models were you using with your application?

idata
Community Manager
109 Views

@Zachary Also, which write_elem() is causing the error, detect_camera_func() or reco_func()? Thanks.

idata
Community Manager
109 Views

@Tome_at_Intel

 

Thank you for your reply.

 

I'm so sorry for not being able to describe the problem clearly!

 

I used Caffa MobileNet-ssd for face detection and the inception-resnet-v1 for face recognition.

 

The write_elem () will be blocked in detect_camera_func().

 

The ssd_detect_output_parse() is to get the boxes of faces and face images.
idata
Community Manager
109 Views

@Zachary I think the NCS device cannot be shared across processes. Additionally it looks like there is an issue involving SSD_MobileNet that needs to be addressed.

Reply