From c02737368860667e6cccae959fc2dd2fbcfb7971 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Mon, 14 Nov 2022 15:13:20 -0800 Subject: [PATCH] Internal change PiperOrigin-RevId: 488481286 --- mediapipe/framework/port/build_config.bzl | 39 +++++++++++++++++-- .../tasks/web/components/containers/BUILD | 10 ++--- .../containers/embedding_result.d.ts | 2 +- .../web/components/containers/landmark.d.ts | 2 +- mediapipe/tasks/web/core/BUILD | 16 +++----- .../tasks/web/vision/gesture_recognizer/BUILD | 23 ++++++++--- .../gesture_recognizer/gesture_recognizer.ts | 2 + ...ons.ts => gesture_recognizer_options.d.ts} | 0 ...sult.ts => gesture_recognizer_result.d.ts} | 0 .../tasks/web/vision/hand_landmarker/BUILD | 22 ++++++++--- .../vision/hand_landmarker/hand_landmarker.ts | 2 + ...ptions.ts => hand_landmarker_options.d.ts} | 0 ..._result.ts => hand_landmarker_result.d.ts} | 0 .../tasks/web/vision/image_classifier/BUILD | 22 ++++++++--- .../image_classifier/image_classifier.ts | 2 + ...tions.ts => image_classifier_options.d.ts} | 0 ...result.ts => image_classifier_result.d.ts} | 0 mediapipe/tasks/web/vision/index.ts | 8 ---- .../tasks/web/vision/object_detector/BUILD | 21 +++++++--- .../vision/object_detector/object_detector.ts | 2 + ...ptions.ts => object_detector_options.d.ts} | 0 ..._result.ts => object_detector_result.d.ts} | 0 22 files changed, 121 insertions(+), 52 deletions(-) rename mediapipe/tasks/web/vision/gesture_recognizer/{gesture_recognizer_options.ts => gesture_recognizer_options.d.ts} (100%) rename mediapipe/tasks/web/vision/gesture_recognizer/{gesture_recognizer_result.ts => gesture_recognizer_result.d.ts} (100%) rename mediapipe/tasks/web/vision/hand_landmarker/{hand_landmarker_options.ts => hand_landmarker_options.d.ts} (100%) rename mediapipe/tasks/web/vision/hand_landmarker/{hand_landmarker_result.ts => hand_landmarker_result.d.ts} (100%) rename mediapipe/tasks/web/vision/image_classifier/{image_classifier_options.ts => image_classifier_options.d.ts} (100%) rename mediapipe/tasks/web/vision/image_classifier/{image_classifier_result.ts => image_classifier_result.d.ts} (100%) rename mediapipe/tasks/web/vision/object_detector/{object_detector_options.ts => object_detector_options.d.ts} (100%) rename mediapipe/tasks/web/vision/object_detector/{object_detector_result.ts => object_detector_result.d.ts} (100%) diff --git a/mediapipe/framework/port/build_config.bzl b/mediapipe/framework/port/build_config.bzl index 80e9bfc4..eaabda85 100644 --- a/mediapipe/framework/port/build_config.bzl +++ b/mediapipe/framework/port/build_config.bzl @@ -214,10 +214,10 @@ def mediapipe_ts_library( """Generate ts_project for MediaPipe open source version. Args: - name: the name of the cc_proto_library. - srcs: the .proto files of the cc_proto_library for Bazel use. + name: the name of the mediapipe_ts_library. + srcs: the .ts files of the mediapipe_ts_library for Bazel use. visibility: visibility of this target. - deps: a list of dependency labels for Bazel use; must be cc_proto_library. + deps: a list of dependency labels for Bazel use. testonly: test only or not. allow_unoptimized_namespaces: ignored, used only internally """ @@ -235,3 +235,36 @@ def mediapipe_ts_library( declaration = True, tsconfig = "//:tsconfig.json", )) + +def mediapipe_ts_declaration( + name, + srcs, + visibility = None, + deps = []): + """Generate ts_declaration for MediaPipe open source version. + + Args: + name: the name of the mediapipe_ts_declaration. + srcs: the .d.ts files of the mediapipe_ts_declaration for Bazel use. + visibility: visibility of this target. + deps: a list of dependency labels for Bazel use + """ + + # Bazel does not create JS files for .d.ts files, which leads to import + # failures in our open source build. We simply re-name the .d.ts files + # to .ts to work around this problem. + for src in srcs: + native.genrule( + name = replace_suffix(src, ".d.ts", "_d_ts"), + srcs = [src], + outs = [replace_suffix(src, ".d.ts", ".ts")], + visibility = visibility, + cmd = "cp -n $< $@;", + ) + + mediapipe_ts_library( + name = name, + srcs = [replace_suffix(src, ".d.ts", "_d_ts") for src in srcs], + visibility = visibility, + deps = deps, + ) diff --git a/mediapipe/tasks/web/components/containers/BUILD b/mediapipe/tasks/web/components/containers/BUILD index d1bc480d..fb0fdff1 100644 --- a/mediapipe/tasks/web/components/containers/BUILD +++ b/mediapipe/tasks/web/components/containers/BUILD @@ -1,26 +1,26 @@ # This package contains options shared by all MediaPipe Tasks for Web. -load("//mediapipe/framework/port:build_config.bzl", "mediapipe_ts_library") +load("//mediapipe/framework/port:build_config.bzl", "mediapipe_ts_declaration") package(default_visibility = ["//mediapipe/tasks:internal"]) -mediapipe_ts_library( +mediapipe_ts_declaration( name = "category", srcs = ["category.d.ts"], ) -mediapipe_ts_library( +mediapipe_ts_declaration( name = "classification_result", srcs = ["classification_result.d.ts"], deps = [":category"], ) -mediapipe_ts_library( +mediapipe_ts_declaration( name = "landmark", srcs = ["landmark.d.ts"], ) -mediapipe_ts_library( +mediapipe_ts_declaration( name = "embedding_result", srcs = ["embedding_result.d.ts"], ) diff --git a/mediapipe/tasks/web/components/containers/embedding_result.d.ts b/mediapipe/tasks/web/components/containers/embedding_result.d.ts index e1efd94c..3779abd9 100644 --- a/mediapipe/tasks/web/components/containers/embedding_result.d.ts +++ b/mediapipe/tasks/web/components/containers/embedding_result.d.ts @@ -21,7 +21,7 @@ * contain data, based on whether or not the embedder was configured to perform * scalar quantization. */ -export interface Embedding { +export declare interface Embedding { /** * Floating-point embedding. Empty if the embedder was configured to perform * scalar-quantization. diff --git a/mediapipe/tasks/web/components/containers/landmark.d.ts b/mediapipe/tasks/web/components/containers/landmark.d.ts index f790d8a0..c887303d 100644 --- a/mediapipe/tasks/web/components/containers/landmark.d.ts +++ b/mediapipe/tasks/web/components/containers/landmark.d.ts @@ -20,7 +20,7 @@ * dimension of image, and the coordinates values are in the range of [0,1]. * Otherwise, it represenet a point in world coordinates. */ -export declare class Landmark { +export declare interface Landmark { /** The x coordinates of the landmark. */ x: number; diff --git a/mediapipe/tasks/web/core/BUILD b/mediapipe/tasks/web/core/BUILD index edfc1e5c..e9ef85d4 100644 --- a/mediapipe/tasks/web/core/BUILD +++ b/mediapipe/tasks/web/core/BUILD @@ -1,10 +1,10 @@ # This package contains options shared by all MediaPipe Tasks for Web. -load("//mediapipe/framework/port:build_config.bzl", "mediapipe_ts_library") +load("//mediapipe/framework/port:build_config.bzl", "mediapipe_ts_declaration", "mediapipe_ts_library") package(default_visibility = ["//mediapipe/tasks:internal"]) -mediapipe_ts_library( +mediapipe_ts_declaration( name = "core", srcs = [ "base_options.d.ts", @@ -24,18 +24,14 @@ mediapipe_ts_library( ], ) -mediapipe_ts_library( +mediapipe_ts_declaration( name = "classifier_options", - srcs = [ - "classifier_options.d.ts", - ], + srcs = ["classifier_options.d.ts"], deps = [":core"], ) -mediapipe_ts_library( +mediapipe_ts_declaration( name = "embedder_options", - srcs = [ - "embedder_options.d.ts", - ], + srcs = ["embedder_options.d.ts"], deps = [":core"], ) diff --git a/mediapipe/tasks/web/vision/gesture_recognizer/BUILD b/mediapipe/tasks/web/vision/gesture_recognizer/BUILD index 6b99f6ce..d67974a1 100644 --- a/mediapipe/tasks/web/vision/gesture_recognizer/BUILD +++ b/mediapipe/tasks/web/vision/gesture_recognizer/BUILD @@ -3,7 +3,7 @@ # This task takes video frames and outputs synchronized frames along with # the detection results for one or more gesture categories, using Gesture Recognizer. -load("//mediapipe/framework/port:build_config.bzl", "mediapipe_ts_library") +load("//mediapipe/framework/port:build_config.bzl", "mediapipe_ts_declaration", "mediapipe_ts_library") package(default_visibility = ["//mediapipe/tasks:internal"]) @@ -11,12 +11,9 @@ licenses(["notice"]) mediapipe_ts_library( name = "gesture_recognizer", - srcs = [ - "gesture_recognizer.ts", - "gesture_recognizer_options.ts", - "gesture_recognizer_result.ts", - ], + srcs = ["gesture_recognizer.ts"], deps = [ + ":gesture_recognizer_types", "//mediapipe/framework:calculator_jspb_proto", "//mediapipe/framework:calculator_options_jspb_proto", "//mediapipe/framework/formats:classification_jspb_proto", @@ -38,3 +35,17 @@ mediapipe_ts_library( "//mediapipe/web/graph_runner:wasm_mediapipe_lib_ts", ], ) + +mediapipe_ts_declaration( + name = "gesture_recognizer_types", + srcs = [ + "gesture_recognizer_options.d.ts", + "gesture_recognizer_result.d.ts", + ], + deps = [ + "//mediapipe/tasks/web/components/containers:category", + "//mediapipe/tasks/web/components/containers:landmark", + "//mediapipe/tasks/web/core", + "//mediapipe/tasks/web/core:classifier_options", + ], +) diff --git a/mediapipe/tasks/web/vision/gesture_recognizer/gesture_recognizer.ts b/mediapipe/tasks/web/vision/gesture_recognizer/gesture_recognizer.ts index c24d1a7b..6c8072ff 100644 --- a/mediapipe/tasks/web/vision/gesture_recognizer/gesture_recognizer.ts +++ b/mediapipe/tasks/web/vision/gesture_recognizer/gesture_recognizer.ts @@ -37,6 +37,8 @@ import {createMediaPipeLib, FileLocator, ImageSource, WasmModule} from '../../.. import {GestureRecognizerOptions} from './gesture_recognizer_options'; import {GestureRecognizerResult} from './gesture_recognizer_result'; +export * from './gesture_recognizer_options'; +export * from './gesture_recognizer_result'; export {ImageSource}; // The OSS JS API does not support the builder pattern. diff --git a/mediapipe/tasks/web/vision/gesture_recognizer/gesture_recognizer_options.ts b/mediapipe/tasks/web/vision/gesture_recognizer/gesture_recognizer_options.d.ts similarity index 100% rename from mediapipe/tasks/web/vision/gesture_recognizer/gesture_recognizer_options.ts rename to mediapipe/tasks/web/vision/gesture_recognizer/gesture_recognizer_options.d.ts diff --git a/mediapipe/tasks/web/vision/gesture_recognizer/gesture_recognizer_result.ts b/mediapipe/tasks/web/vision/gesture_recognizer/gesture_recognizer_result.d.ts similarity index 100% rename from mediapipe/tasks/web/vision/gesture_recognizer/gesture_recognizer_result.ts rename to mediapipe/tasks/web/vision/gesture_recognizer/gesture_recognizer_result.d.ts diff --git a/mediapipe/tasks/web/vision/hand_landmarker/BUILD b/mediapipe/tasks/web/vision/hand_landmarker/BUILD index 9006b54e..25c70e0a 100644 --- a/mediapipe/tasks/web/vision/hand_landmarker/BUILD +++ b/mediapipe/tasks/web/vision/hand_landmarker/BUILD @@ -3,7 +3,7 @@ # This task takes video frames and outputs synchronized frames along with # the detection results for one or more hand categories, using Hand Landmarker. -load("//mediapipe/framework/port:build_config.bzl", "mediapipe_ts_library") +load("//mediapipe/framework/port:build_config.bzl", "mediapipe_ts_declaration", "mediapipe_ts_library") package(default_visibility = ["//mediapipe/tasks:internal"]) @@ -11,12 +11,9 @@ licenses(["notice"]) mediapipe_ts_library( name = "hand_landmarker", - srcs = [ - "hand_landmarker.ts", - "hand_landmarker_options.ts", - "hand_landmarker_result.ts", - ], + srcs = ["hand_landmarker.ts"], deps = [ + ":hand_landmarker_types", "//mediapipe/framework:calculator_jspb_proto", "//mediapipe/framework:calculator_options_jspb_proto", "//mediapipe/framework/formats:classification_jspb_proto", @@ -33,3 +30,16 @@ mediapipe_ts_library( "//mediapipe/web/graph_runner:wasm_mediapipe_lib_ts", ], ) + +mediapipe_ts_declaration( + name = "hand_landmarker_types", + srcs = [ + "hand_landmarker_options.d.ts", + "hand_landmarker_result.d.ts", + ], + deps = [ + "//mediapipe/tasks/web/components/containers:category", + "//mediapipe/tasks/web/components/containers:landmark", + "//mediapipe/tasks/web/core", + ], +) diff --git a/mediapipe/tasks/web/vision/hand_landmarker/hand_landmarker.ts b/mediapipe/tasks/web/vision/hand_landmarker/hand_landmarker.ts index 017a9098..af10305b 100644 --- a/mediapipe/tasks/web/vision/hand_landmarker/hand_landmarker.ts +++ b/mediapipe/tasks/web/vision/hand_landmarker/hand_landmarker.ts @@ -33,6 +33,8 @@ import {createMediaPipeLib, FileLocator, ImageSource, WasmModule} from '../../.. import {HandLandmarkerOptions} from './hand_landmarker_options'; import {HandLandmarkerResult} from './hand_landmarker_result'; +export * from './hand_landmarker_options'; +export * from './hand_landmarker_result'; export {ImageSource}; // The OSS JS API does not support the builder pattern. diff --git a/mediapipe/tasks/web/vision/hand_landmarker/hand_landmarker_options.ts b/mediapipe/tasks/web/vision/hand_landmarker/hand_landmarker_options.d.ts similarity index 100% rename from mediapipe/tasks/web/vision/hand_landmarker/hand_landmarker_options.ts rename to mediapipe/tasks/web/vision/hand_landmarker/hand_landmarker_options.d.ts diff --git a/mediapipe/tasks/web/vision/hand_landmarker/hand_landmarker_result.ts b/mediapipe/tasks/web/vision/hand_landmarker/hand_landmarker_result.d.ts similarity index 100% rename from mediapipe/tasks/web/vision/hand_landmarker/hand_landmarker_result.ts rename to mediapipe/tasks/web/vision/hand_landmarker/hand_landmarker_result.d.ts diff --git a/mediapipe/tasks/web/vision/image_classifier/BUILD b/mediapipe/tasks/web/vision/image_classifier/BUILD index e96d6a8e..8506f357 100644 --- a/mediapipe/tasks/web/vision/image_classifier/BUILD +++ b/mediapipe/tasks/web/vision/image_classifier/BUILD @@ -2,7 +2,7 @@ # # This task takes video or image frames and outputs the classification result. -load("//mediapipe/framework/port:build_config.bzl", "mediapipe_ts_library") +load("//mediapipe/framework/port:build_config.bzl", "mediapipe_ts_declaration", "mediapipe_ts_library") package(default_visibility = ["//mediapipe/tasks:internal"]) @@ -10,12 +10,9 @@ licenses(["notice"]) mediapipe_ts_library( name = "image_classifier", - srcs = [ - "image_classifier.ts", - "image_classifier_options.ts", - "image_classifier_result.ts", - ], + srcs = ["image_classifier.ts"], deps = [ + ":image_classifier_types", "//mediapipe/framework:calculator_jspb_proto", "//mediapipe/framework:calculator_options_jspb_proto", "//mediapipe/tasks/cc/components/containers/proto:classifications_jspb_proto", @@ -31,3 +28,16 @@ mediapipe_ts_library( "//mediapipe/web/graph_runner:wasm_mediapipe_lib_ts", ], ) + +mediapipe_ts_declaration( + name = "image_classifier_types", + srcs = [ + "image_classifier_options.d.ts", + "image_classifier_result.d.ts", + ], + deps = [ + "//mediapipe/tasks/web/components/containers:category", + "//mediapipe/tasks/web/components/containers:classification_result", + "//mediapipe/tasks/web/core:classifier_options", + ], +) diff --git a/mediapipe/tasks/web/vision/image_classifier/image_classifier.ts b/mediapipe/tasks/web/vision/image_classifier/image_classifier.ts index ba4b6c90..5d60e4a2 100644 --- a/mediapipe/tasks/web/vision/image_classifier/image_classifier.ts +++ b/mediapipe/tasks/web/vision/image_classifier/image_classifier.ts @@ -34,6 +34,8 @@ const IMAGE_CLASSIFIER_GRAPH = const INPUT_STREAM = 'input_image'; const CLASSIFICATIONS_STREAM = 'classifications'; +export * from './image_classifier_options'; +export * from './image_classifier_result'; export {ImageSource}; // Used in the public API // The OSS JS API does not support the builder pattern. diff --git a/mediapipe/tasks/web/vision/image_classifier/image_classifier_options.ts b/mediapipe/tasks/web/vision/image_classifier/image_classifier_options.d.ts similarity index 100% rename from mediapipe/tasks/web/vision/image_classifier/image_classifier_options.ts rename to mediapipe/tasks/web/vision/image_classifier/image_classifier_options.d.ts diff --git a/mediapipe/tasks/web/vision/image_classifier/image_classifier_result.ts b/mediapipe/tasks/web/vision/image_classifier/image_classifier_result.d.ts similarity index 100% rename from mediapipe/tasks/web/vision/image_classifier/image_classifier_result.ts rename to mediapipe/tasks/web/vision/image_classifier/image_classifier_result.d.ts diff --git a/mediapipe/tasks/web/vision/index.ts b/mediapipe/tasks/web/vision/index.ts index 6dda83e5..0ea844fc 100644 --- a/mediapipe/tasks/web/vision/index.ts +++ b/mediapipe/tasks/web/vision/index.ts @@ -15,8 +15,6 @@ */ // Image Classifier -export * from '../../../tasks/web/vision/image_classifier/image_classifier_options'; -export * from '../../../tasks/web/vision/image_classifier/image_classifier_result'; export * from '../../../tasks/web/vision/image_classifier/image_classifier'; // Image Embedder @@ -25,16 +23,10 @@ export * from '../../../tasks/web/vision/image_embedder/image_embedder_result'; export * from '../../../tasks/web/vision/image_embedder/image_embedder'; // Gesture Recognizer -export * from '../../../tasks/web/vision/gesture_recognizer/gesture_recognizer_options'; -export * from '../../../tasks/web/vision/gesture_recognizer/gesture_recognizer_result'; export * from '../../../tasks/web/vision/gesture_recognizer/gesture_recognizer'; // Hand Landmarker -export * from '../../../tasks/web/vision/hand_landmarker/hand_landmarker_options'; -export * from '../../../tasks/web/vision/hand_landmarker/hand_landmarker_result'; export * from '../../../tasks/web/vision/hand_landmarker/hand_landmarker'; // Object Detector -export * from '../../../tasks/web/vision/object_detector/object_detector_options'; -export * from '../../../tasks/web/vision/object_detector/object_detector_result'; export * from '../../../tasks/web/vision/object_detector/object_detector'; diff --git a/mediapipe/tasks/web/vision/object_detector/BUILD b/mediapipe/tasks/web/vision/object_detector/BUILD index 095a84b5..a74dc921 100644 --- a/mediapipe/tasks/web/vision/object_detector/BUILD +++ b/mediapipe/tasks/web/vision/object_detector/BUILD @@ -3,7 +3,7 @@ # This task takes video frames and outputs synchronized frames along with # the detection results for one or more object categories, using Object Detector. -load("//mediapipe/framework/port:build_config.bzl", "mediapipe_ts_library") +load("//mediapipe/framework/port:build_config.bzl", "mediapipe_ts_declaration", "mediapipe_ts_library") package(default_visibility = ["//mediapipe/tasks:internal"]) @@ -11,12 +11,9 @@ licenses(["notice"]) mediapipe_ts_library( name = "object_detector", - srcs = [ - "object_detector.ts", - "object_detector_options.ts", - "object_detector_result.ts", - ], + srcs = ["object_detector.ts"], deps = [ + ":object_detector_types", "//mediapipe/framework:calculator_jspb_proto", "//mediapipe/framework:calculator_options_jspb_proto", "//mediapipe/framework/formats:detection_jspb_proto", @@ -28,3 +25,15 @@ mediapipe_ts_library( "//mediapipe/web/graph_runner:wasm_mediapipe_lib_ts", ], ) + +mediapipe_ts_declaration( + name = "object_detector_types", + srcs = [ + "object_detector_options.d.ts", + "object_detector_result.d.ts", + ], + deps = [ + "//mediapipe/tasks/web/components/containers:category", + "//mediapipe/tasks/web/core", + ], +) diff --git a/mediapipe/tasks/web/vision/object_detector/object_detector.ts b/mediapipe/tasks/web/vision/object_detector/object_detector.ts index 022bf630..e17a4202 100644 --- a/mediapipe/tasks/web/vision/object_detector/object_detector.ts +++ b/mediapipe/tasks/web/vision/object_detector/object_detector.ts @@ -33,6 +33,8 @@ const OBJECT_DETECTOR_GRAPH = 'mediapipe.tasks.vision.ObjectDetectorGraph'; const DEFAULT_CATEGORY_INDEX = -1; +export * from './object_detector_options'; +export * from './object_detector_result'; export {ImageSource}; // Used in the public API // The OSS JS API does not support the builder pattern. diff --git a/mediapipe/tasks/web/vision/object_detector/object_detector_options.ts b/mediapipe/tasks/web/vision/object_detector/object_detector_options.d.ts similarity index 100% rename from mediapipe/tasks/web/vision/object_detector/object_detector_options.ts rename to mediapipe/tasks/web/vision/object_detector/object_detector_options.d.ts diff --git a/mediapipe/tasks/web/vision/object_detector/object_detector_result.ts b/mediapipe/tasks/web/vision/object_detector/object_detector_result.d.ts similarity index 100% rename from mediapipe/tasks/web/vision/object_detector/object_detector_result.ts rename to mediapipe/tasks/web/vision/object_detector/object_detector_result.d.ts