MediaPipe on the Web

Michael Hays and Tyler Mullen from the MediaPipe team
4 min readintermediate
--
View Original

Overview

The article discusses the implementation of MediaPipe on the web, highlighting how it enables cross-platform multimodal applied ML pipelines through WebAssembly and XNNPack. It introduces the MediaPipe Visualizer tool for designing and testing ML graphs directly in the browser.

What You'll Learn

1

How to run MediaPipe graphs live in a web browser using WebAssembly

2

Why using XNNPack can accelerate ML inference in web applications

3

How to utilize the MediaPipe Visualizer for graph design and testing

Key Questions Answered

How does MediaPipe run in a web browser?
MediaPipe runs in a web browser by compiling C++ code into WebAssembly using Emscripten, allowing for fast execution in a virtual machine created by the browser. This setup enables the integration of ML pipelines directly in the browser without needing server-side processing.
What is the purpose of the MediaPipe Visualizer?
The MediaPipe Visualizer serves as a tool for users to design and test MediaPipe graphs in real-time. Users can paste graph code or upload files, and the visualizer allows for interactive exploration of the graphs, making it easier to iterate on designs.
What are the performance optimizations made for MediaPipe on the web?
To improve performance, MediaPipe utilizes the GPU for image operations and employs lightweight ML models for faster processing. Additionally, it incorporates the XNNPack ML Inference Library, achieving a 2-3x speedup in applications compared to standard implementations.
What limitations currently exist for web-based MediaPipe?
Current limitations for web-based MediaPipe include restrictions on using only demo calculators, the inability to create custom graphs from scratch, and the requirement for a single-threaded executor. Additionally, TensorFlow Lite inference on GPU is not supported.

Key Statistics & Figures

Speedup from XNNPack
2-3x
This speedup applies to most applications utilizing the XNNPack ML Inference Library.

Technologies & Tools

Backend
Webassembly
Used to compile C++ code for fast execution in web browsers.
ML Library
Xnnpack
Accelerates ML inference in web applications.
Tools
Emscripten
Compiles C++ code into WebAssembly.
Graphics
Webgl
Used for rendering graphics in the MediaPipe framework.

Key Actionable Insights

1
Utilize the MediaPipe Visualizer to quickly prototype and test ML graphs in the browser.
This tool allows for immediate feedback and iteration, which is crucial for developers looking to refine their ML models without extensive setup.
2
Leverage WebAssembly for performance-critical applications to achieve faster execution times compared to traditional JavaScript.
By compiling C++ code to WebAssembly, developers can significantly improve the performance of their web applications, making it suitable for real-time ML inference.
3
Explore the use of XNNPack to enhance ML inference speed in web applications.
Integrating XNNPack can provide substantial performance improvements, especially in applications that require real-time processing, such as video analysis.

Common Pitfalls

1
Developers may attempt to create custom graphs from scratch, which is currently not supported.
This limitation can lead to frustration if users are unaware that they must edit existing demo graphs instead of starting new ones.
2
Expecting high performance from GPU inference with TensorFlow Lite, which is not currently supported.
This misunderstanding can result in performance bottlenecks, as users may not realize they need to optimize their models for CPU inference instead.

Related Concepts

Webassembly For Fast Web Applications
Machine Learning Model Optimization Techniques
Real-time Video Processing Applications