Source-linked AI summary

MediaPipe: A Framework for Building Perception Pipelines

Camillo Lugaresi, Jiuqiang Tang, Hadon Nash, Chris McClanahan, Esha Uboweja, Michael Hays, Fan Zhang, Chuo-Ling Chang, Ming Guang Yong, Juhyun Lee, Wan-Teh Chang, Wei Hua, Manfred Georg, Matthias Grundmann

arXiv:1906.08172v1cs.DC

TL;DR

Developing perception applications requires model selection, prototyping, resource-quality balancing, and mitigation of problematic cases. MediaPipe addresses these needs with reusable graph-based pipelines, deployment and evaluation tools, and cross-platform execution, supporting iterative application improvement.

  • Problem

    Developing perception applications requires selecting models, building prototypes, balancing resource consumption against solution quality, and addressing problematic cases.

  • Method

    MediaPipe builds perception applications as graphs of reusable calculators, with configuration, evaluation tools, and cross-platform deployment support.

  • Results

    MediaPipe supports rapid prototyping, efficient perception applications across multiple platforms, and iterative improvement with reproducible behavior across devices and platforms.

  • Takeaways & Limitations

    MediaPipe provides an environment for developing, evaluating, and deploying perception pipelines while allowing practitioners to focus on algorithm and model development.

  • Takeaways & Limitations

    MediaPipe’s input policies generally cannot be mixed arbitrarily, so calculators using special policies must be specifically written for and declare them.

Abstract

from arXiv · show

Building applications that perceive the world around them is challenging. A developer needs to (a) select and develop corresponding machine learning algorithms and models, (b) build a series of prototypes and demos, (c) balance resource consumption against the quality of the solutions, and finally (d) identify and mitigate problematic cases. The MediaPipe framework addresses all of these challenges. A developer can use MediaPipe to build prototypes by combining existing perception components, to advance them to polished cross-platform applications and measure system performance and resource consumption on target platforms. We show that these features enable a developer to focus on the algorithm or model development and use MediaPipe as an environment for iteratively improving their application with results reproducible across different devices and platforms. MediaPipe will be open-sourced at https://github.com/google/mediapipe.

1. Introduction

MediaPipe supports perception pipelines as graphs of reusable components, addressing coupling and cross-platform deployment challenges while enabling incremental prototyping and evaluation.

  • MediaPipe represents inference over sensory data as graphs of modular components that transform audio and video streams into perceived descriptions.Components include model inference, media-processing algorithms, and data transformations.
  • MediaPipe targets ML practitioners building production applications, research software, and technology prototypes through rapid perception-pipeline prototyping.
  • MediaPipe enables deployment across diverse hardware platforms and supports incremental pipeline improvement through configuration and evaluation tools.
  • Excessive coupling makes adding processing steps or inference models difficult, while supporting multiple platforms requires time-consuming optimization for target devices.
  • MediaPipe abstracts individual perception models into maintainable pipelines whose components can be reused across applications through a common time-series interface.
  • The framework combines sensory-data inference, performance-evaluation tools, and reusable processing components called calculators.

2. Related work

MediaPipe is positioned as a graph-based framework for streaming, high-level audio/video analysis, differing from systems designed primarily for batch processing, simulation, IPC, or low-level media operations.

  • MediaPipe supports dynamic high-level media semantics in which one input can produce zero, one, or multiple outputs.This distinguishes it from neural-network compute graphs with simpler deterministic node behavior.
  • Beam and Dataflow process large data chunks in batches on compute clusters, making them unsuitable for streaming audio/video processing.
  • Ptolemy focuses on modeling and simulation, whereas MediaPipe supports building, analyzing, and deploying concurrent audio/video-processing applications.
  • MediaPipe avoids the additional IPC overhead and complexity used by ROS graph nodes communicating as separate processes.
  • GStreamer targets low-level media handling and editing, while MediaPipe targets higher-level audio/video analysis and understanding.
  • Unlike OpenCV G-API, MediaPipe operates on arbitrary data types and natively supports streaming time-series data for audio and sensor analysis.

3. Architecture

MediaPipe structures perception applications as configurable directed graphs of reusable calculators connected by timestamped data, with mechanisms for refinement, validation, execution, and platform-specific tuning.

  • 3. Architecture: A MediaPipe pipeline is a directed graph of calculators specified by GraphConfig and executed through a Graph object.
  • 3. Architecture: Calculators communicate through streams carrying timestamped packets, while side packets provide constant data such as an ML model path.
  • 3. Architecture: Developers can refine graphs by inserting or replacing calculators and define custom calculators without specialized multithreading expertise because each calculator runs on at most one thread at a time.
  • 3. Architecture: Packets contain timestamps and shared immutable payloads of arbitrary C++ types, with inexpensive copies using reference-counted ownership.
  • 3. Architecture: Calculators receive streams or side packets and produce streams or side packets through a common customizable interface with contract, initialization, processing, and shutdown methods.
  • 3. Architecture: Graph initialization validates source uniqueness, type compatibility, and calculator contracts before execution.
  • 3. Architecture: GraphConfig describes topology and functionality, supports reusable subgraphs, and exposes executor, thread, and queue settings for platform-specific performance tuning.

4. Implementation

MediaPipe uses scheduling logic and synchronization primitives to process time-series data in a customizable fashion.

  • MediaPipe’s scheduling and synchronization mechanisms support customizable processing of time-series data.

4.1. Scheduling

MediaPipe schedules modular perception-graph nodes according to readiness, input policies, and configurable execution resources. Timestamp synchronization and determinism coordinate streams while flow control limits resource use.

  • Scheduling: Calculators execute as scheduler tasks when their readiness conditions are satisfied, with queues, executors, and configurable priorities controlling resource use.Nodes are assigned to scheduler queues and executors; priorities derive from graph layout, and executors can use different thread priorities.
  • Scheduling: Source nodes remain ready until closed, while non-source nodes require a valid input set under their configured input policy.The default policy commonly requires matching timestamps across available inputs, but developers can specify alternatives.
  • Synchronization: Decentralized execution processes different timestamps concurrently, increasing throughput through pipelining while local synchronization coordinates related streams.Timestamps primarily serve as synchronization keys, such as pairing detector outputs with their corresponding frames.
  • Input policies: Changing input policies changes the guarantees calculators can rely on, so special-policy calculators generally must be written for and declare that policy.Packets in each stream must have monotonically increasing timestamps, and tighter timestamp bounds can let downstream nodes settle inputs sooner.
  • Input policies: The default input policy deterministically processes settled input timestamps in ascending order, groups same-timestamp packets, drops none, and runs as soon as guarantees permit.A timestamp is settled once the stream bound makes its state irrevocably known; available packets at that timestamp form one input set.
  • Flow control: Flow control uses back-pressure to throttle upstream nodes or specialized nodes to drop packets, trading buffering and determinism against real-time resource constraints.Back-pressure is suited to batch resource control, while node-based limiting lets authors choose where packets may be dropped.

4.2. GPU support

MediaPipe supports composable GPU and CPU processing while accommodating platform-specific GPU APIs. Its OpenGL design uses multiple contexts and automatic command-stream synchronization to preserve efficient pipelining.

  • GPU architecture: MediaPipe combines GPU compute and rendering nodes with CPU nodes, while allowing each GPU node to use platform-specific APIs rather than one cross-API abstraction.This preserves encapsulation and composability for GPU nodes while maintaining efficiency.
  • GPU architecture: GPU buffers use opaque types with API-specific temporary views, enabling platform-dependent implementations and synchronization during view creation and release.The helper-produced view is ephemeral and is released after the node finishes its processing task.
  • OpenGL support: Multiple OpenGL contexts let slower GPU inference and faster rendering paths use separate sequential command queues instead of reducing rendering to the slower path.MediaPipe assigns one dedicated thread per context, whose commands execute asynchronously on the GPU.
  • OpenGL support: OpenGL cross-context resource sharing requires GPU command-stream synchronization because CPU-thread synchronization alone does not ensure updated object state is visible.Sync fences make later commands in one context wait for preceding commands in another context to finish on the GPU.
  • OpenGL support: MediaPipe automatically inserts appropriate GPU synchronization operations, avoiding much of the programmer’s manual synchronization workload.Synchronization occurs in GPU command streams whenever possible, minimizing CPU synchronization and allowing GPU–CPU pipelining.

5. Tools

MediaPipe provides tracing and visualization tools for inspecting packet flow, calculator execution, graph topology, and performance problems. These tools support diagnosing delays, buffering, frame-rate mismatches, and latency.

  • Tracing: The tracer follows packets through the graph and records timing events for their execution paths.Trace events include event time, packet timestamp, packet data ID, node ID, and stream ID.
  • Tracing: Tracer timing data visualizes packet flows and calculator executions while diagnosing real-time delays, buffering-related memory accumulation, and mismatched frame rates.The data can also aggregate average and extreme latencies for performance tuning.
  • Tracing: Tracing is optional and can be enabled through GraphConfig or removed at compile time, with a mutex-free circular buffer limiting measurement overhead.The design reduces thread contention while timing data is recorded.
  • Visualization: The visualizer helps users inspect pipeline topology and behavior through timeline and graph views driven by recorded traces.The timeline shows packet timing across threads and calculators, while the graph view shows calculator and queue states over time.

6. Application examples

MediaPipe examples show how graph-based pipelines support efficient real-time object detection and face landmark and segmentation processing. These pipelines use parallelism, temporal processing, synchronization, and platform-specific implementations to balance computation and output quality.

  • 6.1. Object detection: 30 FPS object detection can require high resource consumption or become infeasible because of long inference times.
  • 6.1. Object detection: A two-branch graph runs slow detection on selected frames and fast tracking in parallel, allowing the tracker to process every frame.The detection branch selects frames by limiting frequency or scene-change analysis, while the detector outputs results from an inference model.
  • 6.1. Object detection: Detection merging aligns timestamps, removes duplicate results, and can send merged detections back to initialize new tracking targets.
  • 6.1. Object detection: A slightly delayed viewfinder stays aligned with computed and tracked detections, dynamically hiding model latency.
  • 6.1. Object detection: A graph developed and tested on desktop can be deployed and evaluated on mobile, while a node can be replaced with another implementation without changing the rest of the graph.The example contrasts a heavy neural-network detector with a light template-matching detector.
  • 6.2. Face landmark detection and segmentation: The face landmark and portrait-segmentation pipeline reduces computation by processing interleaving frame subsets, then temporally interpolating landmarks and masks across all frames.Annotations from both tasks are synchronized with camera frames before visualization.
  • 6.2. Face landmark detection and segmentation: GPU implementations can keep face-landmark detection, temporal resampling, annotation, and data flow on the GPU to avoid GPU-to-CPU transfer bottlenecks.

7. Conclusion

The paper presents MediaPipe as a reusable-calculator graph framework with scheduling, multi-platform GPU support, and performance-evaluation tools. The authors report rapid prototyping and efficient execution across platforms, while identifying ecosystem and tooling development as priorities after open sourcing.

  • MediaPipe builds perception pipelines as graphs of reusable calculators, with scheduling, multi-platform GPU support, and graph-performance evaluation tools.
  • MediaPipe can help developers prototype quickly and run perception applications efficiently across multiple platforms.
  • After open sourcing, the project prioritizes community support, third-party calculator development, recommended calculators and graphs, and easier performance and quality evaluation.
Loading 1906.08172v1…