diff --git a/.bazelrc b/.bazelrc index 37a0bc1142..73e15b32ba 100644 --- a/.bazelrc +++ b/.bazelrc @@ -58,6 +58,7 @@ build:android_arm64 --fat_apk_cpu=arm64-v8a # iOS configs. build:ios --apple_platform_type=ios +build:ios --copt=-fno-aligned-allocation build:ios_i386 --config=ios build:ios_i386 --cpu=ios_i386 diff --git a/.bazelversion b/.bazelversion index 0b2eb36f50..fae6e3d04b 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -3.7.2 +4.2.1 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d7a1e18772..df7772a91f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,7 +5,7 @@ * Bug fixes * Documentation fixes -For new feature additions (e.g., new graphs and calculators), we are currently not planning to accept new feature pull requests into the MediaPipe repository. Instead, we like to get contributors to create their own repositories of the new feature and list it at [Awesome MediaPipe](https://mediapipe.org). This will allow contributors to more quickly get their code out to the community. +For new feature additions (e.g., new graphs and calculators), we are currently not planning to accept new feature pull requests into the MediaPipe repository. Instead, we like to get contributors to create their own repositories of the new feature and list it at [Awesome MediaPipe](https://mediapipe.page.link/awesome-mediapipe). This will allow contributors to more quickly get their code out to the community. Before sending your pull requests, make sure you followed this list. diff --git a/Dockerfile b/Dockerfile index c4c4df3e48..79f08cc922 100644 --- a/Dockerfile +++ b/Dockerfile @@ -56,7 +56,7 @@ RUN pip3 install tf_slim RUN ln -s /usr/bin/python3 /usr/bin/python # Install bazel -ARG BAZEL_VERSION=3.7.2 +ARG BAZEL_VERSION=4.2.1 RUN mkdir /bazel && \ wget --no-check-certificate -O /bazel/installer.sh "https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/b\ azel-${BAZEL_VERSION}-installer-linux-x86_64.sh" && \ diff --git a/WORKSPACE b/WORKSPACE index c2aaca658a..633169032f 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -122,16 +122,16 @@ http_archive( # ...but the Java download is currently broken, so we use the "source" download. http_archive( name = "com_google_protobuf_javalite", - sha256 = "a79d19dcdf9139fa4b81206e318e33d245c4c9da1ffed21c87288ed4380426f9", - strip_prefix = "protobuf-3.11.4", - urls = ["https://github.com/protocolbuffers/protobuf/archive/v3.11.4.tar.gz"], + sha256 = "87407cd28e7a9c95d9f61a098a53cf031109d451a7763e7dd1253abf8b4df422", + strip_prefix = "protobuf-3.19.1", + urls = ["https://github.com/protocolbuffers/protobuf/archive/v3.19.1.tar.gz"], ) http_archive( name = "com_google_protobuf", - sha256 = "a79d19dcdf9139fa4b81206e318e33d245c4c9da1ffed21c87288ed4380426f9", - strip_prefix = "protobuf-3.11.4", - urls = ["https://github.com/protocolbuffers/protobuf/archive/v3.11.4.tar.gz"], + sha256 = "87407cd28e7a9c95d9f61a098a53cf031109d451a7763e7dd1253abf8b4df422", + strip_prefix = "protobuf-3.19.1", + urls = ["https://github.com/protocolbuffers/protobuf/archive/v3.19.1.tar.gz"], patches = [ "@//third_party:com_google_protobuf_fixes.diff" ], @@ -154,28 +154,29 @@ http_archive( sha256 = "75922da3a1bdb417d820398eb03d4e9bd067c4905a4246d35a44c01d62154d91", ) +# Point to the commit that deprecates the usage of Eigen::MappedSparseMatrix. http_archive( name = "pybind11", urls = [ - "https://storage.googleapis.com/mirror.tensorflow.org/github.com/pybind/pybind11/archive/v2.7.1.tar.gz", - "https://github.com/pybind/pybind11/archive/v2.7.1.tar.gz", + "https://github.com/pybind/pybind11/archive/70a58c577eaf067748c2ec31bfd0b0a614cffba6.zip", ], - sha256 = "616d1c42e4cf14fa27b2a4ff759d7d7b33006fdc5ad8fd603bb2c22622f27020", - strip_prefix = "pybind11-2.7.1", + sha256 = "b971842fab1b5b8f3815a2302331782b7d137fef0e06502422bc4bc360f4956c", + strip_prefix = "pybind11-70a58c577eaf067748c2ec31bfd0b0a614cffba6", build_file = "@pybind11_bazel//:pybind11.BUILD", ) +# Point to the commit that deprecates the usage of Eigen::MappedSparseMatrix. http_archive( name = "ceres_solver", - url = "https://github.com/ceres-solver/ceres-solver/archive/2.0.0.zip", + url = "https://github.com/ceres-solver/ceres-solver/archive/123fba61cf2611a3c8bddc9d91416db26b10b558.zip", patches = [ "@//third_party:ceres_solver_compatibility_fixes.diff" ], patch_args = [ "-p1", ], - strip_prefix = "ceres-solver-2.0.0", - sha256 = "db12d37b4cebb26353ae5b7746c7985e00877baa8e7b12dc4d3a1512252fff3b" + strip_prefix = "ceres-solver-123fba61cf2611a3c8bddc9d91416db26b10b558", + sha256 = "8b7b16ceb363420e0fd499576daf73fa338adb0b1449f58bea7862766baa1ac7" ) http_archive( @@ -249,21 +250,12 @@ http_archive( ], ) -# You may run setup_android.sh to install Android SDK and NDK. -android_ndk_repository( - name = "androidndk", -) - -android_sdk_repository( - name = "androidsdk", -) - # iOS basic build deps. http_archive( name = "build_bazel_rules_apple", - sha256 = "7a7afdd4869bb201c9352eed2daf37294d42b093579b70423490c1b4d4f6ce42", - url = "https://github.com/bazelbuild/rules_apple/releases/download/0.19.0/rules_apple.0.19.0.tar.gz", + sha256 = "77e8bf6fda706f420a55874ae6ee4df0c9d95da6c7838228b26910fc82eea5a2", + url = "https://github.com/bazelbuild/rules_apple/releases/download/0.32.0/rules_apple.0.32.0.tar.gz", patches = [ # Bypass checking ios unit test runner when building MP ios applications. "@//third_party:build_bazel_rules_apple_bypass_test_runner_check.diff" @@ -289,10 +281,9 @@ swift_rules_dependencies() http_archive( name = "build_bazel_apple_support", - sha256 = "122ebf7fe7d1c8e938af6aeaee0efe788a3a2449ece5a8d6a428cb18d6f88033", + sha256 = "741366f79d900c11e11d8efd6cc6c66a31bfb2451178b58e0b5edc6f1db17b35", urls = [ - "https://storage.googleapis.com/mirror.tensorflow.org/github.com/bazelbuild/apple_support/releases/download/0.7.1/apple_support.0.7.1.tar.gz", - "https://github.com/bazelbuild/apple_support/releases/download/0.7.1/apple_support.0.7.1.tar.gz", + "https://github.com/bazelbuild/apple_support/releases/download/0.10.0/apple_support.0.10.0.tar.gz" ], ) @@ -382,9 +373,9 @@ http_archive( ) # Tensorflow repo should always go after the other external dependencies. -# 2021-07-29 -_TENSORFLOW_GIT_COMMIT = "52a2905cbc21034766c08041933053178c5d10e3" -_TENSORFLOW_SHA256 = "06d4691bcdb700f3275fa0971a1585221c2b9f3dffe867963be565a6643d7f56" +# 2021-12-02 +_TENSORFLOW_GIT_COMMIT = "18a1dc0ba806dc023808531f0373d9ec068e64bf" +_TENSORFLOW_SHA256 = "85b90416f7a11339327777bccd634de00ca0de2cf334f5f0727edcb11ff9289a" http_archive( name = "org_tensorflow", urls = [ diff --git a/docs/getting_started/android.md b/docs/getting_started/android.md index c3c6506eea..73e7306794 100644 --- a/docs/getting_started/android.md +++ b/docs/getting_started/android.md @@ -29,8 +29,8 @@ APIs (currently in alpha) that are now available in * Install MediaPipe following these [instructions](./install.md). * Setup Java Runtime. -* Setup Android SDK release 28.0.3 and above. -* Setup Android NDK version between 18 and 21. +* Setup Android SDK release 30.0.0 and above. +* Setup Android NDK version 18 and above. MediaPipe recommends setting up Android SDK and NDK via Android Studio (and see below for Android Studio setup). However, if you prefer using MediaPipe without @@ -47,6 +47,15 @@ export ANDROID_HOME= export ANDROID_NDK_HOME= ``` +and add android_ndk_repository() and android_sdk_repository() rules into the +[`WORKSPACE`](https://github.com/google/mediapipe/blob/master/WORKSPACE) file as +the following: + +```bash +$ echo "android_sdk_repository(name = \"androidsdk\")" >> WORKSPACE +$ echo "android_ndk_repository(name = \"androidndk\")" >> WORKSPACE +``` + In order to use MediaPipe on earlier Android versions, MediaPipe needs to switch to a lower Android API level. You can achieve this by specifying `api_level = $YOUR_INTENDED_API_LEVEL` in android_ndk_repository() and/or diff --git a/docs/getting_started/android_archive_library.md b/docs/getting_started/android_archive_library.md index d2f25213fc..4c526527ca 100644 --- a/docs/getting_started/android_archive_library.md +++ b/docs/getting_started/android_archive_library.md @@ -117,7 +117,7 @@ each project. implementation 'com.google.flogger:flogger-system-backend:latest.release' implementation 'com.google.code.findbugs:jsr305:latest.release' implementation 'com.google.guava:guava:27.0.1-android' - implementation 'com.google.protobuf:protobuf-java:3.11.4' + implementation 'com.google.protobuf:protobuf-javalite:3.19.1' // CameraX core library def camerax_version = "1.0.0-beta10" implementation "androidx.camera:camera-core:$camerax_version" diff --git a/docs/getting_started/install.md b/docs/getting_started/install.md index bb2539d338..430287aebc 100644 --- a/docs/getting_started/install.md +++ b/docs/getting_started/install.md @@ -569,7 +569,7 @@ next section. Option 1. Follow [the official Bazel documentation](https://docs.bazel.build/versions/master/install-windows.html) - to install Bazel 3.7.2 or higher. + to install Bazel 4.2.1 or higher. Option 2. Follow the official [Bazel documentation](https://docs.bazel.build/versions/master/install-bazelisk.html) @@ -657,7 +657,7 @@ cameras. Alternatively, you use a video file as input. Note: Windows' and WSL’s adb versions must be the same version, e.g., if WSL has ADB 1.0.39, you need to download the corresponding Windows ADB from - [here](https://dl.google.com/android/repository/platform-tools_r26.0.1-windows.zip). + [here](https://dl.google.com/android/repository/platform-tools_r30.0.3-windows.zip). 3. Launch WSL. @@ -796,7 +796,7 @@ This will use a Docker image that will isolate mediapipe's installation from the ```bash $ docker run -it --name mediapipe mediapipe:latest - root@bca08b91ff63:/mediapipe# GLOG_logtostderr=1 bazelisk run --define MEDIAPIPE_DISABLE_GPU=1 mediapipe/examples/desktop/hello_world:hello_world + root@bca08b91ff63:/mediapipe# GLOG_logtostderr=1 bazel run --define MEDIAPIPE_DISABLE_GPU=1 mediapipe/examples/desktop/hello_world # Should print: # Hello World! diff --git a/docs/getting_started/python_framework.md b/docs/getting_started/python_framework.md index 688285d872..d80db5ab94 100644 --- a/docs/getting_started/python_framework.md +++ b/docs/getting_started/python_framework.md @@ -249,12 +249,12 @@ three stages: initialization and setup, graph run, and graph shutdown. graph.start_run() graph.add_packet_to_input_stream( - 'in_stream', mp.packet_creator.create_str('abc').at(0)) + 'in_stream', mp.packet_creator.create_string('abc').at(0)) rgb_img = cv2.cvtColor(cv2.imread('/path/to/your/image.png'), cv2.COLOR_BGR2RGB) graph.add_packet_to_input_stream( 'in_stream', - mp.packet_creator.create_image_frame(format=mp.ImageFormat.SRGB, + mp.packet_creator.create_image_frame(image_format=mp.ImageFormat.SRGB, data=rgb_img).at(1)) ``` diff --git a/docs/getting_started/troubleshooting.md b/docs/getting_started/troubleshooting.md index 7cb87d524a..a4f347aaae 100644 --- a/docs/getting_started/troubleshooting.md +++ b/docs/getting_started/troubleshooting.md @@ -108,14 +108,14 @@ ERROR: No matching distribution found for mediapipe after running `pip install mediapipe` usually indicates that there is no qualified MediaPipe Python for your system. Please note that MediaPipe Python PyPI officially supports the **64-bit** -version of Python 3.7 and above on the following OS: +version of Python 3.7 to 3.10 on the following OS: - x86_64 Linux - x86_64 macOS 10.15+ - amd64 Windows If the OS is currently supported and you still see this error, please make sure -that both the Python and pip binary are for Python 3.7 and above. Otherwise, +that both the Python and pip binary are for Python 3.7 to 3.10. Otherwise, please consider building the MediaPipe Python package locally by following the instructions [here](python.md#building-mediapipe-python-package). diff --git a/docs/solutions/hands.md b/docs/solutions/hands.md index e8a75ee162..d73e325987 100644 --- a/docs/solutions/hands.md +++ b/docs/solutions/hands.md @@ -200,13 +200,9 @@ magnitude of `z` uses roughly the same scale as `x`. #### multi_hand_world_landmarks Collection of detected/tracked hands, where each hand is represented as a list -of 21 hand landmarks in world coordinates. Each landmark consists of the -following: - -* `x`, `y` and `z`: Real-world 3D coordinates in meters with the origin at the - hand's approximate geometric center. -* `visibility`: Identical to that defined in the corresponding - [multi_hand_landmarks](#multi_hand_landmarks). +of 21 hand landmarks in world coordinates. Each landmark is composed of `x`, `y` +and `z`: real-world 3D coordinates in meters with the origin at the hand's +approximate geometric center. #### multi_handedness diff --git a/mediapipe/calculators/core/BUILD b/mediapipe/calculators/core/BUILD index 43979d93e7..61d907dab2 100644 --- a/mediapipe/calculators/core/BUILD +++ b/mediapipe/calculators/core/BUILD @@ -1242,7 +1242,6 @@ cc_test( "//mediapipe/framework:calculator_profile_cc_proto", "//mediapipe/framework:test_calculators", "//mediapipe/framework/deps:clock", - "//mediapipe/framework/deps:message_matchers", "//mediapipe/framework/port:core_proto", "//mediapipe/framework/port:gtest_main", "//mediapipe/framework/port:integral_types", diff --git a/mediapipe/calculators/core/graph_profile_calculator_test.cc b/mediapipe/calculators/core/graph_profile_calculator_test.cc index 8a7845b190..5d8f174040 100644 --- a/mediapipe/calculators/core/graph_profile_calculator_test.cc +++ b/mediapipe/calculators/core/graph_profile_calculator_test.cc @@ -23,7 +23,6 @@ #include "mediapipe/framework/calculator_framework.h" #include "mediapipe/framework/calculator_profile.pb.h" #include "mediapipe/framework/deps/clock.h" -#include "mediapipe/framework/deps/message_matchers.h" #include "mediapipe/framework/port/gmock.h" #include "mediapipe/framework/port/gtest.h" #include "mediapipe/framework/port/integral_types.h" diff --git a/mediapipe/calculators/image/image_transformation_calculator.cc b/mediapipe/calculators/image/image_transformation_calculator.cc index 76cc845e28..f017eba797 100644 --- a/mediapipe/calculators/image/image_transformation_calculator.cc +++ b/mediapipe/calculators/image/image_transformation_calculator.cc @@ -45,6 +45,9 @@ namespace mediapipe { #if !MEDIAPIPE_DISABLE_GPU #endif // !MEDIAPIPE_DISABLE_GPU +#if defined(MEDIAPIPE_IOS) + +#endif // defined(MEDIAPIPE_IOS) namespace { constexpr char kImageFrameTag[] = "IMAGE"; diff --git a/mediapipe/calculators/tensor/inference_calculator_test.cc b/mediapipe/calculators/tensor/inference_calculator_test.cc index 882a5e81e8..1cff995a3e 100644 --- a/mediapipe/calculators/tensor/inference_calculator_test.cc +++ b/mediapipe/calculators/tensor/inference_calculator_test.cc @@ -39,8 +39,6 @@ namespace mediapipe { -using ::tflite::Interpreter; - void DoSmokeTest(const std::string& graph_proto) { const int width = 8; const int height = 8; diff --git a/mediapipe/calculators/tensorflow/matrix_to_tensor_calculator_test.cc b/mediapipe/calculators/tensorflow/matrix_to_tensor_calculator_test.cc index c3c6ef5f89..3379f86b99 100644 --- a/mediapipe/calculators/tensorflow/matrix_to_tensor_calculator_test.cc +++ b/mediapipe/calculators/tensorflow/matrix_to_tensor_calculator_test.cc @@ -26,7 +26,6 @@ #include "tensorflow/core/framework/types.h" namespace mediapipe { - namespace { constexpr char kTransposeOptionsString[] = diff --git a/mediapipe/calculators/util/BUILD b/mediapipe/calculators/util/BUILD index 6bd6cfe915..0c1a3ce3c5 100644 --- a/mediapipe/calculators/util/BUILD +++ b/mediapipe/calculators/util/BUILD @@ -176,7 +176,6 @@ cc_test( ":filter_detections_calculator", "//mediapipe/framework:calculator_framework", "//mediapipe/framework:calculator_runner", - "//mediapipe/framework/deps:message_matchers", "//mediapipe/framework/formats:detection_cc_proto", "//mediapipe/framework/port:gtest_main", "//mediapipe/framework/port:parse_text_proto", @@ -215,7 +214,6 @@ cc_test( "//mediapipe/framework:calculator_runner", "//mediapipe/framework:timestamp", "//mediapipe/framework/deps:clock", - "//mediapipe/framework/deps:message_matchers", "//mediapipe/framework/port:gtest_main", "//mediapipe/framework/port:parse_text_proto", "//mediapipe/framework/stream_handler:immediate_input_stream_handler", @@ -488,7 +486,6 @@ cc_test( "//mediapipe/framework:calculator_framework", "//mediapipe/framework:calculator_runner", "//mediapipe/framework:packet", - "//mediapipe/framework/deps:message_matchers", "//mediapipe/framework/formats:detection_cc_proto", "//mediapipe/framework/formats:location_data_cc_proto", "//mediapipe/framework/formats:rect_cc_proto", @@ -772,7 +769,6 @@ cc_test( "//mediapipe/framework:calculator_framework", "//mediapipe/framework:calculator_runner", "//mediapipe/framework:packet", - "//mediapipe/framework/deps:message_matchers", "//mediapipe/framework/formats:detection_cc_proto", "//mediapipe/framework/formats:location_data_cc_proto", "//mediapipe/framework/port:gtest_main", @@ -869,7 +865,6 @@ cc_test( "//mediapipe/framework:calculator_cc_proto", "//mediapipe/framework:calculator_framework", "//mediapipe/framework:calculator_runner", - "//mediapipe/framework/deps:message_matchers", "//mediapipe/framework/formats:landmark_cc_proto", "//mediapipe/framework/formats:rect_cc_proto", "//mediapipe/framework/port:gtest_main", @@ -1067,7 +1062,6 @@ cc_test( "//mediapipe/framework:calculator_framework", "//mediapipe/framework:calculator_runner", "//mediapipe/framework:packet", - "//mediapipe/framework/deps:message_matchers", "//mediapipe/framework/port:gtest_main", "//mediapipe/framework/port:parse_text_proto", "//mediapipe/framework/port:status", @@ -1217,7 +1211,6 @@ cc_test( "//mediapipe/framework:calculator_runner", "//mediapipe/framework:collection_item_id", "//mediapipe/framework:packet", - "//mediapipe/framework/deps:message_matchers", "//mediapipe/framework/formats:detection_cc_proto", "//mediapipe/framework/formats:location_data_cc_proto", "//mediapipe/framework/formats:rect_cc_proto", @@ -1285,6 +1278,7 @@ cc_library( "//mediapipe/framework:calculator_options_cc_proto", "//mediapipe/framework/formats:image_format_cc_proto", "//mediapipe/framework:calculator_framework", + "//mediapipe/framework/api2:node", "//mediapipe/framework/formats:image_frame", "//mediapipe/framework/formats:image", "//mediapipe/framework/port:logging", @@ -1344,7 +1338,6 @@ cc_test( ":detection_classifications_merger_calculator", "//mediapipe/framework:calculator_framework", "//mediapipe/framework:calculator_runner", - "//mediapipe/framework/deps:message_matchers", "//mediapipe/framework/formats:classification_cc_proto", "//mediapipe/framework/formats:detection_cc_proto", "//mediapipe/framework/port:gtest_main", diff --git a/mediapipe/calculators/util/association_calculator_test.cc b/mediapipe/calculators/util/association_calculator_test.cc index 140338ba7b..3c1b33cde0 100644 --- a/mediapipe/calculators/util/association_calculator_test.cc +++ b/mediapipe/calculators/util/association_calculator_test.cc @@ -16,7 +16,6 @@ #include "mediapipe/framework/calculator_framework.h" #include "mediapipe/framework/calculator_runner.h" #include "mediapipe/framework/collection_item_id.h" -#include "mediapipe/framework/deps/message_matchers.h" #include "mediapipe/framework/formats/detection.pb.h" #include "mediapipe/framework/formats/location_data.pb.h" #include "mediapipe/framework/formats/rect.pb.h" diff --git a/mediapipe/calculators/util/detection_classifications_merger_calculator_test.cc b/mediapipe/calculators/util/detection_classifications_merger_calculator_test.cc index 56b1decdbb..e2aa252f92 100644 --- a/mediapipe/calculators/util/detection_classifications_merger_calculator_test.cc +++ b/mediapipe/calculators/util/detection_classifications_merger_calculator_test.cc @@ -14,9 +14,9 @@ #include "mediapipe/framework/calculator_framework.h" #include "mediapipe/framework/calculator_runner.h" -#include "mediapipe/framework/deps/message_matchers.h" #include "mediapipe/framework/formats/classification.pb.h" #include "mediapipe/framework/formats/detection.pb.h" +#include "mediapipe/framework/port/gmock.h" #include "mediapipe/framework/port/gtest.h" #include "mediapipe/framework/port/parse_text_proto.h" #include "mediapipe/framework/port/status_matchers.h" diff --git a/mediapipe/calculators/util/detections_to_rects_calculator_test.cc b/mediapipe/calculators/util/detections_to_rects_calculator_test.cc index a45048d40c..6caf792a73 100644 --- a/mediapipe/calculators/util/detections_to_rects_calculator_test.cc +++ b/mediapipe/calculators/util/detections_to_rects_calculator_test.cc @@ -19,7 +19,6 @@ #include "mediapipe/framework/calculator.pb.h" #include "mediapipe/framework/calculator_framework.h" #include "mediapipe/framework/calculator_runner.h" -#include "mediapipe/framework/deps/message_matchers.h" #include "mediapipe/framework/formats/detection.pb.h" #include "mediapipe/framework/formats/location_data.pb.h" #include "mediapipe/framework/formats/rect.pb.h" diff --git a/mediapipe/calculators/util/detections_to_render_data_calculator_test.cc b/mediapipe/calculators/util/detections_to_render_data_calculator_test.cc index 04d8b5bcd7..0d0da23508 100644 --- a/mediapipe/calculators/util/detections_to_render_data_calculator_test.cc +++ b/mediapipe/calculators/util/detections_to_render_data_calculator_test.cc @@ -17,7 +17,6 @@ #include "mediapipe/framework/calculator.pb.h" #include "mediapipe/framework/calculator_framework.h" #include "mediapipe/framework/calculator_runner.h" -#include "mediapipe/framework/deps/message_matchers.h" #include "mediapipe/framework/formats/detection.pb.h" #include "mediapipe/framework/formats/location_data.pb.h" #include "mediapipe/framework/packet.h" @@ -34,8 +33,6 @@ constexpr char kDetectionsTag[] = "DETECTIONS"; constexpr char kRenderDataTag[] = "RENDER_DATA"; constexpr char kDetectionListTag[] = "DETECTION_LIST"; -using ::testing::DoubleNear; - // Error tolerance for pixels, distances, etc. static constexpr double kErrorTolerance = 1e-5; diff --git a/mediapipe/calculators/util/filter_detections_calculator_test.cc b/mediapipe/calculators/util/filter_detections_calculator_test.cc index 515a8b7df9..58b3fe41da 100644 --- a/mediapipe/calculators/util/filter_detections_calculator_test.cc +++ b/mediapipe/calculators/util/filter_detections_calculator_test.cc @@ -16,7 +16,6 @@ #include "mediapipe/framework/calculator_framework.h" #include "mediapipe/framework/calculator_runner.h" -#include "mediapipe/framework/deps/message_matchers.h" #include "mediapipe/framework/formats/detection.pb.h" #include "mediapipe/framework/port/gmock.h" #include "mediapipe/framework/port/gtest.h" diff --git a/mediapipe/calculators/util/inverse_matrix_calculator.cc b/mediapipe/calculators/util/inverse_matrix_calculator.cc index 5809623c05..9f97e0449f 100644 --- a/mediapipe/calculators/util/inverse_matrix_calculator.cc +++ b/mediapipe/calculators/util/inverse_matrix_calculator.cc @@ -33,9 +33,17 @@ class InverseMatrixCalculatorImpl : public NodeImpl { kInputMatrix(cc).Get().data()); Eigen::Matrix inverse_matrix; - bool inverse_check; - matrix.computeInverseWithCheck(inverse_matrix, inverse_check); - RET_CHECK(inverse_check) << "Inverse matrix cannot be calculated."; + bool inverse_check = false; + // The matrix is invertible if the absolute value of its determinant is + // greater than this threshold. Quite small threshold is selected to enable + // inverting valid matrices containing relatively small values resulting in + // a small determinant. + constexpr double kAbsDeterminantThreshold = + Eigen::NumTraits::epsilon(); + matrix.computeInverseWithCheck(inverse_matrix, inverse_check, + kAbsDeterminantThreshold); + RET_CHECK(inverse_check) + << "Inverse matrix cannot be calculated for: " << matrix; std::array output; Eigen::Map>( diff --git a/mediapipe/calculators/util/inverse_matrix_calculator_test.cc b/mediapipe/calculators/util/inverse_matrix_calculator_test.cc index d3b629c786..ac50fdfac8 100644 --- a/mediapipe/calculators/util/inverse_matrix_calculator_test.cc +++ b/mediapipe/calculators/util/inverse_matrix_calculator_test.cc @@ -42,7 +42,11 @@ void RunTest(const std::array& matrix, const auto& inverse_matrix = output_packets[0].Get>(); - EXPECT_THAT(inverse_matrix, testing::Eq(expected_inverse_matrix)); + EXPECT_THAT( + inverse_matrix, + testing::Pointwise(testing::FloatEq(), + absl::MakeSpan(expected_inverse_matrix.data(), + expected_inverse_matrix.size()))); // Fully close graph at end, otherwise calculator+tensors are destroyed // after calling WaitUntilDone(). @@ -122,5 +126,25 @@ TEST(InverseMatrixCalculatorTest, Rotation90) { RunTest(matrix, expected_inverse_matrix); } +TEST(InverseMatrixCalculatorTest, CheckPrecision) { + // clang-format off + std::array matrix = { + 0.00001f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.00001f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f, + }; + + std::array expected_inverse_matrix = { + 100000.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 100000.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f, + }; + // clang-format on + + RunTest(matrix, expected_inverse_matrix); +} + } // namespace } // namespace mediapipe diff --git a/mediapipe/calculators/util/landmark_projection_calculator_test.cc b/mediapipe/calculators/util/landmark_projection_calculator_test.cc index 2e919c30e6..81e1f6488c 100644 --- a/mediapipe/calculators/util/landmark_projection_calculator_test.cc +++ b/mediapipe/calculators/util/landmark_projection_calculator_test.cc @@ -6,9 +6,9 @@ #include "mediapipe/framework/calculator.pb.h" #include "mediapipe/framework/calculator_framework.h" #include "mediapipe/framework/calculator_runner.h" -#include "mediapipe/framework/deps/message_matchers.h" #include "mediapipe/framework/formats/landmark.pb.h" #include "mediapipe/framework/formats/rect.pb.h" +#include "mediapipe/framework/port/gmock.h" #include "mediapipe/framework/port/gtest.h" #include "mediapipe/framework/port/parse_text_proto.h" #include "mediapipe/framework/port/status_matchers.h" diff --git a/mediapipe/calculators/util/packet_latency_calculator_test.cc b/mediapipe/calculators/util/packet_latency_calculator_test.cc index aade25b0d5..6f03f2e755 100644 --- a/mediapipe/calculators/util/packet_latency_calculator_test.cc +++ b/mediapipe/calculators/util/packet_latency_calculator_test.cc @@ -16,7 +16,6 @@ #include "mediapipe/calculators/util/latency.pb.h" #include "mediapipe/framework/calculator_runner.h" #include "mediapipe/framework/deps/clock.h" -#include "mediapipe/framework/deps/message_matchers.h" #include "mediapipe/framework/port/gmock.h" #include "mediapipe/framework/port/gtest.h" #include "mediapipe/framework/port/parse_text_proto.h" diff --git a/mediapipe/calculators/util/to_image_calculator.cc b/mediapipe/calculators/util/to_image_calculator.cc index 5e119fca74..22fedfdb11 100644 --- a/mediapipe/calculators/util/to_image_calculator.cc +++ b/mediapipe/calculators/util/to_image_calculator.cc @@ -14,6 +14,7 @@ #include +#include "mediapipe/framework/api2/node.h" #include "mediapipe/framework/calculator_framework.h" #include "mediapipe/framework/calculator_options.pb.h" #include "mediapipe/framework/formats/image.h" @@ -23,23 +24,23 @@ #include "mediapipe/framework/port/status.h" #include "mediapipe/framework/port/vector.h" -#if !MEDIAPIPE_DISABLE_GPU -#include "mediapipe/gpu/gl_calculator_helper.h" -#endif // !MEDIAPIPE_DISABLE_GPU - namespace mediapipe { +namespace api2 { -namespace { -constexpr char kImageFrameTag[] = "IMAGE_CPU"; -constexpr char kGpuBufferTag[] = "IMAGE_GPU"; -constexpr char kImageTag[] = "IMAGE"; -} // namespace +#if MEDIAPIPE_DISABLE_GPU +// Just a placeholder to not have to depend on mediapipe::GpuBuffer. +class Nothing {}; +using GpuBuffer = Nothing; +#else +using GpuBuffer = mediapipe::GpuBuffer; +#endif // MEDIAPIPE_DISABLE_GPU // A calculator for converting from legacy MediaPipe datatypes into a // unified image container. // // Inputs: // One of the following two tags: +// IMAGE: An Image, ImageFrame, or GpuBuffer containing input image. // IMAGE_CPU: An ImageFrame containing input image. // IMAGE_GPU: A GpuBuffer containing input image. // @@ -49,112 +50,88 @@ constexpr char kImageTag[] = "IMAGE"; // Note: // No CPU/GPU conversion is done. // -class ToImageCalculator : public CalculatorBase { +class ToImageCalculator : public Node { public: ToImageCalculator() = default; ~ToImageCalculator() override = default; - static absl::Status GetContract(CalculatorContract* cc); + static constexpr Input< + OneOf>::Optional kIn{ + "IMAGE"}; + static constexpr Input::Optional kInCpu{"IMAGE_CPU"}; + static constexpr Input::Optional kInGpu{"IMAGE_GPU"}; + static constexpr Output kOut{"IMAGE"}; + MEDIAPIPE_NODE_CONTRACT(kIn, kInCpu, kInGpu, kOut); + + static absl::Status UpdateContract(CalculatorContract* cc); // From Calculator. - absl::Status Open(CalculatorContext* cc) override; absl::Status Process(CalculatorContext* cc) override; absl::Status Close(CalculatorContext* cc) override; private: - absl::Status RenderGpu(CalculatorContext* cc); - absl::Status RenderCpu(CalculatorContext* cc); - - bool gpu_input_ = false; - bool gpu_initialized_ = false; -#if !MEDIAPIPE_DISABLE_GPU - mediapipe::GlCalculatorHelper gpu_helper_; -#endif // !MEDIAPIPE_DISABLE_GPU + absl::StatusOr> GetInputImage(CalculatorContext* cc); }; -REGISTER_CALCULATOR(ToImageCalculator); - -absl::Status ToImageCalculator::GetContract(CalculatorContract* cc) { - cc->Outputs().Tag(kImageTag).Set(); - - bool gpu_input = false; +MEDIAPIPE_REGISTER_NODE(ToImageCalculator); - if (cc->Inputs().HasTag(kImageFrameTag) && - cc->Inputs().HasTag(kGpuBufferTag)) { +absl::Status ToImageCalculator::UpdateContract(CalculatorContract* cc) { + int num_inputs = static_cast(kIn(cc).IsConnected()) + + static_cast(kInCpu(cc).IsConnected()) + + static_cast(kInGpu(cc).IsConnected()); + if (num_inputs != 1) { return absl::InternalError("Cannot have multiple inputs."); } - if (cc->Inputs().HasTag(kGpuBufferTag)) { -#if !MEDIAPIPE_DISABLE_GPU - cc->Inputs().Tag(kGpuBufferTag).Set(); - gpu_input = true; -#else - RET_CHECK_FAIL() << "GPU is disabled. Cannot use IMAGE_GPU stream."; -#endif // !MEDIAPIPE_DISABLE_GPU - } - if (cc->Inputs().HasTag(kImageFrameTag)) { - cc->Inputs().Tag(kImageFrameTag).Set(); - } - - if (gpu_input) { -#if !MEDIAPIPE_DISABLE_GPU - MP_RETURN_IF_ERROR(mediapipe::GlCalculatorHelper::UpdateContract(cc)); -#endif // !MEDIAPIPE_DISABLE_GPU - } - return absl::OkStatus(); } -absl::Status ToImageCalculator::Open(CalculatorContext* cc) { - cc->SetOffset(TimestampDiff(0)); - - if (cc->Inputs().HasTag(kGpuBufferTag)) { - gpu_input_ = true; - } - - if (gpu_input_) { -#if !MEDIAPIPE_DISABLE_GPU - MP_RETURN_IF_ERROR(gpu_helper_.Open(cc)); -#endif - } // !MEDIAPIPE_DISABLE_GPU +absl::Status ToImageCalculator::Process(CalculatorContext* cc) { + ASSIGN_OR_RETURN(auto output, GetInputImage(cc)); + kOut(cc).Send(output.At(cc->InputTimestamp())); + return absl::OkStatus(); +} +absl::Status ToImageCalculator::Close(CalculatorContext* cc) { return absl::OkStatus(); } -absl::Status ToImageCalculator::Process(CalculatorContext* cc) { - if (gpu_input_) { +// Wrap ImageFrameSharedPtr; shallow copy. +absl::StatusOr> FromImageFrame(Packet packet) { + return MakePacket>( + std::const_pointer_cast( + SharedPtrWithPacket(packet))); +} + +// Wrap texture pointer; shallow copy. +absl::StatusOr> FromGpuBuffer(Packet packet) { #if !MEDIAPIPE_DISABLE_GPU - MP_RETURN_IF_ERROR(gpu_helper_.RunInGlContext([&cc]() -> absl::Status { - auto& input = cc->Inputs().Tag(kGpuBufferTag).Get(); - // Wrap texture pointer; shallow copy. - auto output = std::make_unique(input); - cc->Outputs().Tag(kImageTag).Add(output.release(), cc->InputTimestamp()); - return absl::OkStatus(); - })); + const GpuBuffer& buffer = *packet; + return MakePacket(buffer); +#else + return absl::UnimplementedError("GPU processing is disabled in build flags"); #endif // !MEDIAPIPE_DISABLE_GPU - } else { - // The input ImageFrame. - auto& input = cc->Inputs().Tag(kImageFrameTag).Get(); - // Make a copy of the input packet to co-own the input ImageFrame. - Packet* packet_copy_ptr = - new Packet(cc->Inputs().Tag(kImageFrameTag).Value()); - // Create an output Image that (co-)owns a new ImageFrame that points to - // the same pixel data as the input ImageFrame and also owns the packet - // copy. As a result, the output Image indirectly co-owns the input - // ImageFrame. This ensures a correct life span of the shared pixel data. - std::unique_ptr output = - std::make_unique( - std::make_shared( - input.Format(), input.Width(), input.Height(), - input.WidthStep(), const_cast(input.PixelData()), - [packet_copy_ptr](uint8*) { delete packet_copy_ptr; })); - cc->Outputs().Tag(kImageTag).Add(output.release(), cc->InputTimestamp()); - } - - return absl::OkStatus(); } -absl::Status ToImageCalculator::Close(CalculatorContext* cc) { - return absl::OkStatus(); +absl::StatusOr> ToImageCalculator::GetInputImage( + CalculatorContext* cc) { + if (kIn(cc).IsConnected()) { + return kIn(cc).Visit( + [&](const mediapipe::Image&) { + return absl::StatusOr>(kIn(cc).As()); + }, + [&](const mediapipe::ImageFrame&) { + return FromImageFrame(kIn(cc).As()); + }, + [&](const GpuBuffer&) { + return FromGpuBuffer(kIn(cc).As()); + }); + } else if (kInCpu(cc).IsConnected()) { + return FromImageFrame(kInCpu(cc).As()); + } else if (kInGpu(cc).IsConnected()) { + return FromGpuBuffer(kInGpu(cc).As()); + } + return absl::InvalidArgumentError("No input found."); } +} // namespace api2 } // namespace mediapipe diff --git a/mediapipe/examples/desktop/autoflip/calculators/BUILD b/mediapipe/examples/desktop/autoflip/calculators/BUILD index 9f41a564d9..550a62a63d 100644 --- a/mediapipe/examples/desktop/autoflip/calculators/BUILD +++ b/mediapipe/examples/desktop/autoflip/calculators/BUILD @@ -291,6 +291,7 @@ cc_library( "//mediapipe/framework/formats:image_frame", "//mediapipe/framework/port:ret_check", "//mediapipe/framework/port:status", + "@com_google_absl//absl/container:btree", ], alwayslink = 1, ) @@ -390,6 +391,7 @@ cc_test( "//mediapipe/framework/port:parse_text_proto", "//mediapipe/framework/port:ret_check", "//mediapipe/framework/port:status", + "@com_google_absl//absl/container:btree", "@com_google_absl//absl/flags:flag", "@com_google_absl//absl/strings", ], diff --git a/mediapipe/examples/desktop/autoflip/calculators/content_zooming_calculator.cc b/mediapipe/examples/desktop/autoflip/calculators/content_zooming_calculator.cc index 9113686fe8..f04833b014 100644 --- a/mediapipe/examples/desktop/autoflip/calculators/content_zooming_calculator.cc +++ b/mediapipe/examples/desktop/autoflip/calculators/content_zooming_calculator.cc @@ -657,7 +657,10 @@ absl::Status ContentZoomingCalculator::Process( } const bool camera_active = is_animating || pan_state || tilt_state || zoom_state; - if (cc->Outputs().HasTag(kCameraActive)) { + // Waiting for first rect before setting any value of the camera active flag + // so we avoid setting it to false during initialization. + if (cc->Outputs().HasTag(kCameraActive) && + first_rect_timestamp_ != Timestamp::Unset()) { cc->Outputs() .Tag(kCameraActive) .AddPacket(MakePacket(camera_active).At(cc->InputTimestamp())); diff --git a/mediapipe/examples/desktop/autoflip/calculators/shot_boundary_calculator_test.cc b/mediapipe/examples/desktop/autoflip/calculators/shot_boundary_calculator_test.cc index bcc27a6b2d..9ea79ba446 100644 --- a/mediapipe/examples/desktop/autoflip/calculators/shot_boundary_calculator_test.cc +++ b/mediapipe/examples/desktop/autoflip/calculators/shot_boundary_calculator_test.cc @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "absl/container/btree_set.h" #include "absl/flags/flag.h" #include "absl/strings/string_view.h" #include "mediapipe/examples/desktop/autoflip/calculators/shot_boundary_calculator.pb.h" @@ -54,7 +55,8 @@ const char kConfig[] = R"( const int kTestFrameWidth = 640; const int kTestFrameHeight = 480; -void AddFrames(const int number_of_frames, const std::set& skip_frames, +void AddFrames(const int number_of_frames, + const absl::btree_set& skip_frames, CalculatorRunner* runner) { cv::Mat image = cv::imread(file::JoinPath("./", @@ -78,7 +80,8 @@ void AddFrames(const int number_of_frames, const std::set& skip_frames, } } -void CheckOutput(const int number_of_frames, const std::set& shot_frames, +void CheckOutput(const int number_of_frames, + const absl::btree_set& shot_frames, const std::vector& output_packets) { ASSERT_EQ(number_of_frames, output_packets.size()); for (int i = 0; i < number_of_frames; i++) { diff --git a/mediapipe/examples/desktop/autoflip/calculators/signal_fusing_calculator.cc b/mediapipe/examples/desktop/autoflip/calculators/signal_fusing_calculator.cc index 37643b5d1a..85b2d96f8a 100644 --- a/mediapipe/examples/desktop/autoflip/calculators/signal_fusing_calculator.cc +++ b/mediapipe/examples/desktop/autoflip/calculators/signal_fusing_calculator.cc @@ -18,6 +18,7 @@ #include #include +#include "absl/container/btree_map.h" #include "mediapipe/examples/desktop/autoflip/autoflip_messages.pb.h" #include "mediapipe/examples/desktop/autoflip/calculators/signal_fusing_calculator.pb.h" #include "mediapipe/framework/calculator_framework.h" @@ -178,8 +179,8 @@ absl::Status SignalFusingCalculator::Close(mediapipe::CalculatorContext* cc) { absl::Status SignalFusingCalculator::ProcessScene( mediapipe::CalculatorContext* cc) { - std::map detection_count; - std::map multiframe_score; + absl::btree_map detection_count; + absl::btree_map multiframe_score; // Create a unified score for all items with temporal ids. for (const Frame& frame : scene_frames_) { for (const auto& detection : frame.input_detections) { diff --git a/mediapipe/framework/BUILD b/mediapipe/framework/BUILD index 45e11e3a56..ef32c6c813 100644 --- a/mediapipe/framework/BUILD +++ b/mediapipe/framework/BUILD @@ -1187,7 +1187,6 @@ cc_test( "//mediapipe/framework:calculator_cc_proto", "//mediapipe/framework/api2:node", "//mediapipe/framework/api2:port", - "//mediapipe/framework/deps:message_matchers", "//mediapipe/framework/port:gtest_main", "@com_google_absl//absl/status", "@com_google_absl//absl/strings", @@ -1580,7 +1579,6 @@ cc_test( ":packet", ":packet_test_cc_proto", ":type_map", - "//mediapipe/framework/deps:message_matchers", "//mediapipe/framework/port:core_proto", "//mediapipe/framework/port:gtest_main", "@com_google_absl//absl/strings", @@ -1640,7 +1638,6 @@ cc_test( "//mediapipe/framework:calculator_cc_proto", "//mediapipe/framework:packet_generator_cc_proto", "//mediapipe/framework:status_handler_cc_proto", - "//mediapipe/framework/deps:message_matchers", "//mediapipe/framework/port:gtest_main", "//mediapipe/framework/port:parse_text_proto", "//mediapipe/framework/tool:template_parser", diff --git a/mediapipe/framework/api2/BUILD b/mediapipe/framework/api2/BUILD index 1a4faca134..20022fb899 100644 --- a/mediapipe/framework/api2/BUILD +++ b/mediapipe/framework/api2/BUILD @@ -36,7 +36,6 @@ cc_test( ":tag", ":test_contracts", "//mediapipe/framework:calculator_framework", - "//mediapipe/framework/deps:message_matchers", "//mediapipe/framework/port:gtest_main", "//mediapipe/framework/port:parse_text_proto", "@com_google_absl//absl/strings", @@ -175,7 +174,6 @@ cc_test( ":port", ":test_contracts", "//mediapipe/framework:calculator_framework", - "//mediapipe/framework/deps:message_matchers", "//mediapipe/framework/port:gtest_main", "//mediapipe/framework/port:parse_text_proto", "//mediapipe/framework/tool:subgraph_expansion", diff --git a/mediapipe/framework/api2/builder_test.cc b/mediapipe/framework/api2/builder_test.cc index e340622e91..e2c1820e7e 100644 --- a/mediapipe/framework/api2/builder_test.cc +++ b/mediapipe/framework/api2/builder_test.cc @@ -9,7 +9,6 @@ #include "mediapipe/framework/api2/tag.h" #include "mediapipe/framework/api2/test_contracts.h" #include "mediapipe/framework/calculator_framework.h" -#include "mediapipe/framework/deps/message_matchers.h" #include "mediapipe/framework/port/gmock.h" #include "mediapipe/framework/port/gtest.h" #include "mediapipe/framework/port/parse_text_proto.h" diff --git a/mediapipe/framework/api2/node_test.cc b/mediapipe/framework/api2/node_test.cc index cc69209c6c..a6c1ef7c6c 100644 --- a/mediapipe/framework/api2/node_test.cc +++ b/mediapipe/framework/api2/node_test.cc @@ -565,6 +565,19 @@ TEST(NodeTest, ConsumeInputs) { MP_EXPECT_OK(graph.WaitUntilDone()); } +// Just to test that single-port contracts work. +struct LogSinkNode : public Node { + static constexpr Input kIn{"IN"}; + + MEDIAPIPE_NODE_CONTRACT(kIn); + + absl::Status Process(CalculatorContext* cc) override { + LOG(INFO) << "LogSinkNode received: " << kIn(cc).Get(); + return {}; + } +}; +MEDIAPIPE_REGISTER_NODE(LogSinkNode); + } // namespace test } // namespace api2 } // namespace mediapipe diff --git a/mediapipe/framework/api2/subgraph_test.cc b/mediapipe/framework/api2/subgraph_test.cc index a4938577d8..3dede6b886 100644 --- a/mediapipe/framework/api2/subgraph_test.cc +++ b/mediapipe/framework/api2/subgraph_test.cc @@ -4,7 +4,6 @@ #include "mediapipe/framework/api2/port.h" #include "mediapipe/framework/api2/test_contracts.h" #include "mediapipe/framework/calculator_framework.h" -#include "mediapipe/framework/deps/message_matchers.h" #include "mediapipe/framework/port/gmock.h" #include "mediapipe/framework/port/gtest.h" #include "mediapipe/framework/port/parse_text_proto.h" diff --git a/mediapipe/framework/api2/tuple.h b/mediapipe/framework/api2/tuple.h index 0a7253728d..506b4f9211 100644 --- a/mediapipe/framework/api2/tuple.h +++ b/mediapipe/framework/api2/tuple.h @@ -18,11 +18,10 @@ template using tuple_index_sequence = std::make_index_sequence>>; -// Concatenates two std::index_sequences. -template -constexpr auto index_sequence_cat(std::index_sequence, - std::index_sequence) - -> std::index_sequence { +// Concatenates multiple std::index_sequences. +template +constexpr auto index_sequence_cat(std::index_sequence) + -> std::index_sequence { return {}; } diff --git a/mediapipe/framework/calculator_base_test.cc b/mediapipe/framework/calculator_base_test.cc index 4d38918182..42c03696c9 100644 --- a/mediapipe/framework/calculator_base_test.cc +++ b/mediapipe/framework/calculator_base_test.cc @@ -174,7 +174,7 @@ TEST(CalculatorTest, CreateByName) { TEST(CalculatorTest, CreateByNameWhitelisted) { // Reset the registration namespace whitelist. *const_cast*>( - &NamespaceWhitelist::TopNamespaces()) = absl::flat_hash_set{ + &NamespaceAllowlist::TopNamespaces()) = absl::flat_hash_set{ "mediapipe::test_ns::whitelisted_ns", "mediapipe", }; diff --git a/mediapipe/framework/calculator_node.h b/mediapipe/framework/calculator_node.h index f4421d300c..368e0a5579 100644 --- a/mediapipe/framework/calculator_node.h +++ b/mediapipe/framework/calculator_node.h @@ -236,21 +236,21 @@ class CalculatorNode { } private: - // Sets up the output side packets from the master flat array. + // Sets up the output side packets from the main flat array. absl::Status InitializeOutputSidePackets( const PacketTypeSet& output_side_packet_types, OutputSidePacketImpl* output_side_packets); // Connects the input side packets as mirrors on the output side packets. - // Output side packets are looked up in the master flat array which is + // Output side packets are looked up in the main flat array which is // provided. absl::Status InitializeInputSidePackets( OutputSidePacketImpl* output_side_packets); - // Sets up the output streams from the master flat array. + // Sets up the output streams from the main flat array. absl::Status InitializeOutputStreams( OutputStreamManager* output_stream_managers); // Sets up the input streams and connects them as mirrors on the // output streams. Both input streams and output streams are looked - // up in the master flat arrays which are provided. + // up in the main flat arrays which are provided. absl::Status InitializeInputStreams( InputStreamManager* input_stream_managers, OutputStreamManager* output_stream_managers); diff --git a/mediapipe/framework/collection.h b/mediapipe/framework/collection.h index a8b63435af..c7b6fb0de3 100644 --- a/mediapipe/framework/collection.h +++ b/mediapipe/framework/collection.h @@ -26,6 +26,7 @@ #include "absl/base/macros.h" #include "absl/memory/memory.h" #include "absl/strings/str_cat.h" +#include "absl/strings/string_view.h" #include "mediapipe/framework/collection_item_id.h" #include "mediapipe/framework/port/logging.h" #include "mediapipe/framework/tool/tag_map.h" @@ -50,7 +51,7 @@ struct CollectionErrorHandlerFatal { // Since there isn't any state and we're not returning anything, we // get away with only one version of this function (which is const // but returns a non-const reference). - T& GetFallback(const std::string& tag, int index) const { + T& GetFallback(const absl::string_view tag, int index) const { LOG(FATAL) << "Failed to get tag \"" << tag << "\" index " << index; std::abort(); } @@ -131,16 +132,16 @@ class Collection { const value_type& Get(CollectionItemId id) const; // Convenience functions. - value_type& Get(const std::string& tag, int index); - const value_type& Get(const std::string& tag, int index) const; + value_type& Get(absl::string_view tag, int index); + const value_type& Get(absl::string_view tag, int index) const; // Equivalent to Get("", index); value_type& Index(int index); const value_type& Index(int index) const; // Equivalent to Get(tag, 0); - value_type& Tag(const std::string& tag); - const value_type& Tag(const std::string& tag) const; + value_type& Tag(absl::string_view tag); + const value_type& Tag(absl::string_view tag) const; // These functions only exist for collections with storage == // kStorePointer. GetPtr returns the stored ptr value rather than @@ -179,13 +180,15 @@ class Collection { //////////////////////////////////////// // Returns true if the provided tag is available (not necessarily set yet). - bool HasTag(const std::string& tag) const { return tag_map_->HasTag(tag); } + bool HasTag(const absl::string_view tag) const { + return tag_map_->HasTag(tag); + } // Returns the number of entries in this collection. int NumEntries() const { return tag_map_->NumEntries(); } // Returns the number of entries with the provided tag. - int NumEntries(const std::string& tag) const { + int NumEntries(const absl::string_view tag) const { return tag_map_->NumEntries(tag); } @@ -200,7 +203,7 @@ class Collection { // However, be careful in using this fact, as it circumvents the // validity checks in GetId() (i.e. ++GetId("BLAH", 2) looks like it // is valid, while GetId("BLAH", 3) is not valid). - CollectionItemId GetId(const std::string& tag, int index) const { + CollectionItemId GetId(const absl::string_view tag, int index) const { return tag_map_->GetId(tag, index); } @@ -234,10 +237,10 @@ class Collection { // for (CollectionItemId id = collection.BeginId(tag); // id < collection.EndId(tag); ++id) { // } - CollectionItemId BeginId(const std::string& tag) const { + CollectionItemId BeginId(const absl::string_view tag) const { return tag_map_->BeginId(tag); } - CollectionItemId EndId(const std::string& tag) const { + CollectionItemId EndId(const absl::string_view tag) const { return tag_map_->EndId(tag); } @@ -404,7 +407,7 @@ bool Collection::UsesTags() const { return false; } // If the one tag present is non-empty then we are using tags. - return mapping.begin()->first != ""; + return !mapping.begin()->first.empty(); } template @@ -449,7 +452,8 @@ Collection::GetPtr(CollectionItemId id) const { template typename Collection::value_type& -Collection::Get(const std::string& tag, int index) { +Collection::Get(const absl::string_view tag, + int index) { CollectionItemId id = GetId(tag, index); if (!id.IsValid()) { return error_handler_.GetFallback(tag, index); @@ -459,7 +463,7 @@ Collection::Get(const std::string& tag, int index) { template const typename Collection::value_type& -Collection::Get(const std::string& tag, +Collection::Get(const absl::string_view tag, int index) const { CollectionItemId id = GetId(tag, index); if (!id.IsValid()) { @@ -482,13 +486,13 @@ Collection::Index(int index) const { template typename Collection::value_type& -Collection::Tag(const std::string& tag) { +Collection::Tag(const absl::string_view tag) { return Get(tag, 0); } template const typename Collection::value_type& -Collection::Tag(const std::string& tag) const { +Collection::Tag(const absl::string_view tag) const { return Get(tag, 0); } @@ -535,21 +539,23 @@ Collection::end() const { // Returns c.HasTag(tag) && !Tag(tag)->IsEmpty() (just for convenience). // This version is used with Calculator. template -bool HasTagValue(const internal::Collection& c, const std::string& tag) { +bool HasTagValue(const internal::Collection& c, + const absl::string_view tag) { return c.HasTag(tag) && !c.Tag(tag)->IsEmpty(); } // Returns c.HasTag(tag) && !Tag(tag).IsEmpty() (just for convenience). // This version is used with CalculatorBase. template -bool HasTagValue(const internal::Collection& c, const std::string& tag) { +bool HasTagValue(const internal::Collection& c, + const absl::string_view tag) { return c.HasTag(tag) && !c.Tag(tag).IsEmpty(); } // Returns c.HasTag(tag) && !Tag(tag).IsEmpty() (just for convenience). // This version is used with Calculator or CalculatorBase. template -bool HasTagValue(const C& c, const std::string& tag) { +bool HasTagValue(const C& c, const absl::string_view tag) { return HasTagValue(c->Inputs(), tag); } diff --git a/mediapipe/framework/deps/BUILD b/mediapipe/framework/deps/BUILD index 1133daa62c..27052fcf49 100644 --- a/mediapipe/framework/deps/BUILD +++ b/mediapipe/framework/deps/BUILD @@ -87,10 +87,11 @@ cc_library( name = "message_matchers", testonly = True, hdrs = ["message_matchers.h"], - visibility = ["//visibility:public"], + # Use this library through "mediapipe/framework/port:gtest_main". + visibility = ["//mediapipe/framework/port:__pkg__"], deps = [ "//mediapipe/framework/port:core_proto", - "//mediapipe/framework/port:gtest_main", + "@com_google_googletest//:gtest", ], ) diff --git a/mediapipe/framework/deps/message_matchers.h b/mediapipe/framework/deps/message_matchers.h index cc39223131..31b32deae0 100644 --- a/mediapipe/framework/deps/message_matchers.h +++ b/mediapipe/framework/deps/message_matchers.h @@ -17,8 +17,8 @@ #include +#include "gmock/gmock.h" #include "mediapipe/framework/port/core_proto_inc.h" -#include "mediapipe/framework/port/gmock.h" namespace mediapipe { diff --git a/mediapipe/framework/deps/registration.cc b/mediapipe/framework/deps/registration.cc index c6a3ffa0d7..4054fbf30e 100644 --- a/mediapipe/framework/deps/registration.cc +++ b/mediapipe/framework/deps/registration.cc @@ -21,7 +21,7 @@ namespace mediapipe { namespace { // List of namespaces that can register calculators inside the namespace -// and still refer to them using an unqualified name. This whitelist +// and still refer to them using an unqualified name. This allowlist // is meant to facilitate migration from unqualified to fully qualified // calculator names. constexpr char const* kTopNamespaces[] = { @@ -36,7 +36,7 @@ inline size_t array_size(T (&arr)[SIZE]) { } // namespace /*static*/ -const absl::flat_hash_set& NamespaceWhitelist::TopNamespaces() { +const absl::flat_hash_set& NamespaceAllowlist::TopNamespaces() { static absl::flat_hash_set* result = new absl::flat_hash_set( kTopNamespaces, kTopNamespaces + array_size(kTopNamespaces)); diff --git a/mediapipe/framework/deps/registration.h b/mediapipe/framework/deps/registration.h index 9eb0c8ddfe..07c4a44a42 100644 --- a/mediapipe/framework/deps/registration.h +++ b/mediapipe/framework/deps/registration.h @@ -144,7 +144,7 @@ struct WrapStatusOr> { }; } // namespace registration_internal -class NamespaceWhitelist { +class NamespaceAllowlist { public: static const absl::flat_hash_set& TopNamespaces(); }; @@ -289,14 +289,14 @@ class FunctionRegistry { mutable absl::Mutex lock_; std::unordered_map functions_ ABSL_GUARDED_BY(lock_); - // For names included in NamespaceWhitelist, strips the namespace. + // For names included in NamespaceAllowlist, strips the namespace. std::string GetAdjustedName(const std::string& name) { constexpr auto kCxxSep = registration_internal::kCxxSep; std::vector names = absl::StrSplit(name, kCxxSep); std::string base_name = names.back(); names.pop_back(); std::string ns = absl::StrJoin(names, kCxxSep); - if (NamespaceWhitelist::TopNamespaces().count(ns)) { + if (NamespaceAllowlist::TopNamespaces().count(ns)) { return base_name; } return name; diff --git a/mediapipe/framework/formats/image_frame.cc b/mediapipe/framework/formats/image_frame.cc index 6c8d4974ec..913ffae244 100644 --- a/mediapipe/framework/formats/image_frame.cc +++ b/mediapipe/framework/formats/image_frame.cc @@ -242,7 +242,7 @@ bool ImageFrame::IsValidAlignmentNumber(uint32 alignment_boundary) { // static std::string ImageFrame::InvalidFormatString(ImageFormat::Format format) { -#ifdef MEDIAPIPE_MOBILE +#ifdef MEDIAPIPE_PROTO_LITE return "Invalid format."; #else const proto_ns::EnumValueDescriptor* enum_value_descriptor = diff --git a/mediapipe/framework/formats/image_frame_opencv.cc b/mediapipe/framework/formats/image_frame_opencv.cc index 4e5fe50c47..ada28ae354 100644 --- a/mediapipe/framework/formats/image_frame_opencv.cc +++ b/mediapipe/framework/formats/image_frame_opencv.cc @@ -75,7 +75,6 @@ int GetMatType(const mediapipe::ImageFormat::Format format) { } // namespace namespace mediapipe { - namespace formats { cv::Mat MatView(const ImageFrame* image) { diff --git a/mediapipe/framework/formats/image_opencv.cc b/mediapipe/framework/formats/image_opencv.cc index c03183d148..3c1ec548f8 100644 --- a/mediapipe/framework/formats/image_opencv.cc +++ b/mediapipe/framework/formats/image_opencv.cc @@ -75,7 +75,6 @@ int GetMatType(const mediapipe::ImageFormat::Format format) { } } // namespace namespace mediapipe { - namespace formats { cv::Mat MatView(const mediapipe::Image* image) { diff --git a/mediapipe/framework/formats/tensor_internal.h b/mediapipe/framework/formats/tensor_internal.h index d82cc9fb38..86e366a060 100644 --- a/mediapipe/framework/formats/tensor_internal.h +++ b/mediapipe/framework/formats/tensor_internal.h @@ -1,3 +1,17 @@ +// Copyright 2021 The MediaPipe Authors. +// +// 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. + #ifndef MEDIAPIPE_FRAMEWORK_FORMATS_TENSOR_INTERNAL_H_ #define MEDIAPIPE_FRAMEWORK_FORMATS_TENSOR_INTERNAL_H_ @@ -6,7 +20,7 @@ namespace mediapipe { // Generates unique view id at compile-time using FILE and LINE. -#define TENSOR_UNIQUE_VIEW_ID() \ +#define TENSOR_UNIQUE_VIEW_TYPE_ID() \ static constexpr uint64_t kId = tensor_internal::FnvHash64( \ __FILE__, tensor_internal::FnvHash64(TENSOR_INT_TO_STRING(__LINE__))) diff --git a/mediapipe/framework/graph_validation_test.cc b/mediapipe/framework/graph_validation_test.cc index 3e2336fbad..b2d38fc0e0 100644 --- a/mediapipe/framework/graph_validation_test.cc +++ b/mediapipe/framework/graph_validation_test.cc @@ -20,7 +20,6 @@ #include #include "mediapipe/framework/calculator_framework.h" -#include "mediapipe/framework/deps/message_matchers.h" #include "mediapipe/framework/port/gmock.h" #include "mediapipe/framework/port/gtest.h" #include "mediapipe/framework/port/parse_text_proto.h" diff --git a/mediapipe/framework/input_stream_handler.cc b/mediapipe/framework/input_stream_handler.cc index 4af4c7370c..27cba711f2 100644 --- a/mediapipe/framework/input_stream_handler.cc +++ b/mediapipe/framework/input_stream_handler.cc @@ -21,7 +21,6 @@ #include "mediapipe/framework/port/ret_check.h" namespace mediapipe { - using SyncSet = InputStreamHandler::SyncSet; absl::Status InputStreamHandler::InitializeInputStreamManagers( diff --git a/mediapipe/framework/input_stream_handler.h b/mediapipe/framework/input_stream_handler.h index 9408269323..1aa3194384 100644 --- a/mediapipe/framework/input_stream_handler.h +++ b/mediapipe/framework/input_stream_handler.h @@ -82,7 +82,7 @@ class InputStreamHandler { // flat_input_stream_managers is expected to point to a contiguous // flat array with InputStreamManagers corresponding to the id's in // InputStreamHandler::input_stream_managers_ (meaning it should point - // to somewhere in the middle of the master flat array of all input + // to somewhere in the middle of the main flat array of all input // stream managers). absl::Status InitializeInputStreamManagers( InputStreamManager* flat_input_stream_managers); diff --git a/mediapipe/framework/output_stream_handler.h b/mediapipe/framework/output_stream_handler.h index f134139c61..0b8dbed2c6 100644 --- a/mediapipe/framework/output_stream_handler.h +++ b/mediapipe/framework/output_stream_handler.h @@ -74,7 +74,7 @@ class OutputStreamHandler { // flat_output_stream_managers is expected to point to a contiguous // flat array with OutputStreamManagers corresponding to the id's in // OutputStreamHandler::output_stream_managers_ (meaning it should - // point to somewhere in the middle of the master flat array of all + // point to somewhere in the middle of the main flat array of all // output stream managers). absl::Status InitializeOutputStreamManagers( OutputStreamManager* flat_output_stream_managers); diff --git a/mediapipe/framework/packet.h b/mediapipe/framework/packet.h index db8eab93a1..c0de3a03d3 100644 --- a/mediapipe/framework/packet.h +++ b/mediapipe/framework/packet.h @@ -363,13 +363,8 @@ class HolderBase { HolderBase& operator=(const HolderBase&) = delete; virtual ~HolderBase(); template - void SetHolderTypeId() { - type_id_ = tool::GetTypeHash(); - } - size_t GetHolderTypeId() const { return type_id_; } - template - bool HolderIsOfType() const { - return type_id_ == tool::GetTypeHash(); + bool PayloadIsOfType() const { + return GetTypeId() == tool::GetTypeHash(); } // Returns a printable std::string identifying the type stored in the holder. virtual const std::string DebugTypeName() const = 0; @@ -397,8 +392,7 @@ class HolderBase { virtual StatusOr> GetVectorOfProtoMessageLite() const = 0; - private: - size_t type_id_; + virtual bool HasForeignOwner() const { return false; } }; // Two helper functions to get the proto base pointers. @@ -505,7 +499,6 @@ class Holder : public HolderBase { public: explicit Holder(const T* ptr) : ptr_(ptr) { HolderSupport::EnsureStaticInit(); - SetHolderTypeId(); } ~Holder() override { delete_helper(); } const T& data() const { @@ -521,9 +514,7 @@ class Holder : public HolderBase { absl::StatusOr> Release( typename std::enable_if::value || std::extent::value != 0>::type* = 0) { - // Since C++ doesn't allow virtual, templated functions, check holder - // type here to make sure it's not upcasted from a ForeignHolder. - if (!HolderIsOfType>()) { + if (HasForeignOwner()) { return InternalError( "Foreign holder can't release data ptr without ownership."); } @@ -592,25 +583,19 @@ class Holder : public HolderBase { template class ForeignHolder : public Holder { public: - explicit ForeignHolder(const T* ptr) : Holder(ptr) { - // Distinguishes between Holder and ForeignHolder since Consume() treats - // them differently. - this->template SetHolderTypeId(); - } + using Holder::Holder; ~ForeignHolder() override { // Null out ptr_ so it doesn't get deleted by ~Holder. + // Note that ~Holder cannot call HasForeignOwner because the subclass's + // destructor runs first. this->ptr_ = nullptr; } - // Foreign holder can't release data pointer without ownership. - absl::StatusOr> Release() { - return absl::InternalError( - "Foreign holder can't release data ptr without ownership."); - } + bool HasForeignOwner() const final { return true; } }; template Holder* HolderBase::As() { - if (HolderIsOfType>() || HolderIsOfType>()) { + if (PayloadIsOfType()) { return static_cast*>(this); } // Does not hold a T. @@ -619,7 +604,7 @@ Holder* HolderBase::As() { template const Holder* HolderBase::As() const { - if (HolderIsOfType>() || HolderIsOfType>()) { + if (PayloadIsOfType()) { return static_cast*>(this); } // Does not hold a T. @@ -648,7 +633,7 @@ inline absl::StatusOr> Packet::Consume() { MP_RETURN_IF_ERROR(ValidateAsType()); // Clients who use this function are responsible for ensuring that no // other thread is doing anything with this Packet. - if (holder_.unique()) { + if (!holder_->HasForeignOwner() && holder_.unique()) { VLOG(2) << "Consuming the data of " << DebugString(); absl::StatusOr> release_result = holder_->As()->Release(); @@ -670,8 +655,7 @@ inline absl::StatusOr> Packet::ConsumeOrCopy( typename std::enable_if::value>::type*) { MP_RETURN_IF_ERROR(ValidateAsType()); // If holder is the sole owner of the underlying data, consumes this packet. - if (!holder_->HolderIsOfType>() && - holder_.unique()) { + if (!holder_->HasForeignOwner() && holder_.unique()) { VLOG(2) << "Consuming the data of " << DebugString(); absl::StatusOr> release_result = holder_->As()->Release(); @@ -701,8 +685,7 @@ inline absl::StatusOr> Packet::ConsumeOrCopy( std::extent::value != 0>::type*) { MP_RETURN_IF_ERROR(ValidateAsType()); // If holder is the sole owner of the underlying data, consumes this packet. - if (!holder_->HolderIsOfType>() && - holder_.unique()) { + if (!holder_->HasForeignOwner() && holder_.unique()) { VLOG(2) << "Consuming the data of " << DebugString(); absl::StatusOr> release_result = holder_->As()->Release(); diff --git a/mediapipe/framework/packet_test.cc b/mediapipe/framework/packet_test.cc index 3181552f99..88a8dff43f 100644 --- a/mediapipe/framework/packet_test.cc +++ b/mediapipe/framework/packet_test.cc @@ -21,7 +21,6 @@ #include #include "absl/strings/str_cat.h" -#include "mediapipe/framework/deps/message_matchers.h" #include "mediapipe/framework/packet_test.pb.h" #include "mediapipe/framework/port/core_proto_inc.h" #include "mediapipe/framework/port/gmock.h" @@ -374,9 +373,9 @@ TEST(PacketTest, TestConsumeForeignHolder) { Packet packet = PointToForeign(data.get()); absl::StatusOr> result = packet.Consume(); EXPECT_FALSE(result.ok()); - EXPECT_EQ(result.status().code(), absl::StatusCode::kInternal); + EXPECT_EQ(result.status().code(), absl::StatusCode::kFailedPrecondition); EXPECT_EQ(result.status().message(), - "Foreign holder can't release data ptr without ownership."); + "Packet isn't the sole owner of the holder."); ASSERT_FALSE(packet.IsEmpty()); EXPECT_EQ(33, packet.Get()); } diff --git a/mediapipe/framework/packet_type.h b/mediapipe/framework/packet_type.h index cc924f4af3..676119f28b 100644 --- a/mediapipe/framework/packet_type.h +++ b/mediapipe/framework/packet_type.h @@ -24,6 +24,7 @@ #include "absl/base/macros.h" #include "absl/strings/str_split.h" +#include "absl/strings/string_view.h" #include "mediapipe/framework/collection.h" #include "mediapipe/framework/packet.h" #include "mediapipe/framework/packet_set.h" @@ -133,7 +134,7 @@ class PacketTypeSetErrorHandler { // Returns a usable PacketType. A different PacketType object is // returned for each different invalid location and the same object // is returned for multiple accesses to the same invalid location. - PacketType& GetFallback(const std::string& tag, int index) { + PacketType& GetFallback(const absl::string_view tag, int index) { if (!missing_) { missing_ = absl::make_unique(); } @@ -143,7 +144,7 @@ class PacketTypeSetErrorHandler { } // In the const setting produce a FATAL error. - const PacketType& GetFallback(const std::string& tag, int index) const { + const PacketType& GetFallback(const absl::string_view tag, int index) const { LOG(FATAL) << "Failed to get tag \"" << tag << "\" index " << index << ". Unable to defer error due to const specifier."; std::abort(); diff --git a/mediapipe/framework/port/BUILD b/mediapipe/framework/port/BUILD index 3249487789..9e33052ce5 100644 --- a/mediapipe/framework/port/BUILD +++ b/mediapipe/framework/port/BUILD @@ -176,6 +176,7 @@ cc_library( visibility = ["//visibility:public"], deps = [ ":status_matchers", + "//mediapipe/framework/deps:message_matchers", "@com_google_googletest//:gtest", ], ) @@ -192,6 +193,7 @@ cc_library( visibility = ["//visibility:public"], deps = [ ":status_matchers", + "//mediapipe/framework/deps:message_matchers", "//mediapipe/framework/deps:status_matchers", "@com_google_googletest//:gtest_main", ], diff --git a/mediapipe/framework/port/gmock.h b/mediapipe/framework/port/gmock.h index 288d5dbb4d..7c7fb67d67 100644 --- a/mediapipe/framework/port/gmock.h +++ b/mediapipe/framework/port/gmock.h @@ -16,5 +16,6 @@ #define MEDIAPIPE_PORT_GMOCK_H_ #include "gmock/gmock.h" +#include "mediapipe/framework/deps/message_matchers.h" #endif // MEDIAPIPE_PORT_GMOCK_H_ diff --git a/mediapipe/framework/profiler/BUILD b/mediapipe/framework/profiler/BUILD index d44380a824..4d928bb42b 100644 --- a/mediapipe/framework/profiler/BUILD +++ b/mediapipe/framework/profiler/BUILD @@ -234,7 +234,6 @@ cc_test( "//mediapipe/framework:calculator_profile_cc_proto", "//mediapipe/framework:test_calculators", "//mediapipe/framework/deps:clock", - "//mediapipe/framework/deps:message_matchers", "//mediapipe/framework/port:advanced_proto", "//mediapipe/framework/port:file_helpers", "//mediapipe/framework/port:gtest_main", diff --git a/mediapipe/framework/profiler/graph_profiler_test.cc b/mediapipe/framework/profiler/graph_profiler_test.cc index 22d926a216..c4c12beb99 100644 --- a/mediapipe/framework/profiler/graph_profiler_test.cc +++ b/mediapipe/framework/profiler/graph_profiler_test.cc @@ -28,7 +28,6 @@ #include "mediapipe/framework/tool/simulation_clock.h" #include "mediapipe/framework/tool/tag_map_helper.h" -using ::testing::EqualsProto; using ::testing::proto::Partially; namespace mediapipe { diff --git a/mediapipe/framework/profiler/graph_tracer_test.cc b/mediapipe/framework/profiler/graph_tracer_test.cc index 2370fcb4a9..80af064aa4 100644 --- a/mediapipe/framework/profiler/graph_tracer_test.cc +++ b/mediapipe/framework/profiler/graph_tracer_test.cc @@ -27,7 +27,6 @@ #include "mediapipe/framework/calculator_framework.h" #include "mediapipe/framework/calculator_profile.pb.h" #include "mediapipe/framework/deps/clock.h" -#include "mediapipe/framework/deps/message_matchers.h" #include "mediapipe/framework/port/advanced_proto_inc.h" #include "mediapipe/framework/port/file_helpers.h" #include "mediapipe/framework/port/gmock.h" diff --git a/mediapipe/framework/profiler/trace_builder.cc b/mediapipe/framework/profiler/trace_builder.cc index 6797cd0d9f..7381072e2d 100644 --- a/mediapipe/framework/profiler/trace_builder.cc +++ b/mediapipe/framework/profiler/trace_builder.cc @@ -85,7 +85,7 @@ void BasicTraceEventTypes(TraceEventRegistry* result) { {TraceEvent::PACKET_QUEUED, "An input queue size when a packet arrives.", true, true, false}, }; - for (TraceEventType t : basic_types) { + for (const TraceEventType& t : basic_types) { (*result)[t.event_type()] = t; } } diff --git a/mediapipe/framework/tool/BUILD b/mediapipe/framework/tool/BUILD index 5ac353c1ed..afc24feccd 100644 --- a/mediapipe/framework/tool/BUILD +++ b/mediapipe/framework/tool/BUILD @@ -162,7 +162,6 @@ cc_test( visibility = ["//mediapipe/framework:mediapipe_internal"], deps = [ ":executor_util", - "//mediapipe/framework/deps:message_matchers", "//mediapipe/framework/port:gtest_main", "//mediapipe/framework/port:parse_text_proto", ], @@ -302,7 +301,6 @@ mediapipe_cc_test( "//mediapipe/framework:calculator_framework", "//mediapipe/framework:calculator_runner", "//mediapipe/framework:validated_graph_config", - "//mediapipe/framework/deps:message_matchers", "//mediapipe/framework/port:gtest_main", "//mediapipe/framework/port:parse_text_proto", "//mediapipe/framework/port:status", @@ -449,6 +447,7 @@ cc_library( "//mediapipe/framework/port:status", "//mediapipe/framework/port:statusor", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/container:btree", "@com_google_absl//absl/memory", "@com_google_absl//absl/strings", ], @@ -613,7 +612,6 @@ cc_test( deps = [ ":validate_name", "//mediapipe/framework:calculator_cc_proto", - "//mediapipe/framework/deps:message_matchers", "//mediapipe/framework/port:gtest_main", "@com_google_absl//absl/strings", ], @@ -736,7 +734,6 @@ cc_test( "//mediapipe/framework:packet_type", "//mediapipe/framework:status_handler", "//mediapipe/framework:subgraph", - "//mediapipe/framework/deps:message_matchers", "//mediapipe/framework/port:gtest_main", "//mediapipe/framework/port:logging", "//mediapipe/framework/port:parse_text_proto", @@ -885,7 +882,6 @@ cc_test( "//mediapipe/framework:calculator_framework", "//mediapipe/framework:subgraph", "//mediapipe/framework:test_calculators", - "//mediapipe/framework/deps:message_matchers", "//mediapipe/framework/port:gtest_main", "//mediapipe/framework/port:logging", "//mediapipe/framework/port:parse_text_proto", diff --git a/mediapipe/framework/tool/executor_util_test.cc b/mediapipe/framework/tool/executor_util_test.cc index d001fb4ca2..9ea98b7c3b 100644 --- a/mediapipe/framework/tool/executor_util_test.cc +++ b/mediapipe/framework/tool/executor_util_test.cc @@ -14,7 +14,6 @@ #include "mediapipe/framework/tool/executor_util.h" -#include "mediapipe/framework/deps/message_matchers.h" #include "mediapipe/framework/port/gmock.h" #include "mediapipe/framework/port/gtest.h" #include "mediapipe/framework/port/parse_text_proto.h" diff --git a/mediapipe/framework/tool/options_util_test.cc b/mediapipe/framework/tool/options_util_test.cc index f3dc14b077..870865b1f4 100644 --- a/mediapipe/framework/tool/options_util_test.cc +++ b/mediapipe/framework/tool/options_util_test.cc @@ -17,7 +17,7 @@ #include "absl/strings/string_view.h" #include "mediapipe/framework/calculator_framework.h" -#include "mediapipe/framework/deps/message_matchers.h" +#include "mediapipe/framework/port/gmock.h" #include "mediapipe/framework/port/gtest.h" #include "mediapipe/framework/port/parse_text_proto.h" #include "mediapipe/framework/port/status_matchers.h" diff --git a/mediapipe/framework/tool/subgraph_expansion_test.cc b/mediapipe/framework/tool/subgraph_expansion_test.cc index 549c127cdd..b4f58a42ec 100644 --- a/mediapipe/framework/tool/subgraph_expansion_test.cc +++ b/mediapipe/framework/tool/subgraph_expansion_test.cc @@ -18,7 +18,6 @@ #include "absl/strings/str_cat.h" #include "mediapipe/framework/calculator.pb.h" #include "mediapipe/framework/calculator_framework.h" -#include "mediapipe/framework/deps/message_matchers.h" #include "mediapipe/framework/graph_service_manager.h" #include "mediapipe/framework/packet.h" #include "mediapipe/framework/packet_set.h" diff --git a/mediapipe/framework/tool/switch_container_test.cc b/mediapipe/framework/tool/switch_container_test.cc index 94e28ccb08..8f91d878c2 100644 --- a/mediapipe/framework/tool/switch_container_test.cc +++ b/mediapipe/framework/tool/switch_container_test.cc @@ -15,7 +15,6 @@ #include "absl/strings/str_replace.h" #include "mediapipe/framework/calculator.pb.h" #include "mediapipe/framework/calculator_framework.h" -#include "mediapipe/framework/deps/message_matchers.h" #include "mediapipe/framework/port/gmock.h" #include "mediapipe/framework/port/gtest.h" #include "mediapipe/framework/port/logging.h" diff --git a/mediapipe/framework/tool/tag_map.cc b/mediapipe/framework/tool/tag_map.cc index 25fb07f0e3..97ba240ea7 100644 --- a/mediapipe/framework/tool/tag_map.cc +++ b/mediapipe/framework/tool/tag_map.cc @@ -215,19 +215,16 @@ std::string TagMap::ShortDebugString() const { return output; } -bool TagMap::HasTag(const std::string& tag) const { - return mapping_.find(tag) != mapping_.end(); +bool TagMap::HasTag(const absl::string_view tag) const { + return mapping_.contains(tag); } -int TagMap::NumEntries(const std::string& tag) const { +int TagMap::NumEntries(const absl::string_view tag) const { const auto it = mapping_.find(tag); - if (it == mapping_.end()) { - return 0; - } - return it->second.count; + return it != mapping_.end() ? it->second.count : 0; } -CollectionItemId TagMap::GetId(const std::string& tag, int index) const { +CollectionItemId TagMap::GetId(const absl::string_view tag, int index) const { const auto it = mapping_.find(tag); if (it == mapping_.end()) { return CollectionItemId::GetInvalid(); @@ -248,11 +245,11 @@ std::pair TagMap::TagAndIndexFromId( return {"", -1}; } -CollectionItemId TagMap::BeginId(const std::string& tag) const { +CollectionItemId TagMap::BeginId(const absl::string_view tag) const { return GetId(tag, 0); } -CollectionItemId TagMap::EndId(const std::string& tag) const { +CollectionItemId TagMap::EndId(const absl::string_view tag) const { const auto it = mapping_.find(tag); if (it == mapping_.end()) { return CollectionItemId::GetInvalid(); diff --git a/mediapipe/framework/tool/tag_map.h b/mediapipe/framework/tool/tag_map.h index ff9f64c127..c7f3134d92 100644 --- a/mediapipe/framework/tool/tag_map.h +++ b/mediapipe/framework/tool/tag_map.h @@ -20,6 +20,8 @@ #include #include "absl/base/macros.h" +#include "absl/container/btree_map.h" +#include "absl/strings/string_view.h" #include "mediapipe/framework/collection_item_id.h" #include "mediapipe/framework/port/canonical_errors.h" #include "mediapipe/framework/port/core_proto_inc.h" @@ -72,7 +74,9 @@ class TagMap { } // Returns a reference to the mapping from tag to tag data. - const std::map& Mapping() const { return mapping_; } + const absl::btree_map& Mapping() const { + return mapping_; + } // Returns the vector of names (indexed by CollectionItemId). const std::vector& Names() const { return names_; } @@ -91,16 +95,16 @@ class TagMap { // The following functions are directly utilized by collection.h see // that file for comments. - bool HasTag(const std::string& tag) const; + bool HasTag(absl::string_view tag) const; int NumEntries() const { return num_entries_; } - int NumEntries(const std::string& tag) const; - CollectionItemId GetId(const std::string& tag, int index) const; + int NumEntries(absl::string_view tag) const; + CollectionItemId GetId(absl::string_view tag, int index) const; std::set GetTags() const; std::pair TagAndIndexFromId(CollectionItemId id) const; CollectionItemId BeginId() const { return CollectionItemId(0); } CollectionItemId EndId() const { return CollectionItemId(num_entries_); } - CollectionItemId BeginId(const std::string& tag) const; - CollectionItemId EndId(const std::string& tag) const; + CollectionItemId BeginId(absl::string_view tag) const; + CollectionItemId EndId(absl::string_view tag) const; private: // Use static factory function TagMap::Create(). @@ -122,7 +126,7 @@ class TagMap { // The total number of entries under all tags. int num_entries_; // Mapping from tag to tag data. - std::map mapping_; + absl::btree_map mapping_; // The names of the data (indexed by CollectionItemId). std::vector names_; }; diff --git a/mediapipe/framework/tool/template_parser.cc b/mediapipe/framework/tool/template_parser.cc index 24fbc369b3..90034091d4 100644 --- a/mediapipe/framework/tool/template_parser.cc +++ b/mediapipe/framework/tool/template_parser.cc @@ -37,7 +37,6 @@ #include "mediapipe/framework/tool/proto_util_lite.h" using mediapipe::proto_ns::Descriptor; -using mediapipe::proto_ns::DescriptorPool; using mediapipe::proto_ns::DynamicMessageFactory; using mediapipe::proto_ns::EnumDescriptor; using mediapipe::proto_ns::EnumValueDescriptor; @@ -1666,7 +1665,6 @@ TemplateParser::Parser::Parser() allow_partial_(false), allow_case_insensitive_field_(false), allow_unknown_field_(false), - allow_unknown_extension_(true), allow_unknown_enum_(false), allow_field_number_(false), allow_relaxed_whitespace_(false), @@ -1685,10 +1683,11 @@ bool TemplateParser::Parser::Parse(io::ZeroCopyInputStream* input, : ParserImpl::FORBID_SINGULAR_OVERWRITES; int recursion_limit = std::numeric_limits::max(); + bool allow_unknown_extension = false; MediaPipeParserImpl parser( output->GetDescriptor(), input, error_collector_, finder_, parse_info_tree_, overwrites_policy, allow_case_insensitive_field_, - allow_unknown_field_, allow_unknown_extension_, allow_unknown_enum_, + allow_unknown_field_, allow_unknown_extension, allow_unknown_enum_, allow_field_number_, allow_relaxed_whitespace_, allow_partial_, recursion_limit); return MergeUsingImpl(input, output, &parser); @@ -1703,11 +1702,12 @@ bool TemplateParser::Parser::ParseFromString(const std::string& input, bool TemplateParser::Parser::Merge(io::ZeroCopyInputStream* input, Message* output) { int recursion_limit = std::numeric_limits::max(); + bool allow_unknown_extension = false; MediaPipeParserImpl parser( output->GetDescriptor(), input, error_collector_, finder_, parse_info_tree_, ParserImpl::ALLOW_SINGULAR_OVERWRITES, allow_case_insensitive_field_, allow_unknown_field_, - allow_unknown_extension_, allow_unknown_enum_, allow_field_number_, + allow_unknown_extension, allow_unknown_enum_, allow_field_number_, allow_relaxed_whitespace_, allow_partial_, recursion_limit); return MergeUsingImpl(input, output, &parser); } @@ -1737,11 +1737,12 @@ bool TemplateParser::Parser::ParseFieldValueFromString( const std::string& input, const FieldDescriptor* field, Message* output) { io::ArrayInputStream input_stream(input.data(), input.size()); int recursion_limit = std::numeric_limits::max(); + bool allow_unknown_extension = false; ParserImpl parser( output->GetDescriptor(), &input_stream, error_collector_, finder_, parse_info_tree_, ParserImpl::ALLOW_SINGULAR_OVERWRITES, allow_case_insensitive_field_, allow_unknown_field_, - allow_unknown_extension_, allow_unknown_enum_, allow_field_number_, + allow_unknown_extension, allow_unknown_enum_, allow_field_number_, allow_relaxed_whitespace_, allow_partial_, recursion_limit); return parser.ParseField(field, output); } diff --git a/mediapipe/framework/tool/template_parser.h b/mediapipe/framework/tool/template_parser.h index c7a32d56d3..bd6834bd8a 100644 --- a/mediapipe/framework/tool/template_parser.h +++ b/mediapipe/framework/tool/template_parser.h @@ -37,10 +37,6 @@ class TemplateParser { Parser(); ~Parser(); - void set_allow_unknown_extension(bool allow_unknown_extension) { - allow_unknown_extension_ = allow_unknown_extension; - } - // Like TextFormat::Parse(). bool Parse(proto_ns::io::ZeroCopyInputStream* input, proto_ns::Message* output); @@ -103,7 +99,6 @@ class TemplateParser { bool allow_partial_; bool allow_case_insensitive_field_; bool allow_unknown_field_; - bool allow_unknown_extension_; bool allow_unknown_enum_; bool allow_field_number_; bool allow_relaxed_whitespace_; diff --git a/mediapipe/framework/tool/validate_name.cc b/mediapipe/framework/tool/validate_name.cc index d87a3063e6..bea857dd42 100644 --- a/mediapipe/framework/tool/validate_name.cc +++ b/mediapipe/framework/tool/validate_name.cc @@ -56,7 +56,7 @@ absl::Status GetTagAndNameInfo( } info->names.push_back(name); } - if (info->tags.size() > 0 && info->names.size() != info->tags.size()) { + if (!info->tags.empty() && info->names.size() != info->tags.size()) { info->tags.clear(); info->names.clear(); return absl::InvalidArgumentError(absl::StrCat( diff --git a/mediapipe/framework/tool/validate_name_test.cc b/mediapipe/framework/tool/validate_name_test.cc index 000be5bffd..d7d605f30b 100644 --- a/mediapipe/framework/tool/validate_name_test.cc +++ b/mediapipe/framework/tool/validate_name_test.cc @@ -17,7 +17,6 @@ #include "absl/strings/str_cat.h" #include "absl/strings/substitute.h" #include "mediapipe/framework/calculator.pb.h" -#include "mediapipe/framework/deps/message_matchers.h" #include "mediapipe/framework/port/gmock.h" #include "mediapipe/framework/port/gtest.h" #include "mediapipe/framework/port/status_matchers.h" diff --git a/mediapipe/framework/validated_graph_config.h b/mediapipe/framework/validated_graph_config.h index cf1f0d1b06..c5ffa45b5e 100644 --- a/mediapipe/framework/validated_graph_config.h +++ b/mediapipe/framework/validated_graph_config.h @@ -96,7 +96,7 @@ class NodeTypeInfo { // Get the input/output side packet/stream index that is the first // for the PacketTypeSets. Subsequent id's in the collection are - // guaranteed to be contiguous in the master flat array. + // guaranteed to be contiguous in the main flat array. int InputSidePacketBaseIndex() const { return input_side_packet_base_index_; } int OutputSidePacketBaseIndex() const { return output_side_packet_base_index_; @@ -154,7 +154,7 @@ class NodeTypeInfo { CalculatorContract contract_; // The base indexes of the first entry belonging to this node in - // the master flat arrays of ValidatedGraphConfig. Subsequent + // the main flat arrays of ValidatedGraphConfig. Subsequent // entries are guaranteed to be sequential and in the order of the // CollectionItemIds. // Example: diff --git a/mediapipe/framework/validated_graph_config_test.cc b/mediapipe/framework/validated_graph_config_test.cc index 64bfe2dc4a..01cfc8637b 100644 --- a/mediapipe/framework/validated_graph_config_test.cc +++ b/mediapipe/framework/validated_graph_config_test.cc @@ -9,8 +9,8 @@ #include "mediapipe/framework/api2/port.h" #include "mediapipe/framework/calculator.pb.h" #include "mediapipe/framework/calculator_framework.h" -#include "mediapipe/framework/deps/message_matchers.h" #include "mediapipe/framework/graph_service.h" +#include "mediapipe/framework/port/gmock.h" #include "mediapipe/framework/port/gtest.h" #include "mediapipe/framework/port/status_matchers.h" diff --git a/mediapipe/gpu/gl_texture_buffer.cc b/mediapipe/gpu/gl_texture_buffer.cc index 76482ce4fb..eab0f59fe9 100644 --- a/mediapipe/gpu/gl_texture_buffer.cc +++ b/mediapipe/gpu/gl_texture_buffer.cc @@ -161,15 +161,18 @@ void GlTextureBuffer::Reuse() { // sync fences; with a single-threaded executor, that means switching to // each of those contexts, grabbing its mutex. Let's do that after releasing // our own mutex. + // Likewise, if we don't have sync fences and are simulating them, WaitOnGpu + // will also require invoking the consumer context, so we should not call it + // while holding the mutex. std::unique_ptr old_consumer_sync; { absl::MutexLock lock(&consumer_sync_mutex_); - consumer_multi_sync_->WaitOnGpu(); // Reset the sync points. old_consumer_sync = std::move(consumer_multi_sync_); consumer_multi_sync_ = absl::make_unique(); producer_sync_ = nullptr; } + old_consumer_sync->WaitOnGpu(); } void GlTextureBuffer::Updated(std::shared_ptr prod_token) { diff --git a/mediapipe/gpu/gpu_shared_data_internal.cc b/mediapipe/gpu/gpu_shared_data_internal.cc index bd50bf5bf7..10edb601a5 100644 --- a/mediapipe/gpu/gpu_shared_data_internal.cc +++ b/mediapipe/gpu/gpu_shared_data_internal.cc @@ -112,7 +112,7 @@ absl::Status GpuResources::PrepareGpuNode(CalculatorNode* node) { #ifndef __EMSCRIPTEN__ // TODO Allow calculators to request a separate context. - // For now, white-list a few calculators to run in their own context. + // For now, allow a few calculators to run in their own context. bool gets_own_context = (node_type == "ImageFrameToGpuBufferCalculator") || (node_type == "GpuBufferToImageFrameCalculator") || (node_type == "GlSurfaceSinkCalculator"); diff --git a/mediapipe/java/com/google/mediapipe/mediapipe_aar.bzl b/mediapipe/java/com/google/mediapipe/mediapipe_aar.bzl index 3356eccbe4..4ffcee042e 100644 --- a/mediapipe/java/com/google/mediapipe/mediapipe_aar.bzl +++ b/mediapipe/java/com/google/mediapipe/mediapipe_aar.bzl @@ -154,7 +154,7 @@ EOF "//third_party:camerax_core", "//third_party:camerax_camera2", "//third_party:camerax_lifecycle", - "@com_google_protobuf//:protobuf_java", + "@com_google_protobuf//:protobuf_javalite", "@maven//:com_google_code_findbugs_jsr305", "@maven//:com_google_flogger_flogger", "@maven//:com_google_flogger_flogger_system_backend", @@ -252,7 +252,7 @@ def _proto_java_src_generator(name, proto_src, java_lite_out, srcs = []): native.genrule( name = name + "_proto_java_src_generator", srcs = srcs + [ - "@com_google_protobuf//:well_known_protos", + "@com_google_protobuf//:lite_well_known_protos", ], outs = [java_lite_out], cmd = "$(location @com_google_protobuf//:protoc) " + diff --git a/mediapipe/modules/objectron/calculators/filter_detection_calculator.cc b/mediapipe/modules/objectron/calculators/filter_detection_calculator.cc index 40689fe726..0f29f9ca82 100644 --- a/mediapipe/modules/objectron/calculators/filter_detection_calculator.cc +++ b/mediapipe/modules/objectron/calculators/filter_detection_calculator.cc @@ -38,7 +38,6 @@ constexpr char kDetectionsTag[] = "DETECTIONS"; constexpr char kLabelsTag[] = "LABELS"; constexpr char kLabelsCsvTag[] = "LABELS_CSV"; -using mediapipe::ContainsKey; using mediapipe::RE2; using Detections = std::vector; using Strings = std::vector; @@ -161,24 +160,24 @@ absl::Status FilterDetectionCalculator::Open(CalculatorContext* cc) { limit_labels_ = cc->InputSidePackets().HasTag(kLabelsTag) || cc->InputSidePackets().HasTag(kLabelsCsvTag); if (limit_labels_) { - Strings whitelist_labels; + Strings allowlist_labels; if (cc->InputSidePackets().HasTag(kLabelsCsvTag)) { - whitelist_labels = absl::StrSplit( + allowlist_labels = absl::StrSplit( cc->InputSidePackets().Tag(kLabelsCsvTag).Get(), ',', absl::SkipWhitespace()); - for (auto& e : whitelist_labels) { + for (auto& e : allowlist_labels) { absl::StripAsciiWhitespace(&e); } } else { - whitelist_labels = cc->InputSidePackets().Tag(kLabelsTag).Get(); + allowlist_labels = cc->InputSidePackets().Tag(kLabelsTag).Get(); } - allowed_labels_.insert(whitelist_labels.begin(), whitelist_labels.end()); + allowed_labels_.insert(allowlist_labels.begin(), allowlist_labels.end()); } if (limit_labels_ && allowed_labels_.empty()) { if (options_.fail_on_empty_labels()) { - cc->GetCounter("VideosWithEmptyLabelsWhitelist")->Increment(); + cc->GetCounter("VideosWithEmptyLabelsAllowlist")->Increment(); return tool::StatusFail( - "FilterDetectionCalculator received empty whitelist with " + "FilterDetectionCalculator received empty allowlist with " "fail_on_empty_labels = true."); } if (options_.empty_allowed_labels_means_allow_everything()) { diff --git a/mediapipe/python/calculator_graph_test.py b/mediapipe/python/calculator_graph_test.py index 657c811786..723bbbb611 100644 --- a/mediapipe/python/calculator_graph_test.py +++ b/mediapipe/python/calculator_graph_test.py @@ -211,6 +211,33 @@ def test_side_packet_graph(self): self.assertEqual( mp.packet_getter.get_uint(graph.get_output_side_packet('number')), 42) + def test_sequence_input(self): + text_config = """ + max_queue_size: 1 + input_stream: 'in' + output_stream: 'out' + node { + calculator: 'PassThroughCalculator' + input_stream: 'in' + output_stream: 'out' + } + """ + hello_world_packet = mp.packet_creator.create_string('hello world') + out = [] + graph = mp.CalculatorGraph(graph_config=text_config) + graph.observe_output_stream('out', lambda _, packet: out.append(packet)) + graph.start_run() + + sequence_size = 1000 + for i in range(sequence_size): + graph.add_packet_to_input_stream( + stream='in', packet=hello_world_packet, timestamp=i) + graph.wait_until_idle() + self.assertLen(out, sequence_size) + for i in range(sequence_size): + self.assertEqual(out[i].timestamp, i) + self.assertEqual(mp.packet_getter.get_str(out[i]), 'hello world') + if __name__ == '__main__': absltest.main() diff --git a/mediapipe/python/pybind/BUILD b/mediapipe/python/pybind/BUILD index d5183b35f2..be79e35ad1 100644 --- a/mediapipe/python/pybind/BUILD +++ b/mediapipe/python/pybind/BUILD @@ -121,6 +121,7 @@ pybind_library( "//mediapipe/framework/formats:image", "//mediapipe/framework/formats:matrix", "//mediapipe/framework/port:integral_types", + "@com_google_absl//absl/status:statusor", ], ) diff --git a/mediapipe/python/pybind/calculator_graph.cc b/mediapipe/python/pybind/calculator_graph.cc index afcf4a65c6..431c477cf4 100644 --- a/mediapipe/python/pybind/calculator_graph.cc +++ b/mediapipe/python/pybind/calculator_graph.cc @@ -165,8 +165,10 @@ void CalculatorGraphSubmodule(pybind11::module* module) { " can't be the timestamp of a Packet in a stream.") .c_str()); } + py::gil_scoped_release gil_release; RaisePyErrorIfNotOk( - self->AddPacketToInputStream(stream, packet.At(packet_timestamp))); + self->AddPacketToInputStream(stream, packet.At(packet_timestamp)), + /**acquire_gil=*/true); }, R"doc(Add a packet to a graph input stream. @@ -347,7 +349,9 @@ void CalculatorGraphSubmodule(pybind11::module* module) { calculator_graph.def( "wait_for_observed_output", [](CalculatorGraph* self) { - RaisePyErrorIfNotOk(self->WaitForObservedOutput()); + py::gil_scoped_release gil_release; + RaisePyErrorIfNotOk(self->WaitForObservedOutput(), + /**acquire_gil=*/true); }, R"doc(Wait until a packet is emitted on one of the observed output streams. diff --git a/mediapipe/python/pybind/packet_getter.cc b/mediapipe/python/pybind/packet_getter.cc index 548d777c8a..8a4c98d64d 100644 --- a/mediapipe/python/pybind/packet_getter.cc +++ b/mediapipe/python/pybind/packet_getter.cc @@ -14,6 +14,7 @@ #include "mediapipe/python/pybind/packet_getter.h" +#include "absl/status/statusor.h" #include "mediapipe/framework/formats/image.h" #include "mediapipe/framework/formats/matrix.h" #include "mediapipe/framework/packet.h" diff --git a/mediapipe/python/solutions/hands_test.py b/mediapipe/python/solutions/hands_test.py index 78b3d3e33f..b0cbbf9411 100644 --- a/mediapipe/python/solutions/hands_test.py +++ b/mediapipe/python/solutions/hands_test.py @@ -14,6 +14,7 @@ """Tests for mediapipe.python.solutions.hands.""" +import json import os import tempfile # pylint: disable=unused-import from typing import NamedTuple @@ -52,6 +53,21 @@ class HandsTest(parameterized.TestCase): + def _get_output_path(self, name): + return os.path.join(tempfile.gettempdir(), self.id().split('.')[-1] + name) + + def _landmarks_list_to_array(self, landmark_list, image_shape): + rows, cols, _ = image_shape + return np.asarray([(lmk.x * cols, lmk.y * rows, lmk.z * cols) + for lmk in landmark_list.landmark]) + + def _world_landmarks_list_to_array(self, landmark_list): + return np.asarray([(lmk.x, lmk.y, lmk.z) + for lmk in landmark_list.landmark]) + + def _assert_diff_less(self, array1, array2, threshold): + npt.assert_array_less(np.abs(array1 - array2), threshold) + def _annotate(self, frame: np.ndarray, results: NamedTuple, idx: int): for hand_landmarks in results.multi_hand_landmarks: mp_drawing.draw_landmarks( @@ -112,6 +128,91 @@ def test_multi_hands(self, static_image_mode, model_complexity, num_frames): diff_threshold = LITE_MODEL_DIFF_THRESHOLD if model_complexity == 0 else FULL_MODEL_DIFF_THRESHOLD npt.assert_array_less(prediction_error, diff_threshold) + def _process_video(self, model_complexity, video_path, + max_num_hands=1, + num_landmarks=21, + num_dimensions=3): + # Predict pose landmarks for each frame. + video_cap = cv2.VideoCapture(video_path) + landmarks_per_frame = [] + w_landmarks_per_frame = [] + with mp_hands.Hands( + static_image_mode=False, + max_num_hands=max_num_hands, + model_complexity=model_complexity, + min_detection_confidence=0.5) as hands: + while True: + # Get next frame of the video. + success, input_frame = video_cap.read() + if not success: + break + + # Run pose tracker. + input_frame = cv2.cvtColor(input_frame, cv2.COLOR_BGR2RGB) + frame_shape = input_frame.shape + result = hands.process(image=input_frame) + frame_landmarks = np.zeros([max_num_hands, + num_landmarks, num_dimensions]) * np.nan + frame_w_landmarks = np.zeros([max_num_hands, + num_landmarks, num_dimensions]) * np.nan + + if result.multi_hand_landmarks: + for idx, landmarks in enumerate(result.multi_hand_landmarks): + landmarks = self._landmarks_list_to_array(landmarks, frame_shape) + frame_landmarks[idx] = landmarks + if result.multi_hand_world_landmarks: + for idx, w_landmarks in enumerate(result.multi_hand_world_landmarks): + w_landmarks = self._world_landmarks_list_to_array(w_landmarks) + frame_w_landmarks[idx] = w_landmarks + + landmarks_per_frame.append(frame_landmarks) + w_landmarks_per_frame.append(frame_w_landmarks) + return (np.array(landmarks_per_frame), np.array(w_landmarks_per_frame)) + + @parameterized.named_parameters( + ('full', 1, 'asl_hand.full.npz')) + def test_on_video(self, model_complexity, expected_name): + """Tests hand models on a video.""" + + # Set threshold for comparing actual and expected predictions in pixels. + diff_threshold = 18 + world_diff_threshold = 0.05 + + video_path = os.path.join(os.path.dirname(__file__), + 'testdata/asl_hand.25fps.mp4') + expected_path = os.path.join(os.path.dirname(__file__), + 'testdata/{}'.format(expected_name)) + actual, actual_world = self._process_video(model_complexity, video_path) + + # Dump actual .npz. + npz_path = self._get_output_path(expected_name) + np.savez(npz_path, predictions=actual, w_predictions=actual_world) + + # Dump actual JSON. + json_path = self._get_output_path(expected_name.replace('.npz', '.json')) + with open(json_path, 'w') as fl: + dump_data = { + 'predictions': np.around(actual, 3).tolist(), + 'predictions_world': np.around(actual_world, 3).tolist() + } + fl.write(json.dumps(dump_data, indent=2, separators=(',', ': '))) + + # Validate actual vs. expected landmarks. + expected = np.load(expected_path)['predictions'] + assert actual.shape == expected.shape, ( + 'Unexpected shape of predictions: {} instead of {}'.format( + actual.shape, expected.shape)) + self._assert_diff_less( + actual[..., :2], expected[..., :2], threshold=diff_threshold) + + # Validate actual vs. expected world landmarks. + expected_world = np.load(expected_path)['w_predictions'] + assert actual_world.shape == expected_world.shape, ( + 'Unexpected shape of world predictions: {} instead of {}'.format( + actual_world.shape, expected_world.shape)) + self._assert_diff_less( + actual_world, expected_world, threshold=world_diff_threshold) + if __name__ == '__main__': absltest.main() diff --git a/mediapipe/util/BUILD b/mediapipe/util/BUILD index 9a90c06598..a1b179a3a9 100644 --- a/mediapipe/util/BUILD +++ b/mediapipe/util/BUILD @@ -269,7 +269,6 @@ cc_library( ":time_series_util", "//mediapipe/framework:calculator_framework", "//mediapipe/framework:calculator_runner", - "//mediapipe/framework/deps:message_matchers", "//mediapipe/framework/formats:matrix", "//mediapipe/framework/formats:time_series_header_cc_proto", "//mediapipe/framework/port:gtest_main", @@ -289,7 +288,6 @@ cc_test( deps = [ ":time_series_util", "//mediapipe/framework:calculator_framework", - "//mediapipe/framework/deps:message_matchers", "//mediapipe/framework/formats:time_series_header_cc_proto", "//mediapipe/framework/port:gtest_main", "@eigen_archive//:eigen3", diff --git a/mediapipe/util/cpu_util.cc b/mediapipe/util/cpu_util.cc index 7c6f982eb0..c1be9793bf 100644 --- a/mediapipe/util/cpu_util.cc +++ b/mediapipe/util/cpu_util.cc @@ -27,6 +27,7 @@ #include "absl/algorithm/container.h" #include "absl/flags/flag.h" +#include "absl/strings/match.h" #include "absl/strings/numbers.h" #include "absl/strings/str_cat.h" #include "absl/strings/substitute.h" @@ -45,8 +46,7 @@ namespace { constexpr uint32 kBufferLength = 64; absl::StatusOr GetFilePath(int cpu) { - if (absl::GetFlag(FLAGS_system_cpu_max_freq_file).find("$0") == - std::string::npos) { + if (!absl::StrContains(absl::GetFlag(FLAGS_system_cpu_max_freq_file), "$0")) { return absl::InvalidArgumentError( absl::StrCat("Invalid frequency file: ", absl::GetFlag(FLAGS_system_cpu_max_freq_file))); diff --git a/mediapipe/util/time_series_test_util.h b/mediapipe/util/time_series_test_util.h index bf1a0a4614..81c6d61a59 100644 --- a/mediapipe/util/time_series_test_util.h +++ b/mediapipe/util/time_series_test_util.h @@ -25,7 +25,6 @@ #include "absl/strings/substitute.h" #include "mediapipe/framework/calculator_framework.h" #include "mediapipe/framework/calculator_runner.h" -#include "mediapipe/framework/deps/message_matchers.h" #include "mediapipe/framework/formats/matrix.h" #include "mediapipe/framework/formats/time_series_header.pb.h" #include "mediapipe/framework/port/gmock.h" diff --git a/mediapipe/util/time_series_util_test.cc b/mediapipe/util/time_series_util_test.cc index dc8f3b9177..807bc4f036 100644 --- a/mediapipe/util/time_series_util_test.cc +++ b/mediapipe/util/time_series_util_test.cc @@ -16,7 +16,6 @@ #include "Eigen/Core" #include "mediapipe/framework/calculator_framework.h" -#include "mediapipe/framework/deps/message_matchers.h" #include "mediapipe/framework/formats/time_series_header.pb.h" #include "mediapipe/framework/port/gmock.h" #include "mediapipe/framework/port/gtest.h" diff --git a/mediapipe/util/tracking/BUILD b/mediapipe/util/tracking/BUILD index 7d5156049e..8f4f6b9496 100644 --- a/mediapipe/util/tracking/BUILD +++ b/mediapipe/util/tracking/BUILD @@ -716,7 +716,6 @@ cc_test( deps = [ ":motion_estimation", ":motion_models", - "//mediapipe/framework/deps:message_matchers", "//mediapipe/framework/port:gtest_main", "//mediapipe/framework/port:parse_text_proto", "//mediapipe/framework/port:vector", diff --git a/mediapipe/util/tracking/box_tracker.cc b/mediapipe/util/tracking/box_tracker.cc index 7c5cd2b94b..d5c721c667 100644 --- a/mediapipe/util/tracking/box_tracker.cc +++ b/mediapipe/util/tracking/box_tracker.cc @@ -501,7 +501,7 @@ bool BoxTracker::GetTimedPosition(int id, int64 time_msec, TimedBox* result, absl::MutexLock lock(&path_mutex_); const Path& path = paths_[id]; - if (path.size() < 1) { + if (path.empty()) { LOG(ERROR) << "Empty path!"; return false; } diff --git a/mediapipe/util/tracking/motion_models_test.cc b/mediapipe/util/tracking/motion_models_test.cc index 194aedcb63..537ed2e52f 100644 --- a/mediapipe/util/tracking/motion_models_test.cc +++ b/mediapipe/util/tracking/motion_models_test.cc @@ -14,7 +14,6 @@ #include "mediapipe/util/tracking/motion_models.h" -#include "mediapipe/framework/deps/message_matchers.h" #include "mediapipe/framework/port/gmock.h" #include "mediapipe/framework/port/gtest.h" #include "mediapipe/framework/port/parse_text_proto.h" diff --git a/requirements.txt b/requirements.txt index 46f0fdadb9..b37158d806 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,5 +4,3 @@ matplotlib numpy opencv-contrib-python protobuf>=3.11.4 -six -wheel diff --git a/setup.py b/setup.py index 24fb2e3766..a0368d59c8 100644 --- a/setup.py +++ b/setup.py @@ -26,28 +26,22 @@ import setuptools import setuptools.command.build_ext as build_ext +import setuptools.command.build_py as build_py import setuptools.command.install as install -# It is recommended to import setuptools prior to importing distutils to avoid -# using legacy behavior from distutils. -from distutils import spawn -import distutils.command.build as build -import distutils.command.clean as clean -__version__ = '0.8' +__version__ = 'dev' IS_WINDOWS = (platform.system() == 'Windows') MP_ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) -ROOT_INIT_PY = os.path.join(MP_ROOT_PATH, '__init__.py') MP_DIR_INIT_PY = os.path.join(MP_ROOT_PATH, 'mediapipe/__init__.py') MP_THIRD_PARTY_BUILD = os.path.join(MP_ROOT_PATH, 'third_party/BUILD') -SUBDIR_INIT_PY_FILES = [ +DIR_INIT_PY_FILES = [ + os.path.join(MP_ROOT_PATH, '__init__.py'), os.path.join(MP_ROOT_PATH, 'mediapipe/calculators/__init__.py'), os.path.join(MP_ROOT_PATH, 'mediapipe/modules/__init__.py'), os.path.join(MP_ROOT_PATH, 'mediapipe/modules/holistic_landmark/__init__.py'), os.path.join(MP_ROOT_PATH, 'mediapipe/modules/objectron/__init__.py') ] -if not os.path.exists(ROOT_INIT_PY): - open(ROOT_INIT_PY, 'w').close() def _normalize_path(path): @@ -79,7 +73,7 @@ def _get_long_description(): def _check_bazel(): """Check Bazel binary as well as its version.""" - if not spawn.find_executable('bazel'): + if not shutil.which('bazel'): sys.stderr.write('could not find bazel executable. Please install bazel to' 'build the MediaPipe Python package.') sys.exit(-1) @@ -126,28 +120,6 @@ def _modify_opencv_cmake_rule(link_opencv): build_file.close() -class ModifyInitFiles(setuptools.Command): - """Modify the init files for building MediaPipe Python package.""" - - user_options = [] - - def initialize_options(self): - pass - - def finalize_options(self): - pass - - def run(self): - # Save the original init file. - shutil.copyfile(MP_DIR_INIT_PY, _get_backup_file(MP_DIR_INIT_PY)) - mp_dir_init_file = open(MP_DIR_INIT_PY, 'a') - mp_dir_init_file.writelines( - ['\n', 'from mediapipe.python import *\n', - 'import mediapipe.python.solutions as solutions', - '\n']) - mp_dir_init_file.close() - - class GeneratePyProtos(setuptools.Command): """Generate MediaPipe Python protobuf files by Protocol Compiler.""" @@ -163,18 +135,14 @@ def run(self): if 'PROTOC' in os.environ and os.path.exists(os.environ['PROTOC']): self._protoc = os.environ['PROTOC'] else: - self._protoc = spawn.find_executable('protoc') + self._protoc = shutil.which('protoc') if self._protoc is None: sys.stderr.write( 'protoc is not found. Please run \'apt install -y protobuf' '-compiler\' (linux) or \'brew install protobuf\'(macos) to install ' 'protobuf compiler binary.') sys.exit(-1) - # Add __init__.py to make the generated py proto files visiable. - for init_py in SUBDIR_INIT_PY_FILES: - if not os.path.exists(init_py): - sys.stderr.write('adding __init__ file: %s\n' % init_py) - open(init_py, 'w').close() + self._modify_inits() # Build framework and calculator protos. for pattern in [ 'mediapipe/framework/**/*.proto', 'mediapipe/calculators/**/*.proto', @@ -198,6 +166,21 @@ def run(self): open(init_py, 'w').close() self._generate_proto(proto_file) + def _modify_inits(self): + # Add __init__.py to make the dirs indexable. + for init_py in DIR_INIT_PY_FILES: + if not os.path.exists(init_py): + sys.stderr.write('adding __init__ file: %s\n' % init_py) + open(init_py, 'w').close() + # Save the original init file. + shutil.copyfile(MP_DIR_INIT_PY, _get_backup_file(MP_DIR_INIT_PY)) + mp_dir_init_file = open(MP_DIR_INIT_PY, 'a') + mp_dir_init_file.writelines( + ['\n', 'from mediapipe.python import *\n', + 'import mediapipe.python.solutions as solutions', + '\n']) + mp_dir_init_file.close() + def _generate_proto(self, source): """Invokes the Protocol Compiler to generate a _pb2.py.""" @@ -216,8 +199,20 @@ def _generate_proto(self, source): sys.exit(-1) -class BuildBinaryGraphs(build.build): - """Build binary graphs for Python examples.""" +class BuildBinaryGraphs(build_ext.build_ext): + """Build MediaPipe solution binary graphs.""" + + user_options = build_ext.build_ext.user_options + [ + ('link-opencv', None, 'if true, build opencv from source.'), + ] + boolean_options = build_ext.build_ext.boolean_options + ['link-opencv'] + + def initialize_options(self): + self.link_opencv = False + build_ext.build_ext.initialize_options(self) + + def finalize_options(self): + build_ext.build_ext.finalize_options(self) def run(self): _check_bazel() @@ -271,7 +266,7 @@ def __init__(self, bazel_target, target_name=''): setuptools.Extension.__init__(self, ext_name, sources=[]) -class BuildBazelExtension(build_ext.build_ext): +class BuildExtension(build_ext.build_ext): """A command that runs Bazel to build a C/C++ extension.""" user_options = build_ext.build_ext.user_options + [ @@ -289,10 +284,10 @@ def finalize_options(self): def run(self): _check_bazel() for ext in self.extensions: - self.bazel_build(ext) + self._build_binary(ext) build_ext.build_ext.run(self) - def bazel_build(self, ext): + def _build_binary(self, ext): if not os.path.exists(self.build_temp): os.makedirs(self.build_temp) bazel_command = [ @@ -306,7 +301,8 @@ def bazel_build(self, ext): ] if not self.link_opencv and not IS_WINDOWS: bazel_command.append('--define=OPENCV=source') - self.spawn(bazel_command) + if subprocess.call(bazel_command) != 0: + sys.exit(-1) ext_bazel_bin_path = os.path.join('bazel-bin', ext.relpath, ext.target_name + '.so') ext_dest_path = self.get_ext_fullpath(ext.name) @@ -320,20 +316,20 @@ def bazel_build(self, ext): shutil.copy(opencv_dll, ext_dest_dir) -class Build(build.build): - """Build command that builds binary graphs and extension and does a cleanup afterwards.""" +class BuildPy(build_py.build_py): + """Build command that generates protos, builds binary graphs and extension, builds python source, and performs a cleanup afterwards.""" - user_options = build.build.user_options + [ + user_options = build_py.build_py.user_options + [ ('link-opencv', None, 'if true, use the installed opencv library.'), ] - boolean_options = build.build.boolean_options + ['link-opencv'] + boolean_options = build_py.build_py.boolean_options + ['link-opencv'] def initialize_options(self): self.link_opencv = False - build.build.initialize_options(self) + build_py.build_py.initialize_options(self) def finalize_options(self): - build.build.finalize_options(self) + build_py.build_py.finalize_options(self) def run(self): _modify_opencv_cmake_rule(self.link_opencv) @@ -344,13 +340,12 @@ def run(self): build_ext_obj.link_opencv = self.link_opencv self.run_command('build_binary_graphs') self.run_command('build_ext') - self.run_command('modify_inits') - build.build.run(self) + build_py.build_py.run(self) self.run_command('remove_generated') class Install(install.install): - """Install command that builds binary graphs and extension and does a cleanup afterwards.""" + """Install command that generates protos, builds binary graphs and extension, builds python source, and performs a cleanup afterwards.""" user_options = install.install.user_options + [ ('link-opencv', None, 'if true, use the installed opencv library.'), @@ -373,14 +368,21 @@ def run(self): build_ext_obj.link_opencv = self.link_opencv self.run_command('build_binary_graphs') self.run_command('build_ext') - self.run_command('modify_inits') install.install.run(self) self.run_command('remove_generated') -class RemoveGenerated(clean.clean): +class RemoveGenerated(setuptools.Command): """Remove the generated files.""" + user_options = [] + + def initialize_options(self): + pass + + def finalize_options(self): + pass + def run(self): for pattern in [ 'mediapipe/calculators/**/*pb2.py', @@ -409,9 +411,8 @@ def run(self): if os.path.exists(_get_backup_file(MP_THIRD_PARTY_BUILD)): os.remove(MP_THIRD_PARTY_BUILD) shutil.move(_get_backup_file(MP_THIRD_PARTY_BUILD), MP_THIRD_PARTY_BUILD) - for init_py in SUBDIR_INIT_PY_FILES: + for init_py in DIR_INIT_PY_FILES: os.remove(init_py) - clean.clean.run(self) setuptools.setup( @@ -426,11 +427,10 @@ def run(self): packages=setuptools.find_packages(exclude=['mediapipe.examples.desktop.*']), install_requires=_parse_requirements('requirements.txt'), cmdclass={ - 'build': Build, + 'build_py': BuildPy, 'gen_protos': GeneratePyProtos, - 'modify_inits': ModifyInitFiles, 'build_binary_graphs': BuildBinaryGraphs, - 'build_ext': BuildBazelExtension, + 'build_ext': BuildExtension, 'install': Install, 'remove_generated': RemoveGenerated, }, @@ -451,6 +451,7 @@ def run(self): 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: 3 :: Only', 'Topic :: Scientific/Engineering', 'Topic :: Scientific/Engineering :: Artificial Intelligence', @@ -461,5 +462,3 @@ def run(self): license='Apache 2.0', keywords='mediapipe', ) - -os.remove(ROOT_INIT_PY) diff --git a/setup_android_sdk_and_ndk.sh b/setup_android_sdk_and_ndk.sh index e574552f03..d09960684a 100644 --- a/setup_android_sdk_and_ndk.sh +++ b/setup_android_sdk_and_ndk.sh @@ -17,7 +17,7 @@ # Script to setup Android SDK and NDK. # usage: # $ cd -# $ bash ./setup_android_sdk_and_ndk.sh ~/Android/Sdk ~/Android/Ndk r19c +# $ bash ./setup_android_sdk_and_ndk.sh ~/Android/Sdk ~/Android/Ndk r21 set -e @@ -54,8 +54,8 @@ fi if [ -z $3 ] then - echo "Warning: ndk_version (argument 3) is not specified. Fallback to r19c." - ndk_version="r19c" + echo "Warning: ndk_version (argument 3) is not specified. Fallback to r21." + ndk_version="r21" fi if [ -d "$android_sdk_path" ] @@ -64,11 +64,11 @@ then else rm -rf /tmp/android_sdk/ mkdir /tmp/android_sdk/ - curl https://dl.google.com/android/repository/commandlinetools-${platform_android_sdk}-6609375_latest.zip -o /tmp/android_sdk/commandline_tools.zip + curl https://dl.google.com/android/repository/commandlinetools-${platform_android_sdk}-7583922_latest.zip -o /tmp/android_sdk/commandline_tools.zip unzip /tmp/android_sdk/commandline_tools.zip -d /tmp/android_sdk/ mkdir -p $android_sdk_path - /tmp/android_sdk/tools/bin/sdkmanager --update --sdk_root=${android_sdk_path} - /tmp/android_sdk/tools/bin/sdkmanager "build-tools;29.0.1" "platform-tools" "platforms;android-29" --sdk_root=${android_sdk_path} + /tmp/android_sdk/cmdline-tools/bin/sdkmanager --update --sdk_root=${android_sdk_path} + /tmp/android_sdk/cmdline-tools/bin/sdkmanager "build-tools;30.0.3" "platform-tools" "platforms;android-30" "extras;android;m2repository" --sdk_root=${android_sdk_path} rm -rf /tmp/android_sdk/ echo "Android SDK is now installed. Consider setting \$ANDROID_HOME environment variable to be ${android_sdk_path}" fi @@ -88,22 +88,6 @@ fi echo "Set android_ndk_repository and android_sdk_repository in WORKSPACE" workspace_file="$( cd "$(dirname "$0")" ; pwd -P )"/WORKSPACE - -ndk_block=$(grep -n 'android_ndk_repository(' $workspace_file | awk -F ":" '{print $1}') -ndk_path_line=$((ndk_block+2))'i' -sdk_block=$(grep -n 'android_sdk_repository(' $workspace_file | awk -F ":" '{print $1}') -sdk_path_line=$((sdk_block+3))'i' - -if [ $platform == "darwin" ]; then - sed -i -e "$ndk_path_line\\ - \ \ \ \ path = \"${android_ndk_path}/android-ndk-${ndk_version}\", - " $workspace_file - sed -i -e "$sdk_path_line\\ - \ \ \ \ path = \"${android_sdk_path}\", - " $workspace_file -elif [ $platform == "linux" ]; then - sed -i "$ndk_path_line \ path = \"${android_ndk_path}/android-ndk-${ndk_version}\"," $workspace_file - sed -i "$sdk_path_line \ path = \"${android_sdk_path}\"," $workspace_file -fi - +echo "android_sdk_repository(name = \"androidsdk\", path = \"${android_sdk_path}\")" >> $workspace_file +echo "android_ndk_repository(name = \"androidndk\", path = \"${android_ndk_path}/android-ndk-${ndk_version}\")" >> $workspace_file echo "Done" diff --git a/third_party/ceres_solver_compatibility_fixes.diff b/third_party/ceres_solver_compatibility_fixes.diff index 7b1abc9d66..c7a04b2e94 100644 --- a/third_party/ceres_solver_compatibility_fixes.diff +++ b/third_party/ceres_solver_compatibility_fixes.diff @@ -12,3 +12,15 @@ index ce170b2..bb5aa82 100644 + "@com_github_glog_glog//:glog", ], ) +diff --git a/bazel/ceres.bzl b/bazel/ceres.bzl +index ce170b2..8dd62c5 100644 +--- a/bazel/ceres.bzl ++++ b/bazel/ceres.bzl +@@ -116,7 +116,6 @@ CERES_SRCS = ["internal/ceres/" + filename for filename in [ + "sparse_cholesky.cc", + "sparse_matrix.cc", + "sparse_normal_cholesky_solver.cc", +- "split.cc", + "stringprintf.cc", + "subset_preconditioner.cc", + "suitesparse.cc", diff --git a/third_party/com_google_protobuf_fixes.diff b/third_party/com_google_protobuf_fixes.diff index b9bc17ea9e..c8d4f3259f 100644 --- a/third_party/com_google_protobuf_fixes.diff +++ b/third_party/com_google_protobuf_fixes.diff @@ -1,8 +1,8 @@ diff --git a/BUILD b/BUILD -index 79871d621..51b3a063f 100644 +index 1690d4219..e13ca8338 100644 --- a/BUILD +++ b/BUILD -@@ -26,7 +26,7 @@ config_setting( +@@ -19,7 +19,7 @@ exports_files(["LICENSE"]) # ZLIB configuration ################################################################################ @@ -11,7 +11,7 @@ index 79871d621..51b3a063f 100644 ################################################################################ # Protobuf Runtime Library -@@ -157,6 +157,7 @@ cc_library( +@@ -197,6 +197,7 @@ cc_library( includes = ["src/"], linkopts = LINK_OPTS, visibility = ["//visibility:public"], @@ -19,7 +19,7 @@ index 79871d621..51b3a063f 100644 ) PROTOBUF_DEPS = select({ -@@ -230,6 +231,7 @@ cc_library( +@@ -271,6 +272,7 @@ cc_library( linkopts = LINK_OPTS, visibility = ["//visibility:public"], deps = [":protobuf_lite"] + PROTOBUF_DEPS, @@ -27,63 +27,16 @@ index 79871d621..51b3a063f 100644 ) # This provides just the header files for use in projects that need to build -@@ -318,13 +320,13 @@ cc_proto_library( - - [native_cc_proto_library( - name = proto + "_cc_proto", -- deps = [proto + "_proto"], - visibility = ["//visibility:private"], -+ deps = [proto + "_proto"], - ) for proto in WELL_KNOWN_PROTO_MAP.keys()] - - cc_proto_blacklist_test( - name = "cc_proto_blacklist_test", -- deps = [proto + "_cc_proto" for proto in WELL_KNOWN_PROTO_MAP.keys()] -+ deps = [proto + "_cc_proto" for proto in WELL_KNOWN_PROTO_MAP.keys()], - ) - - ################################################################################ -@@ -900,7 +902,6 @@ py_proto_library( - py_extra_srcs = glob(["python/**/__init__.py"]), - py_libs = [ - ":python_srcs", -- "@six//:six", - ], - srcs_version = "PY2AND3", - visibility = ["//visibility:public"], -@@ -1002,7 +1003,9 @@ cc_library( - # Note: We use `native_proto_common` here because we depend on an implementation-detail of - # `proto_lang_toolchain`, which may not be available on `proto_common`. - reject_blacklisted_files = hasattr(native_proto_common, "proto_lang_toolchain_rejects_files_do_not_use_or_we_will_break_you_without_mercy") -+ - cc_toolchain_blacklisted_protos = [proto + "_proto" for proto in WELL_KNOWN_PROTO_MAP.keys()] if reject_blacklisted_files else [":well_known_protos"] -+ - proto_lang_toolchain( - name = "cc_toolchain", - blacklisted_protos = cc_toolchain_blacklisted_protos, -diff --git a/protobuf.bzl b/protobuf.bzl -index 829464d44..4ac23594b 100644 ---- a/protobuf.bzl -+++ b/protobuf.bzl -@@ -87,6 +87,8 @@ def _proto_gen_impl(ctx): - for dep in ctx.attr.deps: - import_flags += dep.proto.import_flags - deps += dep.proto.deps -+ import_flags = depset(import_flags).to_list() -+ deps = depset(deps).to_list() - - if not ctx.attr.gen_cc and not ctx.attr.gen_py and not ctx.executable.plugin: - return struct( diff --git a/src/google/protobuf/io/gzip_stream.h b/src/google/protobuf/io/gzip_stream.h -index b1ce1d36c..d5d560ea7 100644 +index f0283e86f..436c6ce4b 100644 --- a/src/google/protobuf/io/gzip_stream.h +++ b/src/google/protobuf/io/gzip_stream.h -@@ -47,10 +47,12 @@ +@@ -47,10 +47,13 @@ #include #include #include -#include -- + #include +#if HAVE_ZLIB @@ -93,48 +46,47 @@ index b1ce1d36c..d5d560ea7 100644 namespace google { namespace protobuf { namespace io { -@@ -76,8 +78,10 @@ class PROTOBUF_EXPORT GzipInputStream : public ZeroCopyInputStream { +@@ -76,8 +79,10 @@ class PROTOBUF_EXPORT GzipInputStream : public ZeroCopyInputStream { virtual ~GzipInputStream(); // Return last error message or NULL if no error. -+#if HAVE_ZLIB ++ #if HAVE_ZLIB inline const char* ZlibErrorMessage() const { return zcontext_.msg; } inline int ZlibErrorCode() const { return zerror_; } -+#endif // HAVE_ZLIB ++ #endif // HAVE_ZLIB // implements ZeroCopyInputStream ---------------------------------- - bool Next(const void** data, int* size); -@@ -90,8 +94,10 @@ class PROTOBUF_EXPORT GzipInputStream : public ZeroCopyInputStream { + bool Next(const void** data, int* size) override; +@@ -90,8 +95,10 @@ class PROTOBUF_EXPORT GzipInputStream : public ZeroCopyInputStream { ZeroCopyInputStream* sub_stream_; -+ #if HAVE_ZLIB ++ #if HAVE_ZLIB z_stream zcontext_; int zerror_; -+ #endif // HAVE_ZLIB ++ #endif // HAVE_ZLIB void* output_buffer_; void* output_position_; -@@ -142,9 +148,11 @@ class PROTOBUF_EXPORT GzipOutputStream : public ZeroCopyOutputStream { - +@@ -143,8 +150,10 @@ class PROTOBUF_EXPORT GzipOutputStream : public ZeroCopyOutputStream { virtual ~GzipOutputStream(); -+#if HAVE_ZLIB // Return last error message or NULL if no error. ++ #if HAVE_ZLIB inline const char* ZlibErrorMessage() const { return zcontext_.msg; } inline int ZlibErrorCode() const { return zerror_; } -+#endif // HAVE_ZLIB ++ #endif // HAVE_ZLIB // Flushes data written so far to zipped data in the underlying stream. // It is the caller's responsibility to flush the underlying stream if -@@ -177,8 +185,10 @@ class PROTOBUF_EXPORT GzipOutputStream : public ZeroCopyOutputStream { +@@ -177,8 +186,10 @@ class PROTOBUF_EXPORT GzipOutputStream : public ZeroCopyOutputStream { void* sub_data_; int sub_data_size_; -+#if HAVE_ZLIB ++ #if HAVE_ZLIB z_stream zcontext_; int zerror_; -+#endif //HAVE_ZLIB ++ #endif // HAVE_ZLIB void* input_buffer_; size_t input_buffer_length_; diff --git a/third_party/org_tensorflow_compatibility_fixes.diff b/third_party/org_tensorflow_compatibility_fixes.diff index ccc77709e2..1d74d45a95 100644 --- a/third_party/org_tensorflow_compatibility_fixes.diff +++ b/third_party/org_tensorflow_compatibility_fixes.diff @@ -24,13 +24,13 @@ index b7c22ae77ba..d0ba7b48b4b 100644 } } diff --git a/tensorflow/core/platform/test.h b/tensorflow/core/platform/test.h -index 94b4853a810..75589d04a60 100644 +index b598b6ee1e4..51c013a2d62 100644 --- a/tensorflow/core/platform/test.h +++ b/tensorflow/core/platform/test.h @@ -40,7 +40,6 @@ limitations under the License. - // The advantages of using gmock matchers instead of self defined matchers are // better error messages, more maintainable tests and more test coverage. - #if !defined(PLATFORM_GOOGLE) && !defined(PLATFORM_GOOGLE_ANDROID) + #if !defined(PLATFORM_GOOGLE) && !defined(PLATFORM_GOOGLE_ANDROID) && \ + !defined(PLATFORM_CHROMIUMOS) -#include #include #include