Have I written custom code (as opposed to using a stock example script provided in MediaPipe)
Yes
OS Platform and Distribution
macOS Venture 13.7.3
Apple M1 16GB
MediaPipe Tasks SDK version
mediapipe==0.10.31
Task name (e.g. Image classification, Gesture recognition etc.)
Pose landmark detection
Programming Language and version (e.g. C++, Python, Java)
python 3.12.7
Describe the actual behavior
Memory leaks during GPU execution no longer occur with mediapipe==0.10.31, but the processing speed difference between CPU and GPU processing is no longer noticeable, as it was with mediapipe==0.10.20.
Describe the expected behaviour
I want to improve processing speed using a GPU.
Standalone code/steps you may have used to try to get what you need
import mediapipe as mp
from mediapipe.tasks import python
from mediapipe.tasks.python import vision
import cv2 as cv
import numpy as np
import time
BaseOptions = mp.tasks.BaseOptions
PoseLandmarker = mp.tasks.vision.PoseLandmarker
PoseLandmarkerOptions = mp.tasks.vision.PoseLandmarkerOptions
PoseLandmarkerResult = mp.tasks.vision.PoseLandmarkerResult
VisionRunningMode = mp.tasks.vision.RunningMode
base_options = python.BaseOptions(
model_asset_path='./models/mp/pose_landmarker_heavy.task',
# delegate=python.BaseOptions.Delegate.CPU, # CPU
delegate=python.BaseOptions.Delegate.GPU # GPU
)
options = PoseLandmarkerOptions(
#base_options=BaseOptions(model_asset_path='./models/mp/pose_landmarker_heavy.task'), # CPU
base_options=base_options, # GPU
running_mode=VisionRunningMode.VIDEO,
num_poses = 4,
min_pose_detection_confidence=0.7
)
def main():
cap = cv.VideoCapture(0)
if not cap.isOpened():
print("Cannot open camera")
return
with PoseLandmarker.create_from_options(options) as landmarker:
while True:
ret, frame = cap.read()
if not ret:
print("Cannot receive frame")
break
mediapipe_start = time.time()
# Convert BGR image to RGB
# GPU
rgba_frame = cv.cvtColor(frame, cv.COLOR_BGR2RGBA)
mp_image = mp.Image(image_format=mp.ImageFormat.SRGBA, data=rgba_frame)
# CPU
#rgb_image = cv.cvtColor(frame, cv.COLOR_BGR2RGB)
#mp_image = mp.Image(image_format=mp.ImageFormat.SRGB, data=rgb_image)
# landmark detection
pose_landmarker_result = landmarker.detect_for_video(mp_image, int(time.time() * 1000))
mediapipe_end = time.time()
elapsed_time = mediapipe_end - mediapipe_start
print(f"Mediapipe Pose Landmarker: {elapsed_time*1000:.2f} ms")
cv.imshow('Pose Landmarks', frame)
if cv.waitKey(1) & 0xFF == 27:
break
if __name__ == "__main__":
main()
Other info / Complete Logs
Additionally, the following warning appears during GPU execution. Is this related?
W0000 00:00:1768377893.862985 970510 landmark_projection_calculator.cc:81] Using NORM_RECT without IMAGE_DIMENSIONS is only supported for the square ROI. Provide IMAGE_DIMENSIONS or use PROJECTION_MATRIX.
Have I written custom code (as opposed to using a stock example script provided in MediaPipe)
Yes
OS Platform and Distribution
macOS Venture 13.7.3
Apple M1 16GB
MediaPipe Tasks SDK version
mediapipe==0.10.31
Task name (e.g. Image classification, Gesture recognition etc.)
Pose landmark detection
Programming Language and version (e.g. C++, Python, Java)
python 3.12.7
Describe the actual behavior
Memory leaks during GPU execution no longer occur with mediapipe==0.10.31, but the processing speed difference between CPU and GPU processing is no longer noticeable, as it was with mediapipe==0.10.20.
Describe the expected behaviour
I want to improve processing speed using a GPU.
Standalone code/steps you may have used to try to get what you need
Other info / Complete Logs
Additionally, the following warning appears during GPU execution. Is this related?
W0000 00:00:1768377893.862985 970510 landmark_projection_calculator.cc:81] Using NORM_RECT without IMAGE_DIMENSIONS is only supported for the square ROI. Provide IMAGE_DIMENSIONS or use PROJECTION_MATRIX.