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.44k stars 5.15k forks source link

WARNING: Logging before InitGoogleLogging() is written to STDERR #2810

Closed yoyojacky closed 2 years ago

yoyojacky commented 2 years ago

Please make sure that this is a bug and also refer to the troubleshooting, FAQ documentation before raising any issues.

System information

mp_draw = mp.solutions.drawing_utils mp_hands = mp.solutions.hands

cap = cv2.VideoCapture(0)

while True: ret, frame = cap.read() frame = cv2.flip(frame, 1) frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

hands = mp_hands.Hands(min_detection_confidence=0.5, min_tracking_confidence=0.5)
frame_rgb.flags.writeable = False
result = hands.process(frame_rgb)
frame_rgb.flags.writeable = True

frame = cv2.cvtColor(frame_rgb, cv2.COLOR_RGB2BGR)

if result.multi_hand_landmarks:
    for lms in result.multi_hand_landmarks:
        mp_draw.draw_landmarks(frame, lms, mp_hands.HAND_CONNECTIONS,
                               mp_draw.DrawingSpec(color=(255, 0, 255),thickness=5, circle_radius=5))
        mp_draw.draw_landmarks(frame, lms, mp_hands.HAND_CONNECTIONS, connection_drawing_spec=mp_draw.DrawingSpec((0, 255, 0), thickness=5, circle_radius=4))

cv2.imshow("junction2021", frame)

if cv2.waitKey(1) & 0xFF == 27:
    break

cap.release() cv2.destroyAllWindows()


- OS Platform and Distribution ( MacOS 11.6.1):
- Programming Language and version ( Python3.8):
- [MediaPipe version]( 0.8.9):
- Solution ( Hands ):

**Standalone code to reproduce the issue:**

WARNING: Logging before InitGoogleLogging() is written to STDERR F20211124 01:37:01.669302 261254656 threadpool_pthread_impl.cc:51] Check failed: res == 0 (35 vs. 0) pthread_create failed Check failure stack trace:


It also appears in my Raspberry Pi 4B too,  with the same code and  mediapipe version in Raspberry Pi 4b is `mediapipe-rpi4`. 
sgowroji commented 2 years ago

Hi @yoyojacky, Are you able to execute the code and see the result and Does that cause code breakage ? Python threading and glog logging did actually work ?

google-ml-butler[bot] commented 2 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 2 years ago

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

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

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

yoyojacky commented 2 years ago

Hi @yoyojacky, Are you able to execute the code and see the result and Does that cause code breakage ? Python threading and glog logging did actually work ?

Hi sgowroji, I found that it maybe the OS archteture issue, I am running an 64bit aarm64 OS which is downdload from here: https://downloads.raspberrypi.org/raspios_arm64/images/raspios_arm64-2022-01-28/ and i am create the virual environment by using virualenv and install the package via pip3 install mediapipe-rpi4 and using the same code from the mediapipe website and no luck, it will not work properly ,but openCV works fine.

mshemuni commented 2 years ago

I had the same issue and I found that:

The problem

Your problem is Memory. You are using your full memory.

Why?

Creating objects inside a loop. As a lazy python developer I always thought when a variable is overwritten the __del__ method will work and it will be garbage collected. it's not the case. del does not free the memory. It only informs that you are no longer in need of the memory. See: https://stackoverflow.com/a/35121781

In your code here:

hands = mp_hands.Hands(min_detection_confidence=0.5, min_tracking_confidence=0.5)

you are creating a Hands object over and over. And according to the information given above you are not freeing memory by overriding the variable.

Solution

You may need to move the line before the loop as such:

import cv2
import mediapipe as mp

mp_draw = mp.solutions.drawing_utils
mp_hands = mp.solutions.hands

cap = cv2.VideoCapture(0)

hands = mp_hands.Hands(min_detection_confidence=0.5, min_tracking_confidence=0.5)

while True:
    ret, frame = cap.read()
    frame = cv2.flip(frame, 1)
    frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

    frame_rgb.flags.writeable = False
    result = hands.process(frame_rgb)
    frame_rgb.flags.writeable = True

    frame = cv2.cvtColor(frame_rgb, cv2.COLOR_RGB2BGR)

    if result.multi_hand_landmarks:
        for lms in result.multi_hand_landmarks:
            mp_draw.draw_landmarks(frame, lms, mp_hands.HAND_CONNECTIONS,
                                   mp_draw.DrawingSpec(color=(255, 0, 255),thickness=5, circle_radius=5))
            mp_draw.draw_landmarks(frame, lms, mp_hands.HAND_CONNECTIONS, connection_drawing_spec=mp_draw.DrawingSpec((0, 255, 0), thickness=5, circle_radius=4))

    cv2.imshow("junction2021", frame)

    if cv2.waitKey(1) & 0xFF == 27:
        break

cap.release()
cv2.destroyAllWindows()

it will work perfectly.

matanox commented 6 months ago

Current incranation of the the same title description now at https://github.com/google/mediapipe/issues/5371