页面简介
Cross-platform vision, text, audio, retrieval, and decision tasks for Web, Android, iOS, Python, and Flutter. Run models on-device and test them interactively in your browser.
正文摘录
Home Products Google AI Edge MediaPipe Send feedback MediaPipe Tasks Live ML anywhere Run vision, text, audio, retrieval, and decision models directly in your app across Web, Android, iOS, Python, and Flutter with on-device CPU and GPU acceleration. Browse 22 tasks Web Demos GitHub Samples Quickstart Web, Android, iOS, Python & Flutter CPU & GPU acceleration On-device inference Consistent API across platforms Build once with matching task options and result types across JavaScript, Kotlin/Java, Swift, and Python. Hardware-accelerated pipelines Each task bundles preprocessing, LiteRT model execution, and postprocessing on CPU or GPU. Real-time streaming modes Process single images, decoded video files, or live camera and audio streams with low-latency on-device execution. Explore the tasks 22 on-device tasks across five categories. Pick a category to filter, or browse them all. All 22 Audio 3 Decision 1 Retrieval 2 Text 5 Vision 11 Demos SDK overview & setup Audio3 tasks Classify sounds, transcribe speech, and synthesize voice on-device. Audio ClassifierClassify 521 everyday sound events with YAMNet.WebAndroidiOSPythonFlutter NewAudio TranscriberTranscribe speech audio into text on-device with punctuation and capitalization.WebAndroidiOSPythonFlutter NewText-to-SpeechSynthesize natural 24 kHz speech audio locally from text.WebAndroidiOSPythonFlutter Decision1 task Score choices and rubrics on-device. NewDecision MakerScore choices, booleans, and rubrics in a single forward pass.WebAndroidiOSPythonFlutter Retrieval2 tasks Embed and search text and images for on-device RAG. NewSemantic RetrieverIndex chunks and retrieve relevant context for on-device RAG.WebAndroidiOSPythonFlutter NewUniversal EmbedderEmbed text, images, and audio into a shared multimodal vector space.WebAndroidiOSPythonFlutter Text5 tasks Classify, detect languages, embed, proofread, and summarize text. Language DetectorIdentify the language of text across 110+ languages.WebAndroidiOSPythonFlutter Text ClassifierClassify sentiment and custom text categories on-device.WebAndroidiOSPythonFlutter Text EmbedderCompute semantic text embeddings for similarity and search.WebAndroidiOSPythonFlutter NewText ProofreaderCheck and correct grammar and spelling locally with Gemma.AndroidiOSPythonFlutter NewText SummarizerSummarize articles and notes into concise bullet points on-device.AndroidiOSPythonFlutter Vision11 tasks Detect, track, segment, and classify in images, video, and camera streams. Face DetectorLocate faces with bounding boxes and 6 facial keypoints.WebAndroidiOSPythonFlutter Face LandmarkerPredict 478 3D facial landmarks and 52 expression blendshapes.WebAndroidiOSPythonFlutter Gesture RecognizerClassify common hand gestures alongside 3D hand landmarks.WebAndroidiOSPythonFlutter Hand LandmarkerDetect 21 3D hand landmarks and handedness in real time.WebAndroidiOSPythonFlutter Holistic LandmarkerCombine face, hand, and body pose landmarks in a single pipeline.WebAndroidiOSPythonFlutter Image ClassifierClassify images and video frames across 1,000+ categories.WebAndroidiOSPythonFlutter Image EmbedderExtract feature vectors from images for visual similarity search.WebAndroidiOSPythonFlutter Image SegmenterSegment people, hair, clothes, and backgrounds at pixel resolution.WebAndroidiOSPythonFlutter Interactive SegmenterGenerate an object cutout mask around a user click or scribble.WebAndroidiOSPythonFlutter Object DetectorDetect and label multiple objects with bounding boxes and scores.WebAndroidiOSPythonFlutter Pose LandmarkerTrack 33 full-body 3D landmarks and optional segmentation masks.WebAndroidiOSPythonFlutter Quickstart Install, configure, and run — the same three steps on every platform. 1Install the SDKAdd the domain package from npm, Maven Central, Swift Package Manager, PyPI, or pub.dev. 2Configure the taskPoint baseOptions at a model file and choose a running mode and hardware delegate. The examples below use the Hand Landmarker model (hand_landmarker.task). 3Run inferencePrepare input data—images, video frames, live camera streams, text, or audio—and run inference. Web npmnpm install @mediapipe/tasks-visionWeb demo·Edit in StackBlitz·Setup guide Image IMAGEStateless · single frameSynchronous call on independent still images. Resets temporal tracking state on every call. import { FilesetResolver, HandLandmarker } from "@mediapipe/tasks-vision"; const vision = await FilesetResolver.forVisionTasks( "https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@latest/wasm" ); const handLandmarker = await HandLandmarker.createFromOptions(vision, { baseOptions: { modelAssetPath: "hand_landmarker.task", delegate: "GPU" }, runningMode: "IMAGE", numHands: 2, }); // Synchronous single-frame call (stateless across images) const image = document.getElementById("image") as HTMLImageElement; const result = handLandmarker.detect(image); Video VIDEOEvery frame · no dropsSynchronous tracking across decoded video frames with monotonic timestamps. Processes every frame in order and never drops frames. import { FilesetResolver, HandLandmarker } from "@mediapipe/tasks-vision"; const vision = await FilesetResolver.forVisionTasks( "https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@latest/wasm" ); const handLandmarker = await HandLandmarker.createFromOptions(vision, { baseOptions: { modelAssetPath: "hand_landmarker.task", delegate: "GPU" }, runningMode: "VIDEO", numHands: 2, }); // Synchronous across decoded frames with monotonic timestamps (never drops frames) for (const { frame, timestampMs } of decodedVideoFrames) { const result = handLandmarker.detectForVideo(frame, timestampMs); } Livestream VIDEO + rAFLive camera · latest frameWeb tasks run synchronously—pair runningMode: "VIDEO" with requestAnimationFrame so each paint inspects only the latest camera frame (skipping intermediate frames when busy). import { FilesetResolver, HandLandmarker } from "@mediapipe/tasks-vision"; const vision = await FilesetResolver.forVisionTasks( "https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@latest/wasm" ); // On Web, live camera loops pair runningMode: "VIDEO" with requestAnimationFrame const handLandmarker = await HandLandmarker.createFromOptions(vision, { baseOptions: { modelAssetPath: "hand_landmarker.task", delegate: "GPU" }, runningMode: "VIDEO", numHands: 2, }); const video = document.getElementById("webcam") as HTMLVideoElement; video.srcObject = await navigator.mediaDevices.getUserMedia({ video: true }); await video.play(); let lastVideoTime = -1; function renderLoop() { if (video.readyState >= 2 && video.currentTime !== lastVideoTime) { lastVideoTime = video.currentTime; const result = handLandmarker.detectForVideo(video, performance.now()); console.log(result.landmarks, result.handedness); } requestAnimationFrame(renderLoop); } renderLoop(); Android (Kotlin) Gradleimplementation("com.google.mediapipe:tasks-vision:latest.release")Sample code·Setup guide Image IMAGEStateless · single frameSynchronous call on independent still images. Resets temporal tracking state on every call. import com.google.mediapipe.framework.image.BitmapImageBuilder import com.google.mediapipe.framework.image.MPImage import com.google.mediapipe.tasks.core.BaseOptions import com.google.mediapipe.tasks.vision.core.RunningMode import com.google.mediapipe.tasks.vision.handlandmarker.HandLandmarker val baseOptions = BaseOptions.builder() .setModelAssetPath("hand_landmarker.task") .build() val options = HandLandmarker.HandLandmarkerOptions.builder() .setBaseOptions(baseOptions) .setRunningMode(RunningMode.IMAGE) .setNumHands(2) .build() val handLandmarker = HandLandmarker.createFromOptions(context, options) // Synchronous single-image call (no temporal tracking across calls) val mpImage = BitmapImageBuilder(bitmap).build() val result = handLandmarker.detect(mpImage) Video VIDEOEvery frame · no dropsSynchronous tracking across decoded video frames with monotonic timestamps. Processes every frame in order and never drops frames. import com.google.mediapipe.framework.image.BitmapImageBuilder import com.google.mediapipe.framework.image.MPImage import com.google.mediapipe.tasks.core.BaseOptions import com.google.mediapipe.tasks.vision.core.RunningMode import com.google.mediapipe.tasks.vision.handlandmarker.HandLandmarker val baseOptions = BaseOptions.builder() .setModelAssetPath("hand_landmarker.task") .build() val options = HandLandmarker.HandLandmarkerOptions.builder() .setBaseOptions(baseOptions) .setRunningMode(RunningMode.VIDEO) .setNumHands(2) .build() val handLandmarker = HandLandmarker.createFromOptions(context, options) // Synchronous: processes every frame in order with monotonic timestamps (no frame drops) val mpImage = BitmapImageBuilder(frameBitmap).build() val result = handLandmarker.detectForVideo(mpImage, frameTimestampMs) Livestream LIVE_STREAMAsync · drops frames when busyAsynchronous camera pipeline with a result callback. Automatically drops incoming frames when busy so results stay current with low latency. import android.os.SystemClock import android.util.Log import com.google.mediapipe.framework.image.BitmapImageBuilder import com.google.mediapipe.framework.image.MPImage import com.google.mediapipe.tasks.core.BaseOptions import com.google.mediapipe.tasks.vision.core.RunningMode import com.google.mediapipe.tasks.vision.handlandmarker.HandLandmarker val baseOptions = BaseOptions.builder() .setModelAssetPath("hand_landmarker.task") .build() val options = HandLandmarker.HandLandmarkerOptions.builder() .setBaseOptions(baseOptions) .setRunningMode(RunningMode.LIVE_STREAM) .setNumHands(2) .setResultListener { result, _ -> val hands = result.landmarks() } .setErrorListener { error -> Log.e("MediaPipe", error.message.orEmpty()) } .build() val handLandmarker = HandLandmarker.createFromOptions(context, options) // Async: automatically drops incoming camera frames when busy so results stay current handLandmarker.detectAsync(mpImage, SystemClock.uptimeMillis()) Android (Java) Gradleimpleme