Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selfie Segmentation crashes after running a while, on Linux CPU #2250

Closed
de-code opened this issue Jul 4, 2021 · 3 comments
Closed

Selfie Segmentation crashes after running a while, on Linux CPU #2250

de-code opened this issue Jul 4, 2021 · 3 comments
Assignees
Labels
legacy:selfie segmentation Issues related to selfie segmentation platform:python MediaPipe Python issues type:research Model specific questions

Comments

@de-code
Copy link

de-code commented Jul 4, 2021

System information (Please provide as much relevant information as possible)

  • Have I written custom code (as opposed to using a stock example script provided in Mediapipe): I have written an example to better reproduce the issue
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04, Android 11, iOS 14.4): Linux 20.04
  • MediaPipe version: 0.8.6
  • Bazel version: n/a
  • Solution (e.g. FaceMesh, Pose, Holistic): Selfie Segmentation
  • Programming Language and version ( e.g. C++, Python, Java): Python

Describe the expected behavior:

It shouldn't crash.

Standalone code you may have used to try to get what you need :

This more or less matches #2219 but for Linux and using Python.

I created a gist with Dockerfile to replicate the issue.

Copied the Python code here:

from time import sleep

import numpy as np
import mediapipe as mp
from tqdm import tqdm


mp_drawing = mp.solutions.drawing_utils
mp_selfie_segmentation = mp.solutions.selfie_segmentation

image_shape = (480, 640, 3)

np.random.seed(42)

print('Press Ctrl+C to exit')

try:
    with mp_selfie_segmentation.SelfieSegmentation(
        model_selection=1
    ) as selfie_segmentation:
        with tqdm() as pbar:
            while True:
                image = (np.random.random_sample(image_shape) * 255).astype('uint8')
                result = selfie_segmentation.process(image)
                result.segmentation_mask
                sleep(0.01)
                pbar.update(1)
except KeyboardInterrupt:
    print('exiting')

It might crash after a few hundred or only after more than 10k iterations.

I tried it with Pyhon 3.7, 3.8 and 3.9 as the base image.

Other info / Complete Logs :

Example output:

Press Ctrl+C to exit
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
10913it [04:23, 31.69it/s]

(It shouldn't exit until Ctrl+C was pressed)

In another app where I actually wanted to use it, I was getting a stacktrace (which I don't seem to see in the minimal example):

Fatal Python error: PyEval_SaveThread: NULL tstate

Thread 0x00007fd2e9ad0740 (most recent call first):
  File "/path/to/layered-vision/venv/lib/python3.8/site-packages/mediapipe/python/solution_base.py", line 307 in process
  File "/path/to/layered-vision/venv/lib/python3.8/site-packages/mediapipe/python/solutions/selfie_segmentation.py", line 76 in process
  File "/path/to/layered-vision/layered_vision/filters/mp_selfie_segmentation.py", line 94 in get_segmentation_mask
  ...
Aborted (core dumped)
@de-code de-code added the type:support General questions label Jul 4, 2021
@sgowroji sgowroji added platform:python MediaPipe Python issues legacy:selfie segmentation Issues related to selfie segmentation stat:awaiting googler Waiting for Google Engineer's Response labels Jul 5, 2021
@sgowroji sgowroji assigned jiuqiant and unassigned sgowroji Jul 5, 2021
@sgowroji sgowroji added type:research Model specific questions and removed type:support General questions labels Jul 27, 2021
@jiuqiant
Copy link
Collaborator

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

@de-code
Copy link
Author

de-code commented Aug 26, 2021

At least with my minimal example it hasn't crashed anymore after more than an hour (using 0.8.7.1).

@de-code de-code closed this as completed Aug 26, 2021
@sgowroji sgowroji removed the stat:awaiting googler Waiting for Google Engineer's Response label Aug 27, 2021
@cova-fe
Copy link

cova-fe commented Aug 27, 2021

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

I tried in the same conditions that made the previous version to crash, and it is not happening again. Maybe not a definitive proof, but looks promising.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy:selfie segmentation Issues related to selfie segmentation platform:python MediaPipe Python issues type:research Model specific questions
Projects
None yet
Development

No branches or pull requests

4 participants