From 3ccf7308e03933ceb6285e7f347d2865c7a4d540 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Thu, 17 Nov 2022 05:26:56 -0800 Subject: [PATCH] Add shared options for Text and Audio Tasks PiperOrigin-RevId: 489186644 --- .../audioembedder/AudioEmbedderResult.java | 4 +- .../tasks/audio/core/RunningMode.java | 2 +- .../tasks/web/audio/audio_classifier/BUILD | 1 + .../audio_classifier_options.d.ts | 7 ++- mediapipe/tasks/web/audio/core/BUILD | 13 ++++++ .../web/audio/core/audio_task_options.d.ts | 44 +++++++++++++++++++ .../tasks/web/core/classifier_options.d.ts | 5 +-- .../tasks/web/core/embedder_options.d.ts | 5 +-- mediapipe/tasks/web/text/core/BUILD | 11 +++++ .../web/text/core/text_task_options.d.ts | 23 ++++++++++ .../tasks/web/text/text_classifier/BUILD | 1 + .../text_classifier_options.d.ts | 7 ++- mediapipe/tasks/web/text/text_embedder/BUILD | 1 + .../text_embedder/text_embedder_options.d.ts | 7 ++- mediapipe/tasks/web/vision/core/BUILD | 2 +- .../web/vision/core/vision_task_options.d.ts | 2 +- .../image_classifier_options.d.ts | 2 +- .../image_embedder_options.d.ts | 2 +- 18 files changed, 121 insertions(+), 18 deletions(-) create mode 100644 mediapipe/tasks/web/audio/core/BUILD create mode 100644 mediapipe/tasks/web/audio/core/audio_task_options.d.ts create mode 100644 mediapipe/tasks/web/text/core/BUILD create mode 100644 mediapipe/tasks/web/text/core/text_task_options.d.ts diff --git a/mediapipe/tasks/java/com/google/mediapipe/tasks/audio/audioembedder/AudioEmbedderResult.java b/mediapipe/tasks/java/com/google/mediapipe/tasks/audio/audioembedder/AudioEmbedderResult.java index ee4df0198..a986048f0 100644 --- a/mediapipe/tasks/java/com/google/mediapipe/tasks/audio/audioembedder/AudioEmbedderResult.java +++ b/mediapipe/tasks/java/com/google/mediapipe/tasks/audio/audioembedder/AudioEmbedderResult.java @@ -65,8 +65,8 @@ public abstract class AudioEmbedderResult implements TaskResult { /** * Contains one set of results per classifier head. A {@link EmbeddingResult} usually represents - * one audio embedding result in an audio stream, and s only available when running with the audio - * stream mode. + * one audio embedding result in an audio stream, and is only available when running with the + * audio stream mode. */ public abstract Optional embeddingResult(); diff --git a/mediapipe/tasks/java/com/google/mediapipe/tasks/audio/core/RunningMode.java b/mediapipe/tasks/java/com/google/mediapipe/tasks/audio/core/RunningMode.java index f0a123810..a778eae46 100644 --- a/mediapipe/tasks/java/com/google/mediapipe/tasks/audio/core/RunningMode.java +++ b/mediapipe/tasks/java/com/google/mediapipe/tasks/audio/core/RunningMode.java @@ -20,7 +20,7 @@ package com.google.mediapipe.tasks.audio.core; * */ public enum RunningMode { diff --git a/mediapipe/tasks/web/audio/audio_classifier/BUILD b/mediapipe/tasks/web/audio/audio_classifier/BUILD index 6a78116c3..412af3bea 100644 --- a/mediapipe/tasks/web/audio/audio_classifier/BUILD +++ b/mediapipe/tasks/web/audio/audio_classifier/BUILD @@ -36,6 +36,7 @@ mediapipe_ts_declaration( "audio_classifier_result.d.ts", ], deps = [ + "//mediapipe/tasks/web/audio/core:audio_task_options", "//mediapipe/tasks/web/components/containers:category", "//mediapipe/tasks/web/components/containers:classification_result", "//mediapipe/tasks/web/core", diff --git a/mediapipe/tasks/web/audio/audio_classifier/audio_classifier_options.d.ts b/mediapipe/tasks/web/audio/audio_classifier/audio_classifier_options.d.ts index 93bd9927e..975b1e315 100644 --- a/mediapipe/tasks/web/audio/audio_classifier/audio_classifier_options.d.ts +++ b/mediapipe/tasks/web/audio/audio_classifier/audio_classifier_options.d.ts @@ -14,4 +14,9 @@ * limitations under the License. */ -export {ClassifierOptions as AudioClassifierOptions} from '../../../../tasks/web/core/classifier_options'; +import {AudioTaskOptions} from '../../../../tasks/web/audio/core/audio_task_options'; +import {ClassifierOptions} from '../../../../tasks/web/core/classifier_options'; + +/** Options to configure the MediaPipe Audio Classifier Task */ +export declare interface AudioClassifierOptions extends ClassifierOptions, + AudioTaskOptions {} diff --git a/mediapipe/tasks/web/audio/core/BUILD b/mediapipe/tasks/web/audio/core/BUILD new file mode 100644 index 000000000..ed60f2435 --- /dev/null +++ b/mediapipe/tasks/web/audio/core/BUILD @@ -0,0 +1,13 @@ +# This package contains options shared by all MediaPipe Audio Tasks for Web. + +load("//mediapipe/framework/port:build_config.bzl", "mediapipe_ts_declaration") + +package(default_visibility = ["//mediapipe/tasks:internal"]) + +mediapipe_ts_declaration( + name = "audio_task_options", + srcs = ["audio_task_options.d.ts"], + deps = [ + "//mediapipe/tasks/web/core", + ], +) diff --git a/mediapipe/tasks/web/audio/core/audio_task_options.d.ts b/mediapipe/tasks/web/audio/core/audio_task_options.d.ts new file mode 100644 index 000000000..58a6e55d8 --- /dev/null +++ b/mediapipe/tasks/web/audio/core/audio_task_options.d.ts @@ -0,0 +1,44 @@ +/** + * Copyright 2022 The MediaPipe Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {BaseOptions} from '../../../../tasks/web/core/base_options'; + +/** + * MediaPipe audio task running mode. A MediaPipe audio task can be run with + * two different modes: + * - audio_clips: The mode for running a mediapipe audio task on independent + * audio clips. + * - audio_stream: The mode for running a mediapipe audio task on an audio + * stream, such as from a microphone. + * + */ +export type RunningMode = 'audio_clips'|'audio_stream'; + +/** The options for configuring a MediaPipe Audio Task. */ +export declare interface AudioTaskOptions { + /** Options to configure the loading of the model assets. */ + baseOptions?: BaseOptions; + + /** + * The running mode of the task. Default to the audio_clips mode. + * Audio tasks have two running modes: + * 1) The mode for running a mediapipe audio task on independent + * audio clips. + * 2) The mode for running a mediapipe audio task on an audio + * stream, such as from a microphone. + */ + runningMode?: RunningMode; +} diff --git a/mediapipe/tasks/web/core/classifier_options.d.ts b/mediapipe/tasks/web/core/classifier_options.d.ts index 3dec8d27e..1d804d629 100644 --- a/mediapipe/tasks/web/core/classifier_options.d.ts +++ b/mediapipe/tasks/web/core/classifier_options.d.ts @@ -16,11 +16,8 @@ import {BaseOptions} from '../../../tasks/web/core/base_options'; -/** Options to configure the Mediapipe Classifier Task. */ +/** Options to configure a MediaPipe Classifier Task. */ export declare interface ClassifierOptions { - /** Options to configure the loading of the model assets. */ - baseOptions?: BaseOptions; - /** * The locale to use for display names specified through the TFLite Model * Metadata, if any. Defaults to English. diff --git a/mediapipe/tasks/web/core/embedder_options.d.ts b/mediapipe/tasks/web/core/embedder_options.d.ts index 78ddad1ae..3ec2a170c 100644 --- a/mediapipe/tasks/web/core/embedder_options.d.ts +++ b/mediapipe/tasks/web/core/embedder_options.d.ts @@ -16,11 +16,8 @@ import {BaseOptions} from '../../../tasks/web/core/base_options'; -/** Options to configure the MediaPipe Embedder Task */ +/** Options to configure a MediaPipe Embedder Task */ export declare interface EmbedderOptions { - /** Options to configure the loading of the model assets. */ - baseOptions?: BaseOptions; - /** * Whether to normalize the returned feature vector with L2 norm. Use this * option only if the model does not already contain a native L2_NORMALIZATION diff --git a/mediapipe/tasks/web/text/core/BUILD b/mediapipe/tasks/web/text/core/BUILD new file mode 100644 index 000000000..3e7faec93 --- /dev/null +++ b/mediapipe/tasks/web/text/core/BUILD @@ -0,0 +1,11 @@ +# This package contains options shared by all MediaPipe Texxt Tasks for Web. + +load("//mediapipe/framework/port:build_config.bzl", "mediapipe_ts_declaration") + +package(default_visibility = ["//mediapipe/tasks:internal"]) + +mediapipe_ts_declaration( + name = "text_task_options", + srcs = ["text_task_options.d.ts"], + deps = ["//mediapipe/tasks/web/core"], +) diff --git a/mediapipe/tasks/web/text/core/text_task_options.d.ts b/mediapipe/tasks/web/text/core/text_task_options.d.ts new file mode 100644 index 000000000..4874e35bf --- /dev/null +++ b/mediapipe/tasks/web/text/core/text_task_options.d.ts @@ -0,0 +1,23 @@ +/** + * Copyright 2022 The MediaPipe Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {BaseOptions} from '../../../../tasks/web/core/base_options'; + +/** The options for configuring a MediaPipe Text task. */ +export declare interface TextTaskOptions { + /** Options to configure the loading of the model assets. */ + baseOptions?: BaseOptions; +} diff --git a/mediapipe/tasks/web/text/text_classifier/BUILD b/mediapipe/tasks/web/text/text_classifier/BUILD index 7dbbb18ca..8c3b8e226 100644 --- a/mediapipe/tasks/web/text/text_classifier/BUILD +++ b/mediapipe/tasks/web/text/text_classifier/BUILD @@ -40,5 +40,6 @@ mediapipe_ts_declaration( "//mediapipe/tasks/web/components/containers:category", "//mediapipe/tasks/web/components/containers:classification_result", "//mediapipe/tasks/web/core:classifier_options", + "//mediapipe/tasks/web/text/core:text_task_options", ], ) diff --git a/mediapipe/tasks/web/text/text_classifier/text_classifier_options.d.ts b/mediapipe/tasks/web/text/text_classifier/text_classifier_options.d.ts index 51b2b3947..b50767e1a 100644 --- a/mediapipe/tasks/web/text/text_classifier/text_classifier_options.d.ts +++ b/mediapipe/tasks/web/text/text_classifier/text_classifier_options.d.ts @@ -14,4 +14,9 @@ * limitations under the License. */ -export {ClassifierOptions as TextClassifierOptions} from '../../../../tasks/web/core/classifier_options'; +import {ClassifierOptions} from '../../../../tasks/web/core/classifier_options'; +import {TextTaskOptions} from '../../../../tasks/web/text/core/text_task_options'; + +/** Options to configure the MediaPipe Text Classifier Task */ +export declare interface TextClassifierOptions extends ClassifierOptions, + TextTaskOptions {} diff --git a/mediapipe/tasks/web/text/text_embedder/BUILD b/mediapipe/tasks/web/text/text_embedder/BUILD index bebd612dd..17b5eac06 100644 --- a/mediapipe/tasks/web/text/text_embedder/BUILD +++ b/mediapipe/tasks/web/text/text_embedder/BUILD @@ -39,5 +39,6 @@ mediapipe_ts_declaration( "//mediapipe/tasks/web/components/containers:embedding_result", "//mediapipe/tasks/web/core", "//mediapipe/tasks/web/core:embedder_options", + "//mediapipe/tasks/web/text/core:text_task_options", ], ) diff --git a/mediapipe/tasks/web/text/text_embedder/text_embedder_options.d.ts b/mediapipe/tasks/web/text/text_embedder/text_embedder_options.d.ts index 9af263765..9ea570304 100644 --- a/mediapipe/tasks/web/text/text_embedder/text_embedder_options.d.ts +++ b/mediapipe/tasks/web/text/text_embedder/text_embedder_options.d.ts @@ -14,4 +14,9 @@ * limitations under the License. */ -export {EmbedderOptions as TextEmbedderOptions} from '../../../../tasks/web/core/embedder_options'; +import {EmbedderOptions} from '../../../../tasks/web/core/embedder_options'; +import {TextTaskOptions} from '../../../../tasks/web/text/core/text_task_options'; + +/** Options to configure the MediaPipe Text Embedder Task */ +export declare interface TextEmbedderOptions extends EmbedderOptions, + TextTaskOptions {} diff --git a/mediapipe/tasks/web/vision/core/BUILD b/mediapipe/tasks/web/vision/core/BUILD index 8c405ae6e..e3a5edf33 100644 --- a/mediapipe/tasks/web/vision/core/BUILD +++ b/mediapipe/tasks/web/vision/core/BUILD @@ -1,4 +1,4 @@ -# This package contains options shared by all MediaPipe Tasks for Web. +# This package contains options shared by all MediaPipe Vision Tasks for Web. load("//mediapipe/framework/port:build_config.bzl", "mediapipe_ts_declaration", "mediapipe_ts_library") diff --git a/mediapipe/tasks/web/vision/core/vision_task_options.d.ts b/mediapipe/tasks/web/vision/core/vision_task_options.d.ts index 8b9562e46..e04eb6596 100644 --- a/mediapipe/tasks/web/vision/core/vision_task_options.d.ts +++ b/mediapipe/tasks/web/vision/core/vision_task_options.d.ts @@ -17,7 +17,7 @@ import {BaseOptions} from '../../../../tasks/web/core/base_options'; /** - * The two running modes of a video task. + * The two running modes of a vision task. * 1) The image mode for processing single image inputs. * 2) The video mode for processing decoded frames of a video. */ diff --git a/mediapipe/tasks/web/vision/image_classifier/image_classifier_options.d.ts b/mediapipe/tasks/web/vision/image_classifier/image_classifier_options.d.ts index c1141d28f..e99dd2b69 100644 --- a/mediapipe/tasks/web/vision/image_classifier/image_classifier_options.d.ts +++ b/mediapipe/tasks/web/vision/image_classifier/image_classifier_options.d.ts @@ -17,6 +17,6 @@ import {ClassifierOptions} from '../../../../tasks/web/core/classifier_options'; import {VisionTaskOptions} from '../../../../tasks/web/vision/core/vision_task_options'; -/** Ooptions to configure the image classifier task. */ +/** Options to configure the MediaPipe Image Classifier Task. */ export declare interface ImageClassifierOptions extends ClassifierOptions, VisionTaskOptions {} diff --git a/mediapipe/tasks/web/vision/image_embedder/image_embedder_options.d.ts b/mediapipe/tasks/web/vision/image_embedder/image_embedder_options.d.ts index 10000825c..8a04be5e1 100644 --- a/mediapipe/tasks/web/vision/image_embedder/image_embedder_options.d.ts +++ b/mediapipe/tasks/web/vision/image_embedder/image_embedder_options.d.ts @@ -17,6 +17,6 @@ import {EmbedderOptions} from '../../../../tasks/web/core/embedder_options'; import {VisionTaskOptions} from '../../../../tasks/web/vision/core/vision_task_options'; -/** The options for configuring a MediaPipe image embedder task. */ +/** Options for configuring a MediaPipe Image Embedder task. */ export declare interface ImageEmbedderOptions extends EmbedderOptions, VisionTaskOptions {}