Skip to content

GPU Support for Pose Estimation on MacOS or Linux server #5568

Description

@Sun-Yize

Have I written custom code (as opposed to using a stock example script provided in MediaPipe)

Yes

OS Platform and Distribution

MacOS M2 Chip

MediaPipe Tasks SDK version

0.10.14

Task name (e.g. Image classification, Gesture recognition etc.)

Pose Estimation

Programming Language and version (e.g. C++, Python, Java)

Python

Describe the actual behavior

I tried to run the GPU version of mediapipe in macos, but I kept getting the following error. If it is set to CPU, that is, delegate=BaseOptions.Delegate.CPU, everything works fine

Describe the expected behaviour

Bug Fix

Standalone code/steps you may have used to try to get what you need

import mediapipe as mp
import cv2


BaseOptions = mp.tasks.BaseOptions
PoseLandmarker = mp.tasks.vision.PoseLandmarker
PoseLandmarkerOptions = mp.tasks.vision.PoseLandmarkerOptions
VisionRunningMode = mp.tasks.vision.RunningMode

options = PoseLandmarkerOptions(
    base_options=BaseOptions(
        model_asset_path='data/pose_landmarker_heavy.task',
        delegate=BaseOptions.Delegate.GPU
    ),
    running_mode=VisionRunningMode.IMAGE, 
)

mp_pose = mp.solutions.pose
mp_drawing = mp.solutions.drawing_utils

with PoseLandmarker.create_from_options(options) as landmarker:
    cap = cv2.VideoCapture('test2.mp4')
    fps = cap.get(cv2.CAP_PROP_FPS)
    frame_interval = int(fps // 5)
    count = 0
    while cap.isOpened():
        ret, image = cap.read()
        mp_image = mp.Image(image_format=mp.ImageFormat.SRGB, data=image)
        results = landmarker.detect(mp_image)
        count += 1
    cap.release()
    cv2.destroyAllWindows()

Other info / Complete Logs

WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
I0000 00:00:1723543300.469173 1531245 gl_context.cc:357] GL version: 2.1 (2.1 Metal - 88.1), renderer: Apple M2
INFO: Created TensorFlow Lite delegate for Metal.
F0000 00:00:1723543300.834500 1531448 gpu_buffer_storage_cv_pixel_buffer.cc:154] Check failed: status_or_buffer is OK (UNKNOWN: ; unsupported ImageFrame format: 1) 
*** Check failure stack trace: ***
    @        0x12183c938  absl::log_internal::LogMessage::SendToLog()
    @        0x12183c380  absl::log_internal::LogMessage::Flush()
    @        0x12183cc64  absl::log_internal::LogMessageFatal::~LogMessageFatal()
    @        0x12183cc8c  absl::log_internal::LogMessageFatal::~LogMessageFatal()
    @        0x121210de4  mediapipe::ConvertFromImageFrame()
    @        0x121211654  std::__1::__invoke_void_return_wrapper<>::__call<>()
    @        0x12120f634  std::__1::invoke<>()
    @        0x12120e3d8  mediapipe::GpuBuffer::StorageHolder::GetStorageForView()
    @        0x12120ee58  mediapipe::GpuBuffer::GetStorageForViewOrDie()
    @        0x121193e28  mediapipe::Image::ConvertToGpu()
    @        0x120c77840  std::__1::__function::__func<>::operator()()
    @        0x1212154e8  mediapipe::GlContext::SwitchContextAndRun()
    @        0x121214c2c  mediapipe::GlContext::Run()
    @        0x120c8238c  mediapipe::GlCalculatorHelper::RunInGlContext()
    @        0x120c82550  mediapipe::GlCalculatorHelper::RunInGlContext()
    @        0x120c77558  mediapipe::GlCalculatorHelper::RunInGlContext<>()
    @        0x120c76ba4  mediapipe::api2::ImageCloneCalculator::Process()
    @        0x121226674  mediapipe::CalculatorNode::ProcessNode()
    @        0x121204ddc  mediapipe::internal::SchedulerQueue::RunCalculatorNode()
    @        0x121204878  mediapipe::internal::SchedulerQueue::RunNextTask()
    @        0x12121e9d8  mediapipe::ThreadPool::RunWorker()
    @        0x12121e3f4  mediapipe::ThreadPool::WorkerThread::ThreadBody()
    @        0x19014ef94  _pthread_start
    @        0x190149d34  thread_start
zsh: abort      python test_mediapipe.py

Metadata

Metadata

Assignees

Labels

gpuMediaPipe GPU related issuesos:macOSIssues on MacOSplatform:pythonMediaPipe Python issuestask:pose landmarkerIssues related to Pose Landmarker: Find people and body positionstype:bugBug in the Source Code of MediaPipe Solution

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions