Skip to content

GPU for pose detection enabled but no performance increase #6041

@Julian-Banks

Description

@Julian-Banks

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

Yes

OS Platform and Distribution

MacOS 15.5

MediaPipe Tasks SDK version

Version: 0.10.21

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

Pose landmark detection (GPU enable)

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

Python

Describe the actual behavior

Framerate for pose detection is the same for CPU and GPU

Describe the expected behaviour

Framerate for pose detection is faster with GPU enabled.

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

import mediapipe as mp
import cv2
import time
from collections import deque
BaseOptions = mp.tasks.BaseOptions
PoseLandmarker = mp.tasks.vision.PoseLandmarker
PoseLandmarkerOptions = mp.tasks.vision.PoseLandmarkerOptions
PoseLandmarkerResult = mp.tasks.vision.PoseLandmarkerResult
VisionRunningMode = mp.tasks.vision.RunningMode


model_path = '/absolute/path/to/pose_landmarker.task'

class FPSMeter:
    def __init__(self, window_seconds = 30.0):
        self.timestamps = deque()
        self.window = window_seconds
    def update(self):
        now = time.perf_counter()
        self.timestamps.append(now)

        while self.timestamps and (now-self.timestamps[0])>self.window:
            self.timestamps.popleft()

        if len(self.timestamps)>1:
            duration = self.timestamps[-1] - self.timestamps[0]
            fps = len(self.timestamps)/duration if duration > 0 else 0.0
        else:
            fps = 0.0

        print(f"Average FPS (last {self.window:.0f}s): {fps:.2f}")
        return fps

fps_meter = FPSMeter(window_seconds=30)

def print_result(result: PoseLandmarkerResult, output_image: mp.Image, timestamp_ms: int):
    if result is None:
        print('no result!')
    else:
       fps_meter.update()

options = PoseLandmarkerOptions(
    base_options=BaseOptions(model_asset_path=model_path ,delegate=BaseOptions.Delegate.GPU),
    running_mode=VisionRunningMode.LIVE_STREAM,
    result_callback=print_result)

stream = cv2.VideoCapture(0)
if not stream.isOpened():
    print("no stream :(")
    exit()

#create the landmarker
landmarker = PoseLandmarker.create_from_options(options)

while (True):
    ret, frame = stream.read()
    frame_timestamp_ns = time.monotonic_ns()//1000 
    if not ret:
        print("No more stream :( ")
        break

    mp_frame = mp.Image(image_format=mp.ImageFormat.SRGBA, data=cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA))
            
    landmarker.detect_async(mp_frame, frame_timestamp_ns) 

    if cv2.waitKey(1) == ord('q'):
        break

stream.release() 

Other info / Complete Logs

When running with GPU in the base options:

WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
I0000 00:00:1752594257.192764   49864 gl_context.cc:369] GL version: 2.1 (2.1 Metal - 89.4), renderer: Apple M1 Pro
INFO: Created TensorFlow Lite delegate for Metal.
W0000 00:00:1752594257.332836   49967 landmark_projection_calculator.cc:186] Using NORM_RECT without IMAGE_DIMENSIONS is only supported for the square ROI. Provide IMAGE_DIMENSIONS or use PROJECTION_MATRIX.

... fps averages out over 30 seconds....
Average FPS (last 30s): 27.14

When running with default:

WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
I0000 00:00:1752594148.404747   47815 gl_context.cc:369] GL version: 2.1 (2.1 Metal - 89.4), renderer: Apple M1 Pro
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
W0000 00:00:1752594148.459899   47936 inference_feedback_manager.cc:114] Feedback manager requires a model with a single signature inference. Disabling support for feedback tensors.
W0000 00:00:1752594148.468793   47935 inference_feedback_manager.cc:114] Feedback manager requires a model with a single signature inference. Disabling support for feedback tensors.
W0000 00:00:1752594148.515939   47940 landmark_projection_calculator.cc:186] Using NORM_RECT without IMAGE_DIMENSIONS is only supported for the square ROI. Provide IMAGE_DIMENSIONS or use PROJECTION_MATRIX

.... fps averages out over 30 seconds ....
Average FPS (last 30s): 27.14

Metadata

Metadata

Assignees

Labels

gpuMediaPipe GPU related issuesplatform:pythonMediaPipe Python issuestask:pose landmarkerIssues related to Pose Landmarker: Find people and body positionstype:performanceExecution Time and memory heap, stackoverflow and garbage collection related

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions