google-ai-edge / mediapipe

Cross-platform, customizable ML solutions for live and streaming media.
https://mediapipe.dev
Apache License 2.0
26.42k stars 5.07k forks source link

mediapipe hangs in google cloud functions. #4159

Open nakamura-alice opened 1 year ago

nakamura-alice commented 1 year ago

I am trying to use the mediapipe package in the python runtime of cloud function's gen1. However, when I execute a function from the mediapipe package, the process hangs there. The process does not stop and there is no error message. I have debugged with the print function in the cloud functions and confirmed that the mediapipe package is imported. I have also set the memory to 8,192MB and the timeout to 5 minutes, but the situation remains the same.

Do you know the reason and how to run mediapipe in cloud functions?

code

import mediapipe as mp
import cv2
import numpy as np

class FaceService:
    mpFaceMesh = mp.solutions.face_mesh
    faceMesh = mpFaceMesh.FaceMesh(max_num_faces=2, static_image_mode=True)
    mpDraw = mp.solutions.drawing_utils
    drawSpec = mpDraw.DrawingSpec(thickness=1, circle_radius=2)

    def get_landmarks468(self, img):
        imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
        selfFaceMesh = self.faceMesh
        results = selfFaceMesh.process(imgRGB)   <- it hangs here
        faceLms = results.multi_face_landmarks[0]
        ih, iw, ic = img.shape
        return np.matrix([[int(lm.x*iw), int(lm.y*ih)] for lm in faceLms.landmark])

def hello_world(request):
    face_service = FaceService()
    image = cv2.imread("path/to/test/image")
    landmark = face_service.get_landmarks468(image)
    print(landmark)

if __name__ == "__main__":
    hello_world(None)

runtime: python3.7 requirement.txt

google-cloud-storage==2.7.0
six
mediapipe==0.9.0.1
opencv-python==4.7.0.72
numpy
kuaashish commented 1 year ago

Hi @nakamura-alice, As mentioned above configuration, I tried to reproduce the issue from our end and could reproduce(gist) the issue successfully without any error in the colab. Would you please let us complete system configuration you are using such as OS, Python environment Jupyter, Anaconda, Colab etc? we suggest to fill the template as mentioned here to get maximum relevant info about the issue. Thank you!

nakamura-alice commented 1 year ago

Thank you for the comment @kuaashish. Here is the info in template. It will be grateful telling me any missing information.

OS Platform and Distribution

Google Cloud Functions gen1

Programming Language and version

Python 3.7

MediaPipe version

0.9.0.1