google-ai-edge / mediapipe

Cross-platform, customizable ML solutions for live and streaming media.
https://ai.google.dev/edge/mediapipe
Apache License 2.0
27.72k stars 5.18k forks source link

when multi open python mediapipe facemesh #2269

Closed linyu0219 closed 3 years ago

linyu0219 commented 3 years ago

When I start 20-50 more the under python process, core dump will happen. when into the python mediapipe module, error happen here self._graph.wait_until_idle() ,will return 'Fatal Python error: PyEval_SaveThread: NULL tstate' This error happened in 0.8.6 0.8.5 0.8.4.2 0.8.4.1 But it will not in 0.8.3.1

import cv2
import argparse
import mediapipe as mp
import time
mp_drawing = mp.solutions.drawing_utils
mp_face_mesh = mp.solutions.face_mesh

parser = argparse.ArgumentParser()
parser.add_argument('-n', type=int, required=True)
args = parser.parse_args()

# For static images:
IMAGE_FILES = []
image=cv2.imread('person.png')
img=cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
counter=0
start_time=time.time()
with mp_face_mesh.FaceMesh(
    static_image_mode=False,
    max_num_faces=1,
    min_detection_confidence=0.5) as face_mesh:
    while True:
        # Convert the BGR image to RGB before processing.
        results = face_mesh.process(image)
        counter+=1

        # Print and draw face mesh landmarks on the image.
        if (time.time() - start_time) > 10:
            print(f'Worker {args.n} -', "detect FPS: ", counter / (time.time() - start_time))
            counter = 0
            start_time = time.time()
linyu0219 commented 3 years ago

I try this because when I own program, I open 5 process core dump will happen ,because other functions also cost cpu.

sgowroji commented 3 years ago

Hi @linyu0219, Could you please provide the steps to reproduce the above error. Thanks! !

linyu0219 commented 3 years ago

put above code in a py. and use bash open multiple python process

python mediapipe_test.py -n 31 &
python mediapipe_test.py -n 32 &
python mediapipe_test.py -n 33 &
python mediapipe_test.py -n 34 &
python mediapipe_test.py -n 35 &
python mediapipe_test.py -n 36 &
python mediapipe_test.py -n 37 &
python mediapipe_test.py -n 38 &
python mediapipe_test.py -n 39 &
python mediapipe_test.py -n 40 &
python mediapipe_test.py -n 41 &
python mediapipe_test.py -n 42 &
python mediapipe_test.py -n 43 &
python mediapipe_test.py -n 44 &
python mediapipe_test.py -n 45 &
python mediapipe_test.py -n 46 &
python mediapipe_test.py -n 47 &
python mediapipe_test.py -n 48 &
python mediapipe_test.py -n 49 &
python mediapipe_test.py -n 50 &
linyu0219 commented 3 years ago

0.8.3.1 also core dump ,but dump slow than other version. it happened cpu is nealy 80%usage, mediapipe can't get the cpu resource, it will core dump.

maky-hnou commented 3 years ago

I am facing the same thing with hand tracking when I run a multithreading python code.

jiuqiant commented 3 years ago

There is a GIL related fix in the latest v0.8.7.1 python binaries, which may help resolve this issue. Try pip install mediapipe==0.8.7.1

google-ml-butler[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you.

google-ml-butler[bot] commented 3 years ago

Closing as stale. Please reopen if you'd like to work on this further.

google-ml-butler[bot] commented 3 years ago

Are you satisfied with the resolution of your issue? Yes No