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

If tensorflow is imported first, media pipe solution hangs indefinitely #1461

Closed
NikhilBadami opened this issue Jan 4, 2021 · 12 comments
Closed
Assignees
Labels
legacy:pose Pose Detection related issues platform:python MediaPipe Python issues stale type:support General questions

Comments

@NikhilBadami
Copy link

NikhilBadami commented Jan 4, 2021

I was recently using the pose estimation solution in mediapipe in Python and came across an interesting bug. I found that if I imported tensorflow before importing mediapipe, it would cause the mediapipe library to hang indefinitely, but importing tensorflow second fixed this issue. The code I used to test this is below:

# import tensorflow --> Uncommenting this line will cause this file to hang
import cv2
import mediapipe as mp
mp_drawing = mp.solutions.drawing_utils
mp_pose = mp.solutions.pose
if __name__ == "__main__":
    # For static images:
    pose = mp_pose.Pose(static_image_mode=True, min_detection_confidence=0.5)
    path = "some/image/path"
    image = cv2.imread(path)
    image_hight, image_width, _ = image.shape
    # Convert the BGR image to RGB before processing.
    results = pose.process(cv2.cvtColor(image, cv2.COLOR_BGR2RGB)) --> This is the line the script hangs on

    # Draw pose landmarks on the image.
    annotated_image = image.copy()
    mp_drawing.draw_landmarks(
      annotated_image, results.pose_landmarks, mp_pose.POSE_CONNECTIONS)
    cv2.imshow('', annotated_image)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
    pose.close()

I am working on a Mac on Catalina

@jiuqiant jiuqiant self-assigned this Jan 5, 2021
@jiuqiant jiuqiant added the platform:python MediaPipe Python issues label Jan 5, 2021
@jiuqiant
Copy link
Collaborator

jiuqiant commented Jan 5, 2021

It hangs at https://github.com/google/mediapipe/blob/master/mediapipe/python/solution_base.py#L301 where it's waiting for the results coming back from the c++ graph execution logic.

MediaPipe has the c++ tflite inference engine in its binary. So, my initial guess is that the weird behavior is caused by the conflicts between MediaPipe's builtin tflite inference engine and TensorFlow's tflite inference engine. It's possible that who gets imported first will be registered and the latter one will be totally ignored.

@danhd123
Copy link

Same thing happens with ObjC/Swift on iOS. Mediapipe should probably include a warning in the documentation that you can't import Tensorflow separately and expect it to work.

@4sfaloth
Copy link

any news on this? I may be experiencing the same issue, though it is not fixed by importing tensorflow first

@sgowroji sgowroji added legacy:pose Pose Detection related issues stat:awaiting response Waiting for user response type:support General questions labels Aug 10, 2021
@sgowroji sgowroji assigned sgowroji and unassigned jiuqiant Aug 10, 2021
@google-ml-butler
Copy link

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
Copy link

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

@google-ml-butler
Copy link

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

@sgowroji
Copy link

sgowroji commented Oct 6, 2021

We are reopening this issue as this still exist even with the latest release.

@sgowroji sgowroji reopened this Oct 6, 2021
@sgowroji sgowroji added the stat:awaiting googler Waiting for Google Engineer's Response label Oct 6, 2021
@sgowroji sgowroji assigned jiuqiant and unassigned sgowroji Oct 6, 2021
@flacle
Copy link

flacle commented May 29, 2022

It hangs at https://github.com/google/mediapipe/blob/master/mediapipe/python/solution_base.py#L301 where it's waiting for the results coming back from the c++ graph execution logic.

MediaPipe has the c++ tflite inference engine in its binary. So, my initial guess is that the weird behavior is caused by the conflicts between MediaPipe's builtin tflite inference engine and TensorFlow's tflite inference engine. It's possible that who gets imported first will be registered and the latter one will be totally ignored.

In case you are working with classes, for this special case it might help to scope tensorflow on a class level by using import_module from importlib. Something like this in your __init__():

self.__tf = importlib.import_module('tensorflow')

@sureshdagooglecom
Copy link

sureshdagooglecom commented Sep 23, 2022

Hi @NikhilBadami ,
Could you please try in latest version and confirm if working fine .

@sureshdagooglecom sureshdagooglecom removed the stat:awaiting googler Waiting for Google Engineer's Response label Sep 23, 2022
@sureshdagooglecom sureshdagooglecom self-assigned this Sep 23, 2022
@google-ml-butler
Copy link

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
Copy link

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

@google-ml-butler
Copy link

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

@sureshdagooglecom sureshdagooglecom removed the stat:awaiting response Waiting for user response label Oct 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy:pose Pose Detection related issues platform:python MediaPipe Python issues stale type:support General questions
Projects
None yet
Development

No branches or pull requests

7 participants