From 7c2d654d67130c4916f71f37f8b250f142b4aa6c Mon Sep 17 00:00:00 2001 From: MediaPipe Team Date: Thu, 31 Aug 2023 13:16:20 -0700 Subject: [PATCH] Convert CHECK macro to ABSL_CHECK. Chrome can't use Absl's CHECK because of collisions with its own version. PiperOrigin-RevId: 561740965 --- mediapipe/calculators/audio/BUILD | 5 + .../calculators/audio/mfcc_mel_calculators.cc | 3 +- .../rational_factor_resample_calculator.cc | 5 +- .../audio/stabilized_log_calculator.cc | 3 +- .../audio/time_series_framer_calculator.cc | 3 +- ...time_series_framer_calculator_benchmark.cc | 13 +- mediapipe/calculators/core/BUILD | 4 + .../core/matrix_multiply_calculator_test.cc | 3 +- .../core/packet_resampler_calculator.cc | 13 +- .../core/packet_thinner_calculator.cc | 20 +- .../core/packet_thinner_calculator_test.cc | 3 +- mediapipe/calculators/image/BUILD | 5 + .../image/bilateral_filter_calculator.cc | 5 +- .../image/color_convert_calculator.cc | 5 +- .../image/opencv_image_encoder_calculator.cc | 3 +- .../image/scale_image_calculator.cc | 3 +- .../calculators/image/scale_image_utils.cc | 17 +- mediapipe/calculators/tensor/BUILD | 8 + .../tensor/audio_to_tensor_calculator.cc | 5 +- .../feedback_tensors_calculator_test.cc | 3 +- .../tensor/image_to_tensor_calculator_test.cc | 3 +- .../tensor/inference_calculator_test.cc | 2 +- .../tensor/tensor_converter_calculator.cc | 9 +- .../tensors_to_detections_calculator.cc | 26 +- .../tensor/tensors_to_landmarks_calculator.cc | 2 +- mediapipe/calculators/tensorflow/BUILD | 9 +- .../tensorflow/matrix_to_tensor_calculator.cc | 3 +- .../pack_media_sequence_calculator_test.cc | 1 + .../tensor_to_image_frame_calculator.cc | 3 +- .../tensorflow/tensor_to_matrix_calculator.cc | 5 +- .../tensorflow_inference_calculator.cc | 5 +- .../tensorflow_inference_calculator_test.cc | 3 +- ...unpack_yt8m_sequence_example_calculator.cc | 3 +- .../vector_int_to_tensor_calculator.cc | 9 +- mediapipe/calculators/tflite/BUILD | 6 + .../tflite/ssd_anchors_calculator.cc | 9 +- .../tflite/tflite_converter_calculator.cc | 9 +- .../tflite/tflite_inference_calculator.cc | 12 +- ...te_tensors_to_classification_calculator.cc | 3 +- ...tflite_tensors_to_detections_calculator.cc | 51 ++-- .../tflite_tensors_to_landmarks_calculator.cc | 3 +- mediapipe/calculators/util/BUILD | 6 + .../calculators/util/association_calculator.h | 3 +- .../detections_to_render_data_calculator.cc | 13 +- .../util/labels_to_render_data_calculator.cc | 6 +- .../util/landmarks_refinement_calculator.cc | 4 +- .../util/non_max_suppression_calculator.cc | 9 +- .../util/rect_to_render_data_calculator.cc | 5 +- mediapipe/calculators/video/BUILD | 6 + .../video/box_detector_calculator.cc | 9 +- .../video/box_tracker_calculator.cc | 25 +- .../video/flow_packager_calculator.cc | 5 +- .../video/motion_analysis_calculator.cc | 26 +- mediapipe/calculators/video/tool/BUILD | 1 + .../video/tool/flow_quantizer_model.cc | 5 +- .../calculators/video/tracking_graph_test.cc | 3 +- .../video/tvl1_optical_flow_calculator.cc | 5 +- .../examples/desktop/autoflip/quality/BUILD | 5 +- .../quality/piecewise_linear_function.cc | 8 +- .../polynomial_regression_path_solver_test.cc | 5 +- .../quality/scene_camera_motion_analyzer.h | 2 +- .../scene_camera_motion_analyzer_test.cc | 4 +- .../desktop/autoflip/quality/scene_cropper.h | 2 +- mediapipe/examples/desktop/hello_world/BUILD | 1 + .../desktop/hello_world/hello_world.cc | 3 +- mediapipe/framework/BUILD | 30 +- mediapipe/framework/api2/BUILD | 3 + mediapipe/framework/api2/builder.h | 21 +- mediapipe/framework/api2/packet.h | 23 +- mediapipe/framework/api2/port.h | 5 +- mediapipe/framework/calculator_context.cc | 14 +- mediapipe/framework/calculator_context.h | 3 +- .../framework/calculator_context_manager.cc | 11 +- .../framework/calculator_context_manager.h | 7 +- mediapipe/framework/calculator_graph.cc | 16 +- mediapipe/framework/calculator_graph_test.cc | 19 +- mediapipe/framework/calculator_node.cc | 29 +- mediapipe/framework/calculator_node_test.cc | 3 +- mediapipe/framework/calculator_runner.cc | 13 +- mediapipe/framework/calculator_state.cc | 9 +- mediapipe/framework/collection.h | 17 +- mediapipe/framework/deps/BUILD | 17 +- mediapipe/framework/deps/map_util.h | 7 +- mediapipe/framework/deps/mathutil.h | 6 +- mediapipe/framework/deps/monotonic_clock.cc | 8 +- mediapipe/framework/deps/registration.h | 4 +- mediapipe/framework/deps/safe_int.h | 14 +- .../framework/deps/threadpool_pthread_impl.cc | 3 +- mediapipe/framework/deps/topologicalsorter.cc | 7 +- mediapipe/framework/deps/vector.h | 10 +- mediapipe/framework/formats/BUILD | 10 +- mediapipe/framework/formats/frame_buffer.h | 10 +- mediapipe/framework/formats/image.cc | 1 + mediapipe/framework/formats/image_frame.cc | 40 +-- .../framework/formats/image_multi_pool.cc | 17 +- mediapipe/framework/formats/image_opencv.cc | 3 +- mediapipe/framework/formats/location.cc | 23 +- .../framework/formats/location_opencv.cc | 9 +- mediapipe/framework/formats/matrix.cc | 9 +- mediapipe/framework/formats/motion/BUILD | 2 + .../formats/motion/optical_flow_field.cc | 35 +-- .../formats/motion/optical_flow_field_test.cc | 1 + mediapipe/framework/formats/tensor.cc | 7 +- mediapipe/framework/formats/tensor.h | 5 +- mediapipe/framework/formats/tensor_ahwb.cc | 25 +- mediapipe/framework/graph_output_stream.cc | 7 +- mediapipe/framework/graph_service.h | 3 +- mediapipe/framework/graph_validation_test.cc | 5 +- .../framework/input_side_packet_handler.cc | 3 +- mediapipe/framework/input_stream_handler.cc | 27 +- mediapipe/framework/input_stream_manager.cc | 7 +- mediapipe/framework/input_stream_shard.cc | 4 +- .../framework/output_side_packet_impl.cc | 5 +- mediapipe/framework/output_stream_handler.cc | 11 +- mediapipe/framework/output_stream_handler.h | 3 +- mediapipe/framework/output_stream_manager.cc | 5 +- mediapipe/framework/output_stream_poller.h | 7 +- mediapipe/framework/output_stream_shard.cc | 3 +- mediapipe/framework/output_stream_shard.h | 3 +- mediapipe/framework/packet.cc | 8 +- mediapipe/framework/packet.h | 7 +- mediapipe/framework/packet_type.h | 9 +- mediapipe/framework/port/BUILD | 1 + mediapipe/framework/port/parse_text_proto.h | 3 +- mediapipe/framework/profiler/BUILD | 2 + .../framework/profiler/gl_context_profiler.cc | 1 + .../framework/profiler/graph_profiler.cc | 15 +- .../framework/profiler/graph_tracer_test.cc | 13 +- mediapipe/framework/scheduler.cc | 32 ++- mediapipe/framework/scheduler_queue.cc | 30 +- mediapipe/framework/stream_handler/BUILD | 17 +- .../barrier_input_stream_handler.cc | 10 +- .../barrier_input_stream_handler_test.cc | 3 +- .../early_close_input_stream_handler.cc | 14 +- .../fixed_size_input_stream_handler.cc | 6 +- .../immediate_input_stream_handler.cc | 4 +- .../immediate_input_stream_handler_test.cc | 5 +- .../in_order_output_stream_handler.cc | 11 +- .../mux_input_stream_handler.cc | 26 +- .../sync_set_input_stream_handler.cc | 13 +- .../timestamp_align_input_stream_handler.cc | 18 +- mediapipe/framework/test_calculators.cc | 15 +- mediapipe/framework/timestamp.cc | 5 +- mediapipe/framework/timestamp.h | 5 +- mediapipe/framework/tool/BUILD | 14 +- mediapipe/framework/tool/message_type_util.cc | 5 +- mediapipe/framework/tool/proto_util_lite.cc | 3 +- mediapipe/framework/tool/sink.cc | 32 +-- mediapipe/framework/tool/sink.h | 6 +- mediapipe/framework/tool/status_util.cc | 1 + mediapipe/framework/tool/switch_container.cc | 11 +- mediapipe/framework/tool/template_expander.cc | 7 +- mediapipe/framework/tool/template_parser.cc | 10 +- mediapipe/framework/tool/test_util.cc | 12 +- mediapipe/framework/tool/validate_type.cc | 3 +- mediapipe/framework/type_map.h | 10 +- mediapipe/framework/validated_graph_config.cc | 3 +- mediapipe/gpu/BUILD | 16 +- mediapipe/gpu/MPPMetalHelper.mm | 7 +- mediapipe/gpu/cv_pixel_buffer_pool_wrapper.cc | 9 +- mediapipe/gpu/cv_texture_cache_manager.cc | 9 +- mediapipe/gpu/gl_calculator_helper.cc | 15 +- mediapipe/gpu/gl_context.cc | 29 +- mediapipe/gpu/gl_context.h | 3 +- mediapipe/gpu/gl_context_egl.cc | 4 +- mediapipe/gpu/gl_context_webgl.cc | 3 +- mediapipe/gpu/gl_texture_buffer.cc | 25 +- mediapipe/gpu/gpu_buffer.cc | 10 +- mediapipe/gpu/gpu_buffer.h | 4 +- mediapipe/gpu/gpu_buffer_format.cc | 9 +- .../gpu/gpu_buffer_storage_cv_pixel_buffer.cc | 19 +- .../gpu/gpu_buffer_storage_image_frame.cc | 3 +- mediapipe/gpu/gpu_buffer_storage_yuv_image.cc | 18 +- mediapipe/gpu/gpu_shared_data_internal.cc | 3 +- .../object_detection_3d/calculators/BUILD | 1 + .../gl_animation_overlay_calculator.cc | 7 +- .../com/google/mediapipe/framework/jni/BUILD | 1 + .../framework/jni/surface_output_jni.cc | 5 +- mediapipe/modules/objectron/calculators/BUILD | 9 + .../modules/objectron/calculators/box.cc | 9 +- .../modules/objectron/calculators/box_util.cc | 3 +- .../modules/objectron/calculators/decoder.cc | 13 +- .../modules/objectron/calculators/epnp.cc | 4 +- .../calculators/frame_annotation_tracker.cc | 3 +- .../frame_annotation_tracker_test.cc | 3 +- .../modules/objectron/calculators/model.cc | 7 +- .../objectron/calculators/tensor_util.cc | 12 +- .../tensors_to_objects_calculator.cc | 3 +- .../tflite_tensors_to_objects_calculator.cc | 3 +- mediapipe/objc/BUILD | 1 + mediapipe/objc/util.cc | 7 +- .../tasks/cc/components/calculators/BUILD | 1 + .../ragged/ragged_tensor_to_tensor_tflite.cc | 8 +- .../text/language_detector/custom_ops/BUILD | 2 + .../kmeans_embedding_lookup_test.cc | 5 +- .../custom_ops/ngram_hash_test.cc | 5 +- mediapipe/tasks/cc/text/text_embedder/BUILD | 1 + .../text/text_embedder/text_embedder_graph.cc | 3 +- mediapipe/tasks/cc/text/tokenizers/BUILD | 4 + .../text/tokenizers/sentencepiece_tokenizer.h | 14 +- .../face_detector/face_detector_graph_test.cc | 6 +- .../face_detector/face_detector_test.cc | 6 +- .../cc/vision/face_stylizer/calculators/BUILD | 1 + .../tensors_to_image_calculator.cc | 5 +- .../hand_detector/hand_detector_graph_test.cc | 5 +- .../vision/hand_landmarker/calculators/BUILD | 1 + .../hand_association_calculator.cc | 5 +- .../cc/vision/image_generator/diffuser/BUILD | 2 +- .../diffusion_plugins_output_calculator.cc | 4 +- .../pose_detector/pose_detector_graph_test.cc | 11 +- mediapipe/tasks/cc/vision/utils/BUILD | 1 + .../vision/utils/image_tensor_specs_test.cc | 3 +- mediapipe/util/BUILD | 6 + mediapipe/util/android/BUILD | 2 +- mediapipe/util/android/asset_manager_util.cc | 4 +- mediapipe/util/annotation_renderer.cc | 117 ++++---- mediapipe/util/audio_decoder.cc | 27 +- mediapipe/util/filtering/BUILD | 3 +- .../filtering/relative_velocity_filter.cc | 6 +- .../relative_velocity_filter_test.cc | 3 +- mediapipe/util/frame_buffer/BUILD | 1 + .../frame_buffer/frame_buffer_util_test.cc | 7 +- mediapipe/util/image_frame_util.cc | 17 +- mediapipe/util/resource_cache.h | 5 +- mediapipe/util/sequence/BUILD | 2 + mediapipe/util/sequence/media_sequence.cc | 5 +- mediapipe/util/sequence/media_sequence_util.h | 9 +- mediapipe/util/tflite/BUILD | 1 + mediapipe/util/tflite/cpu_op_resolver.cc | 3 +- mediapipe/util/time_series_test_util.h | 3 +- mediapipe/util/time_series_util.cc | 7 +- mediapipe/util/tracking/BUILD | 25 +- mediapipe/util/tracking/box_detector.cc | 23 +- mediapipe/util/tracking/box_tracker.cc | 33 +-- mediapipe/util/tracking/camera_motion.cc | 9 +- mediapipe/util/tracking/camera_motion.h | 9 +- mediapipe/util/tracking/flow_packager.cc | 117 ++++---- mediapipe/util/tracking/image_util.cc | 7 +- mediapipe/util/tracking/image_util.h | 5 +- mediapipe/util/tracking/measure_time.h | 4 +- mediapipe/util/tracking/motion_analysis.cc | 49 ++-- mediapipe/util/tracking/motion_estimation.cc | 262 +++++++++--------- mediapipe/util/tracking/motion_models.cc | 45 +-- mediapipe/util/tracking/motion_models.h | 35 +-- mediapipe/util/tracking/motion_models_cv.cc | 4 +- mediapipe/util/tracking/motion_saliency.cc | 39 +-- mediapipe/util/tracking/parallel_invoker.h | 19 +- mediapipe/util/tracking/push_pull_filtering.h | 53 ++-- mediapipe/util/tracking/region_flow.cc | 62 +++-- mediapipe/util/tracking/region_flow.h | 31 ++- .../util/tracking/region_flow_computation.cc | 213 +++++++------- .../tracking/region_flow_computation_test.cc | 7 +- .../tracking/region_flow_visualization.cc | 9 +- mediapipe/util/tracking/streaming_buffer.cc | 11 +- mediapipe/util/tracking/streaming_buffer.h | 28 +- mediapipe/util/tracking/tone_estimation.cc | 21 +- mediapipe/util/tracking/tone_estimation.h | 13 +- mediapipe/util/tracking/tone_models.cc | 11 +- mediapipe/util/tracking/tone_models.h | 13 +- mediapipe/util/tracking/tracking.cc | 137 ++++----- mediapipe/util/tracking/tracking.h | 9 +- .../tracking_visualization_utilities.cc | 9 +- 262 files changed, 1881 insertions(+), 1474 deletions(-) diff --git a/mediapipe/calculators/audio/BUILD b/mediapipe/calculators/audio/BUILD index f72e88199..c12583e5b 100644 --- a/mediapipe/calculators/audio/BUILD +++ b/mediapipe/calculators/audio/BUILD @@ -146,6 +146,7 @@ cc_library( "//mediapipe/framework/port:logging", "//mediapipe/framework/port:status", "//mediapipe/util:time_series_util", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", "@com_google_audio_tools//audio/dsp/mfcc", "@eigen_archive//:eigen3", @@ -165,6 +166,7 @@ cc_library( "//mediapipe/framework/formats:time_series_header_cc_proto", "//mediapipe/framework/port:integral_types", "//mediapipe/util:time_series_util", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", "@com_google_audio_tools//audio/dsp:resampler", @@ -186,6 +188,7 @@ cc_library( "//mediapipe/framework/port:core_proto", "//mediapipe/framework/port:status", "//mediapipe/util:time_series_util", + "@com_google_absl//absl/log:absl_check", ], alwayslink = 1, ) @@ -225,6 +228,7 @@ cc_library( "//mediapipe/framework/formats:time_series_header_cc_proto", "//mediapipe/framework/port:ret_check", "//mediapipe/util:time_series_util", + "@com_google_absl//absl/log:absl_check", "@com_google_audio_tools//audio/dsp:window_functions", "@eigen_archive//:eigen3", ], @@ -329,6 +333,7 @@ cc_binary( "//mediapipe/framework:packet", "//mediapipe/framework/formats:matrix", "//mediapipe/framework/formats:time_series_header_cc_proto", + "@com_google_absl//absl/log:absl_check", "@com_google_benchmark//:benchmark", ], ) diff --git a/mediapipe/calculators/audio/mfcc_mel_calculators.cc b/mediapipe/calculators/audio/mfcc_mel_calculators.cc index a63b9d6ea..ec936c844 100644 --- a/mediapipe/calculators/audio/mfcc_mel_calculators.cc +++ b/mediapipe/calculators/audio/mfcc_mel_calculators.cc @@ -23,6 +23,7 @@ #include #include "Eigen/Core" +#include "absl/log/absl_check.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" #include "absl/strings/substitute.h" @@ -138,7 +139,7 @@ absl::Status FramewiseTransformCalculatorBase::Process(CalculatorContext* cc) { TransformFrame(input_frame, &output_frame); // Copy output from vector to Eigen::Vector. - CHECK_EQ(output_frame.size(), num_output_channels_); + ABSL_CHECK_EQ(output_frame.size(), num_output_channels_); Eigen::Map output_frame_map(&output_frame[0], output_frame.size(), 1); output->col(frame) = output_frame_map.cast(); diff --git a/mediapipe/calculators/audio/rational_factor_resample_calculator.cc b/mediapipe/calculators/audio/rational_factor_resample_calculator.cc index b5e2cca58..e01bf5269 100644 --- a/mediapipe/calculators/audio/rational_factor_resample_calculator.cc +++ b/mediapipe/calculators/audio/rational_factor_resample_calculator.cc @@ -16,6 +16,7 @@ #include "mediapipe/calculators/audio/rational_factor_resample_calculator.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "audio/dsp/resampler_q.h" @@ -46,9 +47,9 @@ void CopyVectorToChannel(const std::vector& vec, Matrix* matrix, if (matrix->cols() == 0) { matrix->resize(matrix->rows(), vec.size()); } else { - CHECK_EQ(vec.size(), matrix->cols()); + ABSL_CHECK_EQ(vec.size(), matrix->cols()); } - CHECK_LT(channel, matrix->rows()); + ABSL_CHECK_LT(channel, matrix->rows()); matrix->row(channel) = Eigen::Map(vec.data(), vec.size()); } diff --git a/mediapipe/calculators/audio/stabilized_log_calculator.cc b/mediapipe/calculators/audio/stabilized_log_calculator.cc index 0c697a196..a7de6a37c 100644 --- a/mediapipe/calculators/audio/stabilized_log_calculator.cc +++ b/mediapipe/calculators/audio/stabilized_log_calculator.cc @@ -18,6 +18,7 @@ #include #include +#include "absl/log/absl_check.h" #include "mediapipe/calculators/audio/stabilized_log_calculator.pb.h" #include "mediapipe/framework/calculator_framework.h" #include "mediapipe/framework/formats/matrix.h" @@ -59,7 +60,7 @@ class StabilizedLogCalculator : public CalculatorBase { output_scale_ = stabilized_log_calculator_options.output_scale(); check_nonnegativity_ = stabilized_log_calculator_options.check_nonnegativity(); - CHECK_GE(stabilizer_, 0.0) + ABSL_CHECK_GE(stabilizer_, 0.0) << "stabilizer must be >= 0.0, received a value of " << stabilizer_; // If the input packets have a header, propagate the header to the output. diff --git a/mediapipe/calculators/audio/time_series_framer_calculator.cc b/mediapipe/calculators/audio/time_series_framer_calculator.cc index 2911c5720..d8cda5149 100644 --- a/mediapipe/calculators/audio/time_series_framer_calculator.cc +++ b/mediapipe/calculators/audio/time_series_framer_calculator.cc @@ -18,6 +18,7 @@ #include #include "Eigen/Core" +#include "absl/log/absl_check.h" #include "audio/dsp/window_functions.h" #include "mediapipe/calculators/audio/time_series_framer_calculator.pb.h" #include "mediapipe/framework/calculator_framework.h" @@ -104,7 +105,7 @@ class TimeSeriesFramerCalculator : public CalculatorBase { // All numbers are in input samples. const int64_t current_output_frame_start = static_cast( round(cumulative_output_frames_ * average_frame_step_samples_)); - CHECK_EQ(current_output_frame_start, cumulative_completed_samples_); + ABSL_CHECK_EQ(current_output_frame_start, cumulative_completed_samples_); const int64_t next_output_frame_start = static_cast( round((cumulative_output_frames_ + 1) * average_frame_step_samples_)); return next_output_frame_start - current_output_frame_start; diff --git a/mediapipe/calculators/audio/time_series_framer_calculator_benchmark.cc b/mediapipe/calculators/audio/time_series_framer_calculator_benchmark.cc index 28e5b62c7..6eada1ad3 100644 --- a/mediapipe/calculators/audio/time_series_framer_calculator_benchmark.cc +++ b/mediapipe/calculators/audio/time_series_framer_calculator_benchmark.cc @@ -17,6 +17,7 @@ #include #include +#include "absl/log/absl_check.h" #include "benchmark/benchmark.h" #include "mediapipe/calculators/audio/time_series_framer_calculator.pb.h" #include "mediapipe/framework/calculator_framework.h" @@ -70,7 +71,7 @@ void BM_TimeSeriesFramerCalculator(benchmark::State& state) { } // Initialize graph. mediapipe::CalculatorGraph graph; - CHECK_OK(graph.Initialize(config)); + ABSL_CHECK_OK(graph.Initialize(config)); // Prepare input header. auto header = std::make_unique(); header->set_sample_rate(kSampleRate); @@ -78,13 +79,13 @@ void BM_TimeSeriesFramerCalculator(benchmark::State& state) { state.ResumeTiming(); // Resume benchmark timing. - CHECK_OK(graph.StartRun({}, {{"input", Adopt(header.release())}})); + ABSL_CHECK_OK(graph.StartRun({}, {{"input", Adopt(header.release())}})); for (auto& packet : input_packets) { - CHECK_OK(graph.AddPacketToInputStream("input", packet)); + ABSL_CHECK_OK(graph.AddPacketToInputStream("input", packet)); } - CHECK(!graph.HasError()); - CHECK_OK(graph.CloseAllInputStreams()); - CHECK_OK(graph.WaitUntilIdle()); + ABSL_CHECK(!graph.HasError()); + ABSL_CHECK_OK(graph.CloseAllInputStreams()); + ABSL_CHECK_OK(graph.WaitUntilIdle()); } } BENCHMARK(BM_TimeSeriesFramerCalculator); diff --git a/mediapipe/calculators/core/BUILD b/mediapipe/calculators/core/BUILD index 4722dcc1b..02efc84ea 100644 --- a/mediapipe/calculators/core/BUILD +++ b/mediapipe/calculators/core/BUILD @@ -582,6 +582,7 @@ cc_library( "//mediapipe/framework/port:logging", "//mediapipe/framework/port:status", "//mediapipe/framework/tool:options_util", + "@com_google_absl//absl/log:absl_check", ], alwayslink = 1, ) @@ -597,6 +598,7 @@ cc_test( "//mediapipe/framework/formats:video_stream_header", "//mediapipe/framework/port:gtest_main", "//mediapipe/framework/port:integral_types", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", ], ) @@ -780,6 +782,7 @@ cc_library( "//mediapipe/framework/port:ret_check", "//mediapipe/framework/port:status", "//mediapipe/framework/tool:options_util", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", ], @@ -836,6 +839,7 @@ cc_test( "//mediapipe/framework/port:gtest_main", "//mediapipe/framework/port:logging", "//mediapipe/framework/tool:validate_type", + "@com_google_absl//absl/log:absl_check", "@eigen_archive//:eigen3", ], ) diff --git a/mediapipe/calculators/core/matrix_multiply_calculator_test.cc b/mediapipe/calculators/core/matrix_multiply_calculator_test.cc index e62ca8073..60976577a 100644 --- a/mediapipe/calculators/core/matrix_multiply_calculator_test.cc +++ b/mediapipe/calculators/core/matrix_multiply_calculator_test.cc @@ -16,6 +16,7 @@ #include #include "Eigen/Core" +#include "absl/log/absl_check.h" #include "mediapipe/framework/calculator_framework.h" #include "mediapipe/framework/calculator_runner.h" #include "mediapipe/framework/formats/matrix.h" @@ -209,7 +210,7 @@ TEST(MatrixMultiplyCalculatorTest, Multiply) { MatrixFromTextProto(kSamplesText, &samples); Matrix expected; MatrixFromTextProto(kExpectedText, &expected); - CHECK_EQ(samples.cols(), expected.cols()); + ABSL_CHECK_EQ(samples.cols(), expected.cols()); for (int i = 0; i < samples.cols(); ++i) { // Take a column from samples and produce a packet with just that diff --git a/mediapipe/calculators/core/packet_resampler_calculator.cc b/mediapipe/calculators/core/packet_resampler_calculator.cc index 49977444c..81a68f03f 100644 --- a/mediapipe/calculators/core/packet_resampler_calculator.cc +++ b/mediapipe/calculators/core/packet_resampler_calculator.cc @@ -16,6 +16,7 @@ #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" namespace { @@ -202,15 +203,15 @@ PacketResamplerCalculator::GetSamplingStrategy( Timestamp PacketResamplerCalculator::PeriodIndexToTimestamp( int64_t index) const { - CHECK_EQ(jitter_, 0.0); - CHECK_NE(first_timestamp_, Timestamp::Unset()); + ABSL_CHECK_EQ(jitter_, 0.0); + ABSL_CHECK_NE(first_timestamp_, Timestamp::Unset()); return first_timestamp_ + TimestampDiffFromSeconds(index / frame_rate_); } int64_t PacketResamplerCalculator::TimestampToPeriodIndex( Timestamp timestamp) const { - CHECK_EQ(jitter_, 0.0); - CHECK_NE(first_timestamp_, Timestamp::Unset()); + ABSL_CHECK_EQ(jitter_, 0.0); + ABSL_CHECK_NE(first_timestamp_, Timestamp::Unset()); return MathUtil::SafeRound( (timestamp - first_timestamp_).Seconds() * frame_rate_); } @@ -344,8 +345,8 @@ void LegacyJitterWithReflectionStrategy::UpdateNextOutputTimestampWithJitter() { next_output_timestamp_ = Timestamp(ReflectBetween( next_output_timestamp_.Value(), next_output_timestamp_min_.Value(), next_output_timestamp_max_.Value())); - CHECK_GE(next_output_timestamp_, next_output_timestamp_min_); - CHECK_LT(next_output_timestamp_, next_output_timestamp_max_); + ABSL_CHECK_GE(next_output_timestamp_, next_output_timestamp_min_); + ABSL_CHECK_LT(next_output_timestamp_, next_output_timestamp_max_); } absl::Status ReproducibleJitterWithReflectionStrategy::Open( diff --git a/mediapipe/calculators/core/packet_thinner_calculator.cc b/mediapipe/calculators/core/packet_thinner_calculator.cc index 35cd966ea..0bc5cc16d 100644 --- a/mediapipe/calculators/core/packet_thinner_calculator.cc +++ b/mediapipe/calculators/core/packet_thinner_calculator.cc @@ -17,6 +17,7 @@ #include // for ceil #include +#include "absl/log/absl_check.h" #include "mediapipe/calculators/core/packet_thinner_calculator.pb.h" #include "mediapipe/framework/calculator_context.h" #include "mediapipe/framework/calculator_framework.h" @@ -160,8 +161,8 @@ absl::Status PacketThinnerCalculator::Open(CalculatorContext* cc) { thinner_type_ = options.thinner_type(); // This check enables us to assume only two thinner types exist in Process() - CHECK(thinner_type_ == PacketThinnerCalculatorOptions::ASYNC || - thinner_type_ == PacketThinnerCalculatorOptions::SYNC) + ABSL_CHECK(thinner_type_ == PacketThinnerCalculatorOptions::ASYNC || + thinner_type_ == PacketThinnerCalculatorOptions::SYNC) << "Unsupported thinner type."; if (thinner_type_ == PacketThinnerCalculatorOptions::ASYNC) { @@ -177,7 +178,8 @@ absl::Status PacketThinnerCalculator::Open(CalculatorContext* cc) { } else { period_ = TimestampDiff(options.period()); } - CHECK_LT(TimestampDiff(0), period_) << "Specified period must be positive."; + ABSL_CHECK_LT(TimestampDiff(0), period_) + << "Specified period must be positive."; if (options.has_start_time()) { start_time_ = Timestamp(options.start_time()); @@ -189,7 +191,7 @@ absl::Status PacketThinnerCalculator::Open(CalculatorContext* cc) { end_time_ = options.has_end_time() ? Timestamp(options.end_time()) : Timestamp::Max(); - CHECK_LT(start_time_, end_time_) + ABSL_CHECK_LT(start_time_, end_time_) << "Invalid PacketThinner: start_time must be earlier than end_time"; sync_output_timestamps_ = options.sync_output_timestamps(); @@ -232,7 +234,7 @@ absl::Status PacketThinnerCalculator::Close(CalculatorContext* cc) { // Emit any saved packets before quitting. if (!saved_packet_.IsEmpty()) { // Only sync thinner should have saved packets. - CHECK_EQ(PacketThinnerCalculatorOptions::SYNC, thinner_type_); + ABSL_CHECK_EQ(PacketThinnerCalculatorOptions::SYNC, thinner_type_); if (sync_output_timestamps_) { cc->Outputs().Index(0).AddPacket( saved_packet_.At(NearestSyncTimestamp(saved_packet_.Timestamp()))); @@ -269,7 +271,7 @@ absl::Status PacketThinnerCalculator::SyncThinnerProcess( const Timestamp saved_sync = NearestSyncTimestamp(saved); const Timestamp now = cc->InputTimestamp(); const Timestamp now_sync = NearestSyncTimestamp(now); - CHECK_LE(saved_sync, now_sync); + ABSL_CHECK_LE(saved_sync, now_sync); if (saved_sync == now_sync) { // Saved Packet is in same interval as current packet. // Replace saved packet with current if it is at least as @@ -295,7 +297,7 @@ absl::Status PacketThinnerCalculator::SyncThinnerProcess( } Timestamp PacketThinnerCalculator::NearestSyncTimestamp(Timestamp now) const { - CHECK_NE(start_time_, Timestamp::Unset()) + ABSL_CHECK_NE(start_time_, Timestamp::Unset()) << "Method only valid for sync thinner calculator."; // Computation is done using int64 arithmetic. No easy way to avoid @@ -303,12 +305,12 @@ Timestamp PacketThinnerCalculator::NearestSyncTimestamp(Timestamp now) const { const int64_t now64 = now.Value(); const int64_t start64 = start_time_.Value(); const int64_t period64 = period_.Value(); - CHECK_LE(0, period64); + ABSL_CHECK_LE(0, period64); // Round now64 to its closest interval (units of period64). int64_t sync64 = (now64 - start64 + period64 / 2) / period64 * period64 + start64; - CHECK_LE(abs(now64 - sync64), period64 / 2) + ABSL_CHECK_LE(abs(now64 - sync64), period64 / 2) << "start64: " << start64 << "; now64: " << now64 << "; sync64: " << sync64; diff --git a/mediapipe/calculators/core/packet_thinner_calculator_test.cc b/mediapipe/calculators/core/packet_thinner_calculator_test.cc index 09de0ca70..69c008395 100644 --- a/mediapipe/calculators/core/packet_thinner_calculator_test.cc +++ b/mediapipe/calculators/core/packet_thinner_calculator_test.cc @@ -16,6 +16,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/strings/str_cat.h" #include "mediapipe/calculators/core/packet_thinner_calculator.pb.h" #include "mediapipe/framework/calculator_framework.h" @@ -70,7 +71,7 @@ class SimpleRunner : public CalculatorRunner { } double GetFrameRate() const { - CHECK(!Outputs().Index(0).header.IsEmpty()); + ABSL_CHECK(!Outputs().Index(0).header.IsEmpty()); return Outputs().Index(0).header.Get().frame_rate; } }; diff --git a/mediapipe/calculators/image/BUILD b/mediapipe/calculators/image/BUILD index ad6133181..18d4e2feb 100644 --- a/mediapipe/calculators/image/BUILD +++ b/mediapipe/calculators/image/BUILD @@ -97,6 +97,7 @@ cc_library( "//mediapipe/framework/port:ret_check", "//mediapipe/framework/port:source_location", "//mediapipe/framework/port:status", + "@com_google_absl//absl/log:absl_check", ], alwayslink = 1, ) @@ -125,6 +126,7 @@ cc_library( "//mediapipe/framework/port:opencv_imgcodecs", "//mediapipe/framework/port:opencv_imgproc", "//mediapipe/framework/port:status", + "@com_google_absl//absl/log:absl_check", ], alwayslink = 1, ) @@ -202,6 +204,7 @@ cc_library( "//mediapipe/framework/port:opencv_imgproc", "//mediapipe/framework/port:status", "//mediapipe/framework/port:vector", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", ] + select({ "//mediapipe/gpu:disable_gpu": [], @@ -397,6 +400,7 @@ cc_library( "//mediapipe/framework/port:logging", "//mediapipe/framework/port:ret_check", "//mediapipe/framework/port:status", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", ], ) @@ -421,6 +425,7 @@ cc_library( "//mediapipe/framework/port:ret_check", "//mediapipe/framework/port:status", "//mediapipe/util:image_frame_util", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", "@libyuv", diff --git a/mediapipe/calculators/image/bilateral_filter_calculator.cc b/mediapipe/calculators/image/bilateral_filter_calculator.cc index 88f1d4c12..3d364ad93 100644 --- a/mediapipe/calculators/image/bilateral_filter_calculator.cc +++ b/mediapipe/calculators/image/bilateral_filter_calculator.cc @@ -15,6 +15,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/strings/str_replace.h" #include "mediapipe/calculators/image/bilateral_filter_calculator.pb.h" #include "mediapipe/framework/calculator_framework.h" @@ -183,8 +184,8 @@ absl::Status BilateralFilterCalculator::Open(CalculatorContext* cc) { sigma_color_ = options_.sigma_color(); sigma_space_ = options_.sigma_space(); - CHECK_GE(sigma_color_, 0.0); - CHECK_GE(sigma_space_, 0.0); + ABSL_CHECK_GE(sigma_color_, 0.0); + ABSL_CHECK_GE(sigma_space_, 0.0); if (!use_gpu_) sigma_color_ *= 255.0; if (use_gpu_) { diff --git a/mediapipe/calculators/image/color_convert_calculator.cc b/mediapipe/calculators/image/color_convert_calculator.cc index 4781f1ea1..f8f018363 100644 --- a/mediapipe/calculators/image/color_convert_calculator.cc +++ b/mediapipe/calculators/image/color_convert_calculator.cc @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "absl/log/absl_check.h" #include "mediapipe/framework/calculator_framework.h" #include "mediapipe/framework/formats/image_frame.h" #include "mediapipe/framework/formats/image_frame_opencv.h" @@ -25,8 +26,8 @@ namespace mediapipe { namespace { void SetColorChannel(int channel, uint8 value, cv::Mat* mat) { - CHECK(mat->depth() == CV_8U); - CHECK(channel < mat->channels()); + ABSL_CHECK(mat->depth() == CV_8U); + ABSL_CHECK(channel < mat->channels()); const int step = mat->channels(); for (int r = 0; r < mat->rows; ++r) { uint8* row_ptr = mat->ptr(r); diff --git a/mediapipe/calculators/image/opencv_image_encoder_calculator.cc b/mediapipe/calculators/image/opencv_image_encoder_calculator.cc index 93ec9435f..0308b9b8c 100644 --- a/mediapipe/calculators/image/opencv_image_encoder_calculator.cc +++ b/mediapipe/calculators/image/opencv_image_encoder_calculator.cc @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "absl/log/absl_check.h" #include "mediapipe/calculators/image/opencv_image_encoder_calculator.pb.h" #include "mediapipe/framework/calculator_framework.h" #include "mediapipe/framework/formats/image_frame_opencv.h" @@ -61,7 +62,7 @@ absl::Status OpenCvImageEncoderCalculator::Open(CalculatorContext* cc) { absl::Status OpenCvImageEncoderCalculator::Process(CalculatorContext* cc) { const ImageFrame& image_frame = cc->Inputs().Index(0).Get(); - CHECK_EQ(1, image_frame.ByteDepth()); + ABSL_CHECK_EQ(1, image_frame.ByteDepth()); std::unique_ptr encoded_result = absl::make_unique(); diff --git a/mediapipe/calculators/image/scale_image_calculator.cc b/mediapipe/calculators/image/scale_image_calculator.cc index 10b14116c..1d4f980fe 100644 --- a/mediapipe/calculators/image/scale_image_calculator.cc +++ b/mediapipe/calculators/image/scale_image_calculator.cc @@ -18,6 +18,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/strings/str_cat.h" #include "absl/strings/substitute.h" @@ -509,7 +510,7 @@ absl::Status ScaleImageCalculator::ValidateImageFrame( absl::Status ScaleImageCalculator::ValidateYUVImage(CalculatorContext* cc, const YUVImage& yuv_image) { - CHECK_EQ(input_format_, ImageFormat::YCBCR420P); + ABSL_CHECK_EQ(input_format_, ImageFormat::YCBCR420P); if (!has_header_) { if (input_width_ != yuv_image.width() || input_height_ != yuv_image.height()) { diff --git a/mediapipe/calculators/image/scale_image_utils.cc b/mediapipe/calculators/image/scale_image_utils.cc index 86a53ffc5..77b7c0ece 100644 --- a/mediapipe/calculators/image/scale_image_utils.cc +++ b/mediapipe/calculators/image/scale_image_utils.cc @@ -18,6 +18,7 @@ #include +#include "absl/log/absl_check.h" #include "absl/strings/str_split.h" #include "mediapipe/framework/port/logging.h" #include "mediapipe/framework/port/ret_check.h" @@ -40,10 +41,10 @@ absl::Status FindCropDimensions(int input_width, int input_height, // const std::string& max_aspect_ratio, // int* crop_width, int* crop_height, // int* col_start, int* row_start) { - CHECK(crop_width); - CHECK(crop_height); - CHECK(col_start); - CHECK(row_start); + ABSL_CHECK(crop_width); + ABSL_CHECK(crop_height); + ABSL_CHECK(col_start); + ABSL_CHECK(row_start); double min_aspect_ratio_q = 0.0; double max_aspect_ratio_q = 0.0; @@ -83,8 +84,8 @@ absl::Status FindCropDimensions(int input_width, int input_height, // } } - CHECK_LE(*crop_width, input_width); - CHECK_LE(*crop_height, input_height); + ABSL_CHECK_LE(*crop_width, input_width); + ABSL_CHECK_LE(*crop_height, input_height); return absl::OkStatus(); } @@ -96,8 +97,8 @@ absl::Status FindOutputDimensions(int input_width, // bool preserve_aspect_ratio, // int scale_to_multiple_of, // int* output_width, int* output_height) { - CHECK(output_width); - CHECK(output_height); + ABSL_CHECK(output_width); + ABSL_CHECK(output_height); if (target_max_area > 0 && input_width * input_height > target_max_area) { preserve_aspect_ratio = true; diff --git a/mediapipe/calculators/tensor/BUILD b/mediapipe/calculators/tensor/BUILD index 2d22e02db..017ab4f39 100644 --- a/mediapipe/calculators/tensor/BUILD +++ b/mediapipe/calculators/tensor/BUILD @@ -87,6 +87,7 @@ cc_library( "//mediapipe/framework/formats:time_series_header_cc_proto", "//mediapipe/framework/port:ret_check", "//mediapipe/util:time_series_util", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/memory", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", @@ -181,6 +182,7 @@ cc_library( "//mediapipe/framework:calculator_framework", "//mediapipe/framework/api2:node", "//mediapipe/framework/formats:tensor", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/status", ], alwayslink = 1, @@ -198,6 +200,7 @@ cc_test( "//mediapipe/framework/formats:tensor", "//mediapipe/framework/port:gtest_main", "//mediapipe/framework/port:parse_text_proto", + "@com_google_absl//absl/log:absl_check", "@org_tensorflow//tensorflow/lite/c:common", ], ) @@ -656,6 +659,7 @@ cc_library( "//mediapipe/gpu:gpu_buffer_format", "//mediapipe/gpu:gpu_origin_cc_proto", "//mediapipe/util:resource_util", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings:str_format", ] + select({ "//mediapipe/gpu:disable_gpu": [], @@ -745,6 +749,7 @@ cc_library( "//mediapipe/framework/formats:tensor", "//mediapipe/framework/formats/object_detection:anchor_cc_proto", "//mediapipe/framework/port:ret_check", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings:str_format", "@com_google_absl//absl/types:span", @@ -802,6 +807,7 @@ cc_library( "//mediapipe/framework/formats:landmark_cc_proto", "//mediapipe/framework/formats:tensor", "//mediapipe/framework/port:ret_check", + "@com_google_absl//absl/log:absl_check", ], alwayslink = 1, ) @@ -994,6 +1000,7 @@ cc_library( "//mediapipe/framework/port:status", "//mediapipe/framework/port:statusor", "//mediapipe/gpu:gpu_origin_cc_proto", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", ] + select({ "//mediapipe/gpu:disable_gpu": [], @@ -1087,6 +1094,7 @@ cc_test( "//mediapipe/framework/port:parse_text_proto", "//mediapipe/util:image_test_utils", "@com_google_absl//absl/flags:flag", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/memory", "@com_google_absl//absl/strings", "@com_google_absl//absl/strings:str_format", diff --git a/mediapipe/calculators/tensor/audio_to_tensor_calculator.cc b/mediapipe/calculators/tensor/audio_to_tensor_calculator.cc index 01cc60a15..eaf593a69 100644 --- a/mediapipe/calculators/tensor/audio_to_tensor_calculator.cc +++ b/mediapipe/calculators/tensor/audio_to_tensor_calculator.cc @@ -20,6 +20,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/memory/memory.h" #include "absl/status/status.h" #include "absl/status/statusor.h" @@ -348,7 +349,7 @@ absl::Status AudioToTensorCalculator::Process(CalculatorContext* cc) { return absl::InvalidArgumentError( "The audio data should be stored in column-major."); } - CHECK(channels_match || mono_output); + ABSL_CHECK(channels_match || mono_output); const Matrix& input = channels_match ? input_frame // Mono mixdown. : input_frame.colwise().mean(); @@ -457,7 +458,7 @@ absl::Status AudioToTensorCalculator::SetupStreamingResampler( } void AudioToTensorCalculator::AppendZerosToSampleBuffer(int num_samples) { - CHECK_GE(num_samples, 0); // Ensured by `UpdateContract`. + ABSL_CHECK_GE(num_samples, 0); // Ensured by `UpdateContract`. if (num_samples == 0) { return; } diff --git a/mediapipe/calculators/tensor/feedback_tensors_calculator_test.cc b/mediapipe/calculators/tensor/feedback_tensors_calculator_test.cc index 5797cc31c..6c5e5cc4f 100644 --- a/mediapipe/calculators/tensor/feedback_tensors_calculator_test.cc +++ b/mediapipe/calculators/tensor/feedback_tensors_calculator_test.cc @@ -18,6 +18,7 @@ #include #include +#include "absl/log/absl_check.h" #include "mediapipe/calculators/tensor/feedback_tensors_calculator.pb.h" #include "mediapipe/framework/calculator.pb.h" #include "mediapipe/framework/calculator_framework.h" @@ -65,7 +66,7 @@ template Tensor MakeTensor(std::initializer_list shape, std::initializer_list values) { Tensor tensor(TensorElementType::value, shape); - CHECK_EQ(values.size(), tensor.shape().num_elements()) + ABSL_CHECK_EQ(values.size(), tensor.shape().num_elements()) << "The size of `values` is incompatible with `shape`"; absl::c_copy(values, tensor.GetCpuWriteView().buffer()); return tensor; diff --git a/mediapipe/calculators/tensor/image_to_tensor_calculator_test.cc b/mediapipe/calculators/tensor/image_to_tensor_calculator_test.cc index 409b8623c..7017c1e3a 100644 --- a/mediapipe/calculators/tensor/image_to_tensor_calculator_test.cc +++ b/mediapipe/calculators/tensor/image_to_tensor_calculator_test.cc @@ -18,6 +18,7 @@ #include #include "absl/flags/flag.h" +#include "absl/log/absl_check.h" #include "absl/memory/memory.h" #include "absl/strings/str_format.h" #include "absl/strings/substitute.h" @@ -205,7 +206,7 @@ mediapipe::ImageFormat::Format GetImageFormat(int image_channels) { } else if (image_channels == 1) { return ImageFormat::GRAY8; } - CHECK(false) << "Unsupported input image channles: " << image_channels; + ABSL_CHECK(false) << "Unsupported input image channles: " << image_channels; } Packet MakeImageFramePacket(cv::Mat input) { diff --git a/mediapipe/calculators/tensor/inference_calculator_test.cc b/mediapipe/calculators/tensor/inference_calculator_test.cc index 3662af391..2e75bb976 100644 --- a/mediapipe/calculators/tensor/inference_calculator_test.cc +++ b/mediapipe/calculators/tensor/inference_calculator_test.cc @@ -16,7 +16,7 @@ #include #include -#include "absl/log/check.h" +#include "absl/log/absl_check.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_replace.h" #include "absl/strings/string_view.h" diff --git a/mediapipe/calculators/tensor/tensor_converter_calculator.cc b/mediapipe/calculators/tensor/tensor_converter_calculator.cc index 2f98628bf..f624ed566 100644 --- a/mediapipe/calculators/tensor/tensor_converter_calculator.cc +++ b/mediapipe/calculators/tensor/tensor_converter_calculator.cc @@ -16,6 +16,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_format.h" @@ -623,7 +624,7 @@ absl::Status TensorConverterCalculator::LoadOptions(CalculatorContext* cc) { if (options.has_output_tensor_float_range()) { output_range_.emplace(options.output_tensor_float_range().min(), options.output_tensor_float_range().max()); - CHECK_GT(output_range_->second, output_range_->first); + ABSL_CHECK_GT(output_range_->second, output_range_->first); } // Custom div and sub values. @@ -641,9 +642,9 @@ absl::Status TensorConverterCalculator::LoadOptions(CalculatorContext* cc) { // Get desired way to handle input channels. max_num_channels_ = options.max_num_channels(); - CHECK_GE(max_num_channels_, 1); - CHECK_LE(max_num_channels_, 4); - CHECK_NE(max_num_channels_, 2); + ABSL_CHECK_GE(max_num_channels_, 1); + ABSL_CHECK_LE(max_num_channels_, 4); + ABSL_CHECK_NE(max_num_channels_, 2); return absl::OkStatus(); } diff --git a/mediapipe/calculators/tensor/tensors_to_detections_calculator.cc b/mediapipe/calculators/tensor/tensors_to_detections_calculator.cc index 51d2d229a..6d42226b9 100644 --- a/mediapipe/calculators/tensor/tensors_to_detections_calculator.cc +++ b/mediapipe/calculators/tensor/tensors_to_detections_calculator.cc @@ -84,7 +84,7 @@ void ConvertRawValuesToAnchors(const float* raw_anchors, int num_boxes, void ConvertAnchorsToRawValues(const std::vector& anchors, int num_boxes, float* raw_anchors) { - CHECK_EQ(anchors.size(), num_boxes); + ABSL_CHECK_EQ(anchors.size(), num_boxes); int box = 0; for (const auto& anchor : anchors) { raw_anchors[box * kNumCoordsPerBox + 0] = anchor.y_center(); @@ -704,18 +704,18 @@ absl::Status TensorsToDetectionsCalculator::LoadOptions(CalculatorContext* cc) { num_boxes_ = options_.num_boxes(); num_coords_ = options_.num_coords(); box_output_format_ = GetBoxFormat(options_); - CHECK_NE(options_.max_results(), 0) + ABSL_CHECK_NE(options_.max_results(), 0) << "The maximum number of the top-scored detection results must be " "non-zero."; max_results_ = options_.max_results(); // Currently only support 2D when num_values_per_keypoint equals to 2. - CHECK_EQ(options_.num_values_per_keypoint(), 2); + ABSL_CHECK_EQ(options_.num_values_per_keypoint(), 2); // Check if the output size is equal to the requested boxes and keypoints. - CHECK_EQ(options_.num_keypoints() * options_.num_values_per_keypoint() + - kNumCoordsPerBox, - num_coords_); + ABSL_CHECK_EQ(options_.num_keypoints() * options_.num_values_per_keypoint() + + kNumCoordsPerBox, + num_coords_); if (kSideInIgnoreClasses(cc).IsConnected()) { RET_CHECK(!kSideInIgnoreClasses(cc).IsEmpty()); @@ -1155,11 +1155,12 @@ void main() { } // TODO support better filtering. if (class_index_set_.is_allowlist) { - CHECK_EQ(class_index_set_.values.size(), - IsClassIndexAllowed(0) ? num_classes_ : num_classes_ - 1) + ABSL_CHECK_EQ(class_index_set_.values.size(), + IsClassIndexAllowed(0) ? num_classes_ : num_classes_ - 1) << "Only all classes >= class 0 or >= class 1"; } else { - CHECK_EQ(class_index_set_.values.size(), IsClassIndexAllowed(0) ? 0 : 1) + ABSL_CHECK_EQ(class_index_set_.values.size(), + IsClassIndexAllowed(0) ? 0 : 1) << "Only ignore class 0 is allowed"; } @@ -1380,11 +1381,12 @@ kernel void scoreKernel( // TODO support better filtering. if (class_index_set_.is_allowlist) { - CHECK_EQ(class_index_set_.values.size(), - IsClassIndexAllowed(0) ? num_classes_ : num_classes_ - 1) + ABSL_CHECK_EQ(class_index_set_.values.size(), + IsClassIndexAllowed(0) ? num_classes_ : num_classes_ - 1) << "Only all classes >= class 0 or >= class 1"; } else { - CHECK_EQ(class_index_set_.values.size(), IsClassIndexAllowed(0) ? 0 : 1) + ABSL_CHECK_EQ(class_index_set_.values.size(), + IsClassIndexAllowed(0) ? 0 : 1) << "Only ignore class 0 is allowed"; } diff --git a/mediapipe/calculators/tensor/tensors_to_landmarks_calculator.cc b/mediapipe/calculators/tensor/tensors_to_landmarks_calculator.cc index a1cc4e202..5942f234d 100644 --- a/mediapipe/calculators/tensor/tensors_to_landmarks_calculator.cc +++ b/mediapipe/calculators/tensor/tensors_to_landmarks_calculator.cc @@ -142,7 +142,7 @@ absl::Status TensorsToLandmarksCalculator::Process(CalculatorContext* cc) { RET_CHECK(input_tensors[0].element_type() == Tensor::ElementType::kFloat32); int num_values = input_tensors[0].shape().num_elements(); const int num_dimensions = num_values / num_landmarks_; - CHECK_GT(num_dimensions, 0); + ABSL_CHECK_GT(num_dimensions, 0); auto view = input_tensors[0].GetCpuReadView(); auto raw_landmarks = view.buffer(); diff --git a/mediapipe/calculators/tensorflow/BUILD b/mediapipe/calculators/tensorflow/BUILD index 21cc24e3a..cd4d1ad88 100644 --- a/mediapipe/calculators/tensorflow/BUILD +++ b/mediapipe/calculators/tensorflow/BUILD @@ -315,6 +315,7 @@ cc_library( "//mediapipe/framework/formats:time_series_header_cc_proto", "//mediapipe/framework/port:ret_check", "//mediapipe/framework/port:status", + "@com_google_absl//absl/log:absl_check", ] + select({ "//conditions:default": [ "@org_tensorflow//tensorflow/core:framework", @@ -429,7 +430,7 @@ cc_library( "//mediapipe/framework/port:status", "//mediapipe/framework/tool:status_util", "@com_google_absl//absl/base:core_headers", - "@com_google_absl//absl/log:check", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/memory", "@com_google_absl//absl/strings", "@com_google_absl//absl/synchronization", @@ -670,6 +671,7 @@ cc_library( "//mediapipe/framework/formats:image_frame", "//mediapipe/framework/port:ret_check", "//mediapipe/framework/port:status", + "@com_google_absl//absl/log:absl_check", "@org_tensorflow//tensorflow/core:framework", ], alwayslink = 1, @@ -685,6 +687,7 @@ cc_library( "//mediapipe/framework/formats:time_series_header_cc_proto", "//mediapipe/framework/port:ret_check", "//mediapipe/framework/port:status", + "@com_google_absl//absl/log:absl_check", ] + select({ "//conditions:default": [ "@org_tensorflow//tensorflow/core:framework", @@ -796,6 +799,7 @@ cc_library( "//mediapipe/framework:calculator_framework", "//mediapipe/framework/port:ret_check", "//mediapipe/framework/port:status", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@org_tensorflow//tensorflow/core:framework", ], @@ -838,6 +842,7 @@ cc_library( "//mediapipe/framework:calculator_framework", "//mediapipe/framework:packet", "//mediapipe/framework/port:status", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@org_tensorflow//tensorflow/core:protos_all_cc", ], @@ -945,6 +950,7 @@ cc_test( "//mediapipe/framework/port:gtest_main", "//mediapipe/framework/port:opencv_imgcodecs", "//mediapipe/util/sequence:media_sequence", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/memory", "@com_google_absl//absl/strings", "@com_google_googletest//:gtest_main", @@ -1257,6 +1263,7 @@ cc_test( "//mediapipe/framework/tool:sink", "//mediapipe/framework/tool:validate_type", "@com_google_absl//absl/flags:flag", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", ] + select({ "//conditions:default": [ diff --git a/mediapipe/calculators/tensorflow/matrix_to_tensor_calculator.cc b/mediapipe/calculators/tensorflow/matrix_to_tensor_calculator.cc index 32a0eb70b..bbd5cff3e 100644 --- a/mediapipe/calculators/tensorflow/matrix_to_tensor_calculator.cc +++ b/mediapipe/calculators/tensorflow/matrix_to_tensor_calculator.cc @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "absl/log/absl_check.h" #include "mediapipe/calculators/tensorflow/matrix_to_tensor_calculator_options.pb.h" #include "mediapipe/framework/calculator_framework.h" #include "mediapipe/framework/formats/matrix.h" @@ -28,7 +29,7 @@ namespace mediapipe { namespace { absl::Status FillTimeSeriesHeaderIfValid(const Packet& header_packet, TimeSeriesHeader* header) { - CHECK(header); + ABSL_CHECK(header); if (header_packet.IsEmpty()) { return absl::UnknownError("No header found."); } diff --git a/mediapipe/calculators/tensorflow/pack_media_sequence_calculator_test.cc b/mediapipe/calculators/tensorflow/pack_media_sequence_calculator_test.cc index a91074f07..3fb48d1e7 100644 --- a/mediapipe/calculators/tensorflow/pack_media_sequence_calculator_test.cc +++ b/mediapipe/calculators/tensorflow/pack_media_sequence_calculator_test.cc @@ -16,6 +16,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/memory/memory.h" #include "absl/strings/str_cat.h" #include "mediapipe/calculators/image/opencv_image_encoder_calculator.pb.h" diff --git a/mediapipe/calculators/tensorflow/tensor_to_image_frame_calculator.cc b/mediapipe/calculators/tensorflow/tensor_to_image_frame_calculator.cc index b5a94e014..3b4d53813 100644 --- a/mediapipe/calculators/tensorflow/tensor_to_image_frame_calculator.cc +++ b/mediapipe/calculators/tensorflow/tensor_to_image_frame_calculator.cc @@ -14,6 +14,7 @@ #include +#include "absl/log/absl_check.h" #include "mediapipe/calculators/tensorflow/tensor_to_image_frame_calculator.pb.h" #include "mediapipe/framework/calculator_framework.h" #include "mediapipe/framework/formats/image_frame.h" @@ -99,7 +100,7 @@ absl::Status TensorToImageFrameCalculator::Process(CalculatorContext* cc) { const tf::Tensor& input_tensor = cc->Inputs().Tag(kTensor).Get(); int32_t depth = 1; if (input_tensor.dims() != 2) { // Depth is 1 for 2D tensors. - CHECK(3 == input_tensor.dims()) + ABSL_CHECK(3 == input_tensor.dims()) << "Only 2 or 3-D Tensors can be converted to frames. Instead got: " << input_tensor.dims(); depth = input_tensor.dim_size(2); diff --git a/mediapipe/calculators/tensorflow/tensor_to_matrix_calculator.cc b/mediapipe/calculators/tensorflow/tensor_to_matrix_calculator.cc index 081e0c83a..dc3d97844 100644 --- a/mediapipe/calculators/tensorflow/tensor_to_matrix_calculator.cc +++ b/mediapipe/calculators/tensorflow/tensor_to_matrix_calculator.cc @@ -15,6 +15,7 @@ // Calculator converts from one-dimensional Tensor of DT_FLOAT to Matrix // OR from (batched) two-dimensional Tensor of DT_FLOAT to Matrix. +#include "absl/log/absl_check.h" #include "mediapipe/calculators/tensorflow/tensor_to_matrix_calculator.pb.h" #include "mediapipe/framework/calculator_framework.h" #include "mediapipe/framework/formats/matrix.h" @@ -36,7 +37,7 @@ constexpr char kReference[] = "REFERENCE"; absl::Status FillTimeSeriesHeaderIfValid(const Packet& header_packet, TimeSeriesHeader* header) { - CHECK(header); + ABSL_CHECK(header); if (header_packet.IsEmpty()) { return absl::UnknownError("No header found."); } @@ -191,7 +192,7 @@ absl::Status TensorToMatrixCalculator::Process(CalculatorContext* cc) { << "Tensor stream packet does not contain a Tensor."; const tf::Tensor& input_tensor = cc->Inputs().Tag(kTensor).Get(); - CHECK(1 == input_tensor.dims() || 2 == input_tensor.dims()) + ABSL_CHECK(1 == input_tensor.dims() || 2 == input_tensor.dims()) << "Only 1-D or 2-D Tensors can be converted to matrices."; const int32_t length = input_tensor.dim_size(input_tensor.dims() - 1); const int32_t width = diff --git a/mediapipe/calculators/tensorflow/tensorflow_inference_calculator.cc b/mediapipe/calculators/tensorflow/tensorflow_inference_calculator.cc index 2608b1c5b..84c32fed6 100644 --- a/mediapipe/calculators/tensorflow/tensorflow_inference_calculator.cc +++ b/mediapipe/calculators/tensorflow/tensorflow_inference_calculator.cc @@ -20,6 +20,7 @@ #include #include "absl/base/thread_annotations.h" +#include "absl/log/absl_check.h" #include "absl/memory/memory.h" #include "absl/strings/str_split.h" #include "absl/synchronization/mutex.h" @@ -515,7 +516,7 @@ class TensorFlowInferenceCalculator : public CalculatorBase { tf::Tensor concated; const tf::Status concat_status = tf::tensor::Concat(keyed_tensors.second, &concated); - CHECK(concat_status.ok()) << concat_status.ToString(); + ABSL_CHECK(concat_status.ok()) << concat_status.ToString(); input_tensors.emplace_back(tag_to_tensor_map_[keyed_tensors.first], concated); } @@ -597,7 +598,7 @@ class TensorFlowInferenceCalculator : public CalculatorBase { std::vector split_tensors; const tf::Status split_status = tf::tensor::Split(outputs[i], split_vector, &split_tensors); - CHECK(split_status.ok()) << split_status.ToString(); + ABSL_CHECK(split_status.ok()) << split_status.ToString(); // Loop over timestamps so that we don't copy the padding. for (int j = 0; j < inference_state->batch_timestamps_.size(); ++j) { tf::Tensor output_tensor(split_tensors[j]); diff --git a/mediapipe/calculators/tensorflow/tensorflow_inference_calculator_test.cc b/mediapipe/calculators/tensorflow/tensorflow_inference_calculator_test.cc index fa74c97c0..708f1711e 100644 --- a/mediapipe/calculators/tensorflow/tensorflow_inference_calculator_test.cc +++ b/mediapipe/calculators/tensorflow/tensorflow_inference_calculator_test.cc @@ -17,6 +17,7 @@ #include #include "absl/flags/flag.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "mediapipe/calculators/tensorflow/tensorflow_inference_calculator.pb.h" #include "mediapipe/calculators/tensorflow/tensorflow_session_from_frozen_graph_generator.pb.h" @@ -119,7 +120,7 @@ class TensorflowInferenceCalculatorTest : public ::testing::Test { // Create tensor from Vector and add as a Packet to the provided tag as input. void AddVectorToInputsAsPacket(const std::vector& packets, const std::string& tag) { - CHECK(!packets.empty()) + ABSL_CHECK(!packets.empty()) << "Please specify at least some data in the packet"; auto packets_ptr = absl::make_unique>(packets); runner_->MutableInputs()->Tag(tag).packets.push_back( diff --git a/mediapipe/calculators/tensorflow/unpack_yt8m_sequence_example_calculator.cc b/mediapipe/calculators/tensorflow/unpack_yt8m_sequence_example_calculator.cc index 508112e52..12f2ade02 100644 --- a/mediapipe/calculators/tensorflow/unpack_yt8m_sequence_example_calculator.cc +++ b/mediapipe/calculators/tensorflow/unpack_yt8m_sequence_example_calculator.cc @@ -14,6 +14,7 @@ #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "mediapipe/calculators/tensorflow/lapped_tensor_buffer_calculator.pb.h" #include "mediapipe/framework/calculator_framework.h" @@ -47,7 +48,7 @@ std::string GetQuantizedFeature( .Get(index) .bytes_list() .value(); - CHECK_EQ(1, bytes_list.size()); + ABSL_CHECK_EQ(1, bytes_list.size()); return bytes_list.Get(0); } } // namespace diff --git a/mediapipe/calculators/tensorflow/vector_int_to_tensor_calculator.cc b/mediapipe/calculators/tensorflow/vector_int_to_tensor_calculator.cc index 482f8c606..f4a892027 100644 --- a/mediapipe/calculators/tensorflow/vector_int_to_tensor_calculator.cc +++ b/mediapipe/calculators/tensorflow/vector_int_to_tensor_calculator.cc @@ -15,6 +15,7 @@ // Converts a single int or vector or vector> to 1D (or 2D) // tf::Tensor. +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "mediapipe/calculators/tensorflow/vector_int_to_tensor_calculator_options.pb.h" #include "mediapipe/framework/calculator_framework.h" @@ -114,11 +115,11 @@ absl::Status VectorIntToTensorCalculator::Process(CalculatorContext* cc) { .Get>>(); const int32_t rows = input.size(); - CHECK_GE(rows, 1); + ABSL_CHECK_GE(rows, 1); const int32_t cols = input[0].size(); - CHECK_GE(cols, 1); + ABSL_CHECK_GE(cols, 1); for (int i = 1; i < rows; ++i) { - CHECK_EQ(input[i].size(), cols); + ABSL_CHECK_EQ(input[i].size(), cols); } if (options_.transpose()) { tensor_shape = tf::TensorShape({cols, rows}); @@ -172,7 +173,7 @@ absl::Status VectorIntToTensorCalculator::Process(CalculatorContext* cc) { } else { input = cc->Inputs().Tag(kVectorInt).Value().Get>(); } - CHECK_GE(input.size(), 1); + ABSL_CHECK_GE(input.size(), 1); const int32_t length = input.size(); tensor_shape = tf::TensorShape({length}); auto output = ::absl::make_unique(options_.tensor_data_type(), diff --git a/mediapipe/calculators/tflite/BUILD b/mediapipe/calculators/tflite/BUILD index 7b37d7f6b..ed9f47a8b 100644 --- a/mediapipe/calculators/tflite/BUILD +++ b/mediapipe/calculators/tflite/BUILD @@ -103,6 +103,7 @@ cc_library( "//mediapipe/framework/formats/object_detection:anchor_cc_proto", "//mediapipe/framework/port:ret_check", "//mediapipe/framework/port:status", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", ], alwayslink = 1, @@ -202,6 +203,7 @@ cc_library( "//mediapipe/framework/stream_handler:fixed_size_input_stream_handler", "//mediapipe/util/tflite:config", "//mediapipe/util/tflite:tflite_model_loader", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/memory", "@org_tensorflow//tensorflow/lite:framework", @@ -278,6 +280,7 @@ cc_library( "//mediapipe/framework/stream_handler:fixed_size_input_stream_handler", "//mediapipe/util:resource_util", "//mediapipe/util/tflite:config", + "@com_google_absl//absl/log:absl_check", "@org_tensorflow//tensorflow/lite:framework", "@org_tensorflow//tensorflow/lite/kernels:builtin_ops", ] + selects.with_or({ @@ -395,6 +398,7 @@ cc_library( "//mediapipe/framework/formats/object_detection:anchor_cc_proto", "//mediapipe/framework/port:ret_check", "//mediapipe/util/tflite:config", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings:str_format", "@com_google_absl//absl/types:span", @@ -432,6 +436,7 @@ cc_library( "//mediapipe/framework/port:ret_check", "//mediapipe/util:resource_util", "@com_google_absl//absl/container:node_hash_map", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings:str_format", "@com_google_absl//absl/types:span", "@org_tensorflow//tensorflow/lite:framework", @@ -460,6 +465,7 @@ cc_library( "//mediapipe/framework:calculator_framework", "//mediapipe/framework/formats:landmark_cc_proto", "//mediapipe/framework/port:ret_check", + "@com_google_absl//absl/log:absl_check", "@org_tensorflow//tensorflow/lite:framework", ], alwayslink = 1, diff --git a/mediapipe/calculators/tflite/ssd_anchors_calculator.cc b/mediapipe/calculators/tflite/ssd_anchors_calculator.cc index 9f2649dea..d5303d65c 100644 --- a/mediapipe/calculators/tflite/ssd_anchors_calculator.cc +++ b/mediapipe/calculators/tflite/ssd_anchors_calculator.cc @@ -16,6 +16,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "mediapipe/calculators/tflite/ssd_anchors_calculator.pb.h" #include "mediapipe/framework/calculator_framework.h" @@ -275,11 +276,11 @@ absl::Status SsdAnchorsCalculator::GenerateAnchors( if (options.strides_size()) { ABSL_LOG(ERROR) << "Found feature map shapes. Strides will be ignored."; } - CHECK_EQ(options.feature_map_height_size(), kNumLayers); - CHECK_EQ(options.feature_map_height_size(), - options.feature_map_width_size()); + ABSL_CHECK_EQ(options.feature_map_height_size(), kNumLayers); + ABSL_CHECK_EQ(options.feature_map_height_size(), + options.feature_map_width_size()); } else { - CHECK_EQ(options.strides_size(), kNumLayers); + ABSL_CHECK_EQ(options.strides_size(), kNumLayers); } if (options.multiscale_anchor_generation()) { diff --git a/mediapipe/calculators/tflite/tflite_converter_calculator.cc b/mediapipe/calculators/tflite/tflite_converter_calculator.cc index ff6b2ff91..7188cbc59 100644 --- a/mediapipe/calculators/tflite/tflite_converter_calculator.cc +++ b/mediapipe/calculators/tflite/tflite_converter_calculator.cc @@ -15,6 +15,7 @@ #include #include +#include "absl/log/absl_check.h" #include "mediapipe/calculators/tflite/tflite_converter_calculator.pb.h" #include "mediapipe/framework/calculator_framework.h" #include "mediapipe/framework/formats/image_frame.h" @@ -643,7 +644,7 @@ absl::Status TfLiteConverterCalculator::LoadOptions(CalculatorContext* cc) { if (options.has_output_tensor_float_range()) { output_range_.emplace(options.output_tensor_float_range().min(), options.output_tensor_float_range().max()); - CHECK_GT(output_range_->second, output_range_->first); + ABSL_CHECK_GT(output_range_->second, output_range_->first); } // Custom div and sub values. @@ -661,9 +662,9 @@ absl::Status TfLiteConverterCalculator::LoadOptions(CalculatorContext* cc) { // Get desired way to handle input channels. max_num_channels_ = options.max_num_channels(); - CHECK_GE(max_num_channels_, 1); - CHECK_LE(max_num_channels_, 4); - CHECK_NE(max_num_channels_, 2); + ABSL_CHECK_GE(max_num_channels_, 1); + ABSL_CHECK_LE(max_num_channels_, 4); + ABSL_CHECK_NE(max_num_channels_, 2); #if defined(MEDIAPIPE_IOS) if (cc->Inputs().HasTag(kGpuBufferTag)) // Currently on iOS, tflite gpu input tensor must be 4 channels, diff --git a/mediapipe/calculators/tflite/tflite_inference_calculator.cc b/mediapipe/calculators/tflite/tflite_inference_calculator.cc index 69c7d608c..d875b6940 100644 --- a/mediapipe/calculators/tflite/tflite_inference_calculator.cc +++ b/mediapipe/calculators/tflite/tflite_inference_calculator.cc @@ -17,6 +17,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/memory/memory.h" #include "mediapipe/calculators/tflite/tflite_inference_calculator.pb.h" @@ -111,8 +112,8 @@ std::unique_ptr BuildEdgeTpuInterpreter( edgetpu::EdgeTpuContext* edgetpu_context) { resolver->AddCustom(edgetpu::kCustomOp, edgetpu::RegisterCustomOp()); std::unique_ptr interpreter; - CHECK_EQ(tflite::InterpreterBuilder(model, *resolver)(&interpreter), - kTfLiteOk); + ABSL_CHECK_EQ(tflite::InterpreterBuilder(model, *resolver)(&interpreter), + kTfLiteOk); interpreter->SetExternalContext(kTfLiteEdgeTpuContext, edgetpu_context); return interpreter; } @@ -413,7 +414,7 @@ absl::Status TfLiteInferenceCalculator::Open(CalculatorContext* cc) { "Falling back to the default TFLite API."; use_advanced_gpu_api_ = false; } - CHECK(!use_advanced_gpu_api_ || gpu_inference_); + ABSL_CHECK(!use_advanced_gpu_api_ || gpu_inference_); MP_RETURN_IF_ERROR(LoadModel(cc)); @@ -805,9 +806,10 @@ absl::Status TfLiteInferenceCalculator::InitTFLiteGPURunner( const int tensor_idx = interpreter_->inputs()[i]; interpreter_->SetTensorParametersReadWrite(tensor_idx, kTfLiteFloat32, "", shape, quant); - CHECK(interpreter_->ResizeInputTensor(tensor_idx, shape) == kTfLiteOk); + ABSL_CHECK(interpreter_->ResizeInputTensor(tensor_idx, shape) == + kTfLiteOk); } - CHECK(interpreter_->AllocateTensors() == kTfLiteOk); + ABSL_CHECK(interpreter_->AllocateTensors() == kTfLiteOk); } // Create and bind OpenGL buffers for outputs. diff --git a/mediapipe/calculators/tflite/tflite_tensors_to_classification_calculator.cc b/mediapipe/calculators/tflite/tflite_tensors_to_classification_calculator.cc index 4d28b91e9..98ab4b1da 100644 --- a/mediapipe/calculators/tflite/tflite_tensors_to_classification_calculator.cc +++ b/mediapipe/calculators/tflite/tflite_tensors_to_classification_calculator.cc @@ -17,6 +17,7 @@ #include #include "absl/container/node_hash_map.h" +#include "absl/log/absl_check.h" #include "absl/strings/str_format.h" #include "absl/types/span.h" #include "mediapipe/calculators/tflite/tflite_tensors_to_classification_calculator.pb.h" @@ -172,7 +173,7 @@ absl::Status TfLiteTensorsToClassificationCalculator::Process( // Note that partial_sort will raise error when top_k_ > // classification_list->classification_size(). - CHECK_GE(classification_list->classification_size(), top_k_); + ABSL_CHECK_GE(classification_list->classification_size(), top_k_); auto raw_classification_list = classification_list->mutable_classification(); if (top_k_ > 0 && classification_list->classification_size() >= top_k_) { std::partial_sort(raw_classification_list->begin(), diff --git a/mediapipe/calculators/tflite/tflite_tensors_to_detections_calculator.cc b/mediapipe/calculators/tflite/tflite_tensors_to_detections_calculator.cc index 6213d50a0..269661f73 100644 --- a/mediapipe/calculators/tflite/tflite_tensors_to_detections_calculator.cc +++ b/mediapipe/calculators/tflite/tflite_tensors_to_detections_calculator.cc @@ -15,6 +15,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/strings/str_format.h" #include "absl/types/span.h" @@ -94,7 +95,7 @@ void ConvertRawValuesToAnchors(const float* raw_anchors, int num_boxes, void ConvertAnchorsToRawValues(const std::vector& anchors, int num_boxes, float* raw_anchors) { - CHECK_EQ(anchors.size(), num_boxes); + ABSL_CHECK_EQ(anchors.size(), num_boxes); int box = 0; for (const auto& anchor : anchors) { raw_anchors[box * kNumCoordsPerBox + 0] = anchor.y_center(); @@ -289,14 +290,14 @@ absl::Status TfLiteTensorsToDetectionsCalculator::ProcessCPU( const TfLiteTensor* raw_score_tensor = &input_tensors[1]; // TODO: Add flexible input tensor size handling. - CHECK_EQ(raw_box_tensor->dims->size, 3); - CHECK_EQ(raw_box_tensor->dims->data[0], 1); - CHECK_EQ(raw_box_tensor->dims->data[1], num_boxes_); - CHECK_EQ(raw_box_tensor->dims->data[2], num_coords_); - CHECK_EQ(raw_score_tensor->dims->size, 3); - CHECK_EQ(raw_score_tensor->dims->data[0], 1); - CHECK_EQ(raw_score_tensor->dims->data[1], num_boxes_); - CHECK_EQ(raw_score_tensor->dims->data[2], num_classes_); + ABSL_CHECK_EQ(raw_box_tensor->dims->size, 3); + ABSL_CHECK_EQ(raw_box_tensor->dims->data[0], 1); + ABSL_CHECK_EQ(raw_box_tensor->dims->data[1], num_boxes_); + ABSL_CHECK_EQ(raw_box_tensor->dims->data[2], num_coords_); + ABSL_CHECK_EQ(raw_score_tensor->dims->size, 3); + ABSL_CHECK_EQ(raw_score_tensor->dims->data[0], 1); + ABSL_CHECK_EQ(raw_score_tensor->dims->data[1], num_boxes_); + ABSL_CHECK_EQ(raw_score_tensor->dims->data[2], num_classes_); const float* raw_boxes = raw_box_tensor->data.f; const float* raw_scores = raw_score_tensor->data.f; @@ -304,13 +305,13 @@ absl::Status TfLiteTensorsToDetectionsCalculator::ProcessCPU( if (!anchors_init_) { if (input_tensors.size() == kNumInputTensorsWithAnchors) { const TfLiteTensor* anchor_tensor = &input_tensors[2]; - CHECK_EQ(anchor_tensor->dims->size, 2); - CHECK_EQ(anchor_tensor->dims->data[0], num_boxes_); - CHECK_EQ(anchor_tensor->dims->data[1], kNumCoordsPerBox); + ABSL_CHECK_EQ(anchor_tensor->dims->size, 2); + ABSL_CHECK_EQ(anchor_tensor->dims->data[0], num_boxes_); + ABSL_CHECK_EQ(anchor_tensor->dims->data[1], kNumCoordsPerBox); const float* raw_anchors = anchor_tensor->data.f; ConvertRawValuesToAnchors(raw_anchors, num_boxes_, &anchors_); } else if (side_packet_anchors_) { - CHECK(!cc->InputSidePackets().Tag("ANCHORS").IsEmpty()); + ABSL_CHECK(!cc->InputSidePackets().Tag("ANCHORS").IsEmpty()); anchors_ = cc->InputSidePackets().Tag("ANCHORS").Get>(); } else { @@ -410,7 +411,7 @@ absl::Status TfLiteTensorsToDetectionsCalculator::ProcessGPU( CopyBuffer(input_tensors[1], gpu_data_->raw_scores_buffer)); if (!anchors_init_) { if (side_packet_anchors_) { - CHECK(!cc->InputSidePackets().Tag("ANCHORS").IsEmpty()); + ABSL_CHECK(!cc->InputSidePackets().Tag("ANCHORS").IsEmpty()); const auto& anchors = cc->InputSidePackets().Tag("ANCHORS").Get>(); std::vector raw_anchors(num_boxes_ * kNumCoordsPerBox); @@ -418,7 +419,7 @@ absl::Status TfLiteTensorsToDetectionsCalculator::ProcessGPU( MP_RETURN_IF_ERROR(gpu_data_->raw_anchors_buffer.Write( absl::MakeSpan(raw_anchors))); } else { - CHECK_EQ(input_tensors.size(), kNumInputTensorsWithAnchors); + ABSL_CHECK_EQ(input_tensors.size(), kNumInputTensorsWithAnchors); MP_RETURN_IF_ERROR( CopyBuffer(input_tensors[2], gpu_data_->raw_anchors_buffer)); } @@ -478,7 +479,7 @@ absl::Status TfLiteTensorsToDetectionsCalculator::ProcessGPU( commandBuffer:[gpu_helper_ commandBuffer]]; if (!anchors_init_) { if (side_packet_anchors_) { - CHECK(!cc->InputSidePackets().Tag("ANCHORS").IsEmpty()); + ABSL_CHECK(!cc->InputSidePackets().Tag("ANCHORS").IsEmpty()); const auto& anchors = cc->InputSidePackets().Tag("ANCHORS").Get>(); std::vector raw_anchors(num_boxes_ * kNumCoordsPerBox); @@ -568,12 +569,12 @@ absl::Status TfLiteTensorsToDetectionsCalculator::LoadOptions( num_coords_ = options_.num_coords(); // Currently only support 2D when num_values_per_keypoint equals to 2. - CHECK_EQ(options_.num_values_per_keypoint(), 2); + ABSL_CHECK_EQ(options_.num_values_per_keypoint(), 2); // Check if the output size is equal to the requested boxes and keypoints. - CHECK_EQ(options_.num_keypoints() * options_.num_values_per_keypoint() + - kNumCoordsPerBox, - num_coords_); + ABSL_CHECK_EQ(options_.num_keypoints() * options_.num_values_per_keypoint() + + kNumCoordsPerBox, + num_coords_); for (int i = 0; i < options_.ignore_classes_size(); ++i) { ignore_classes_.insert(options_.ignore_classes(i)); @@ -898,10 +899,11 @@ void main() { int max_wg_size; // typically <= 1024 glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 1, &max_wg_size); // y-dim - CHECK_LT(num_classes_, max_wg_size) + ABSL_CHECK_LT(num_classes_, max_wg_size) << "# classes must be < " << max_wg_size; // TODO support better filtering. - CHECK_LE(ignore_classes_.size(), 1) << "Only ignore class 0 is allowed"; + ABSL_CHECK_LE(ignore_classes_.size(), 1) + << "Only ignore class 0 is allowed"; // Shader program GlShader score_shader; @@ -1116,7 +1118,7 @@ kernel void scoreKernel( ignore_classes_.size() ? 1 : 0); // TODO support better filtering. - CHECK_LE(ignore_classes_.size(), 1) << "Only ignore class 0 is allowed"; + ABSL_CHECK_LE(ignore_classes_.size(), 1) << "Only ignore class 0 is allowed"; { // Shader program @@ -1148,7 +1150,8 @@ kernel void scoreKernel( options:MTLResourceStorageModeShared]; // # filter classes supported is hardware dependent. int max_wg_size = gpu_data_->score_program.maxTotalThreadsPerThreadgroup; - CHECK_LT(num_classes_, max_wg_size) << "# classes must be <" << max_wg_size; + ABSL_CHECK_LT(num_classes_, max_wg_size) + << "# classes must be <" << max_wg_size; } #endif // MEDIAPIPE_TFLITE_GL_INFERENCE diff --git a/mediapipe/calculators/tflite/tflite_tensors_to_landmarks_calculator.cc b/mediapipe/calculators/tflite/tflite_tensors_to_landmarks_calculator.cc index 1be83bbe1..6740f0afa 100644 --- a/mediapipe/calculators/tflite/tflite_tensors_to_landmarks_calculator.cc +++ b/mediapipe/calculators/tflite/tflite_tensors_to_landmarks_calculator.cc @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "absl/log/absl_check.h" #include "mediapipe/calculators/tflite/tflite_tensors_to_landmarks_calculator.pb.h" #include "mediapipe/framework/calculator_framework.h" #include "mediapipe/framework/formats/landmark.pb.h" @@ -199,7 +200,7 @@ absl::Status TfLiteTensorsToLandmarksCalculator::Process( num_values *= raw_tensor->dims->data[i]; } const int num_dimensions = num_values / num_landmarks_; - CHECK_GT(num_dimensions, 0); + ABSL_CHECK_GT(num_dimensions, 0); const float* raw_landmarks = raw_tensor->data.f; diff --git a/mediapipe/calculators/util/BUILD b/mediapipe/calculators/util/BUILD index a5ad3a425..ad75c65d1 100644 --- a/mediapipe/calculators/util/BUILD +++ b/mediapipe/calculators/util/BUILD @@ -378,6 +378,7 @@ cc_library( "//mediapipe/framework/formats:location", "//mediapipe/framework/port:rectangle", "//mediapipe/framework/port:status", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", ], alwayslink = 1, @@ -677,6 +678,7 @@ cc_library( "//mediapipe/framework/port:ret_check", "//mediapipe/util:color_cc_proto", "//mediapipe/util:render_data_cc_proto", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/memory", "@com_google_absl//absl/strings", ], @@ -733,6 +735,7 @@ cc_library( "//mediapipe/framework/port:statusor", "//mediapipe/util:color_cc_proto", "//mediapipe/util:render_data_cc_proto", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", ], alwayslink = 1, @@ -748,6 +751,7 @@ cc_library( "//mediapipe/framework/port:ret_check", "//mediapipe/util:color_cc_proto", "//mediapipe/util:render_data_cc_proto", + "@com_google_absl//absl/log:absl_check", ], alwayslink = 1, ) @@ -1212,6 +1216,7 @@ cc_library( "//mediapipe/framework/port:rectangle", "//mediapipe/framework/port:status", "//mediapipe/util:rectangle_util", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/memory", ], alwayslink = 1, @@ -1483,6 +1488,7 @@ cc_library( "//mediapipe/framework/formats:landmark_cc_proto", "//mediapipe/framework/port:core_proto", "//mediapipe/framework/port:ret_check", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/memory", ], alwayslink = 1, diff --git a/mediapipe/calculators/util/association_calculator.h b/mediapipe/calculators/util/association_calculator.h index 037ea838c..1cec63c80 100644 --- a/mediapipe/calculators/util/association_calculator.h +++ b/mediapipe/calculators/util/association_calculator.h @@ -18,6 +18,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/memory/memory.h" #include "mediapipe/calculators/util/association_calculator.pb.h" #include "mediapipe/framework/calculator_context.h" @@ -72,7 +73,7 @@ class AssociationCalculator : public CalculatorBase { prev_input_stream_id_ = cc->Inputs().GetId("PREV", 0); } options_ = cc->Options<::mediapipe::AssociationCalculatorOptions>(); - CHECK_GE(options_.min_similarity_threshold(), 0); + ABSL_CHECK_GE(options_.min_similarity_threshold(), 0); return absl::OkStatus(); } diff --git a/mediapipe/calculators/util/detections_to_render_data_calculator.cc b/mediapipe/calculators/util/detections_to_render_data_calculator.cc index 25d74ba68..73c2cb1d2 100644 --- a/mediapipe/calculators/util/detections_to_render_data_calculator.cc +++ b/mediapipe/calculators/util/detections_to_render_data_calculator.cc @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "absl/log/absl_check.h" #include "absl/memory/memory.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" @@ -233,13 +234,13 @@ void DetectionsToRenderDataCalculator::AddLabels( const Detection& detection, const DetectionsToRenderDataCalculatorOptions& options, float text_line_height, RenderData* render_data) { - CHECK(detection.label().empty() || detection.label_id().empty() || - detection.label_size() == detection.label_id_size()) + ABSL_CHECK(detection.label().empty() || detection.label_id().empty() || + detection.label_size() == detection.label_id_size()) << "String or integer labels should be of same size. Or only one of them " "is present."; const auto num_labels = std::max(detection.label_size(), detection.label_id_size()); - CHECK_EQ(detection.score_size(), num_labels) + ABSL_CHECK_EQ(detection.score_size(), num_labels) << "Number of scores and labels should match for detection."; // Extracts all "label(_id),score" for the detection. @@ -361,9 +362,9 @@ void DetectionsToRenderDataCalculator::AddDetectionToRenderData( const Detection& detection, const DetectionsToRenderDataCalculatorOptions& options, RenderData* render_data) { - CHECK(detection.location_data().format() == LocationData::BOUNDING_BOX || - detection.location_data().format() == - LocationData::RELATIVE_BOUNDING_BOX) + ABSL_CHECK(detection.location_data().format() == LocationData::BOUNDING_BOX || + detection.location_data().format() == + LocationData::RELATIVE_BOUNDING_BOX) << "Only Detection with formats of BOUNDING_BOX or RELATIVE_BOUNDING_BOX " "are supported."; double text_line_height; diff --git a/mediapipe/calculators/util/labels_to_render_data_calculator.cc b/mediapipe/calculators/util/labels_to_render_data_calculator.cc index dcd76d47b..314640ed7 100644 --- a/mediapipe/calculators/util/labels_to_render_data_calculator.cc +++ b/mediapipe/calculators/util/labels_to_render_data_calculator.cc @@ -19,6 +19,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/strings/str_cat.h" #include "mediapipe/calculators/util/labels_to_render_data_calculator.pb.h" #include "mediapipe/framework/calculator_framework.h" @@ -114,7 +115,8 @@ absl::Status LabelsToRenderDataCalculator::Process(CalculatorContext* cc) { video_height_ = video_header.height; return absl::OkStatus(); } else { - CHECK_EQ(options_.location(), LabelsToRenderDataCalculatorOptions::TOP_LEFT) + ABSL_CHECK_EQ(options_.location(), + LabelsToRenderDataCalculatorOptions::TOP_LEFT) << "Only TOP_LEFT is supported without VIDEO_PRESTREAM."; } @@ -144,7 +146,7 @@ absl::Status LabelsToRenderDataCalculator::Process(CalculatorContext* cc) { if (cc->Inputs().HasTag(kScoresTag)) { std::vector score_vector = cc->Inputs().Tag(kScoresTag).Get>(); - CHECK_EQ(label_vector.size(), score_vector.size()); + ABSL_CHECK_EQ(label_vector.size(), score_vector.size()); scores.resize(label_vector.size()); for (int i = 0; i < label_vector.size(); ++i) { scores[i] = score_vector[i]; diff --git a/mediapipe/calculators/util/landmarks_refinement_calculator.cc b/mediapipe/calculators/util/landmarks_refinement_calculator.cc index 8f734ac88..87394c6c5 100644 --- a/mediapipe/calculators/util/landmarks_refinement_calculator.cc +++ b/mediapipe/calculators/util/landmarks_refinement_calculator.cc @@ -18,6 +18,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/memory/memory.h" #include "mediapipe/calculators/util/landmarks_refinement_calculator.pb.h" #include "mediapipe/framework/api2/node.h" @@ -102,7 +103,8 @@ void RefineZ( ->set_z(z_average); } } else { - CHECK(false) << "Z refinement is either not specified or not supported"; + ABSL_CHECK(false) + << "Z refinement is either not specified or not supported"; } } diff --git a/mediapipe/calculators/util/non_max_suppression_calculator.cc b/mediapipe/calculators/util/non_max_suppression_calculator.cc index 0aff4388b..be3a8da73 100644 --- a/mediapipe/calculators/util/non_max_suppression_calculator.cc +++ b/mediapipe/calculators/util/non_max_suppression_calculator.cc @@ -18,6 +18,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "mediapipe/calculators/util/non_max_suppression_calculator.pb.h" #include "mediapipe/framework/calculator_framework.h" @@ -47,8 +48,8 @@ bool RetainMaxScoringLabelOnly(Detection* detection) { if (detection->label_id_size() == 0 && detection->label_size() == 0) { return false; } - CHECK(detection->label_id_size() == detection->score_size() || - detection->label_size() == detection->score_size()) + ABSL_CHECK(detection->label_id_size() == detection->score_size() || + detection->label_size() == detection->score_size()) << "Number of scores must be equal to number of detections."; std::vector> indexed_scores; @@ -171,9 +172,9 @@ class NonMaxSuppressionCalculator : public CalculatorBase { cc->SetOffset(TimestampDiff(0)); options_ = cc->Options(); - CHECK_GT(options_.num_detection_streams(), 0) + ABSL_CHECK_GT(options_.num_detection_streams(), 0) << "At least one detection stream need to be specified."; - CHECK_NE(options_.max_num_detections(), 0) + ABSL_CHECK_NE(options_.max_num_detections(), 0) << "max_num_detections=0 is not a valid value. Please choose a " << "positive number of you want to limit the number of output " << "detections, or set -1 if you do not want any limit."; diff --git a/mediapipe/calculators/util/rect_to_render_data_calculator.cc b/mediapipe/calculators/util/rect_to_render_data_calculator.cc index bbc08255e..002471cab 100644 --- a/mediapipe/calculators/util/rect_to_render_data_calculator.cc +++ b/mediapipe/calculators/util/rect_to_render_data_calculator.cc @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "absl/log/absl_check.h" #include "mediapipe/calculators/util/rect_to_render_data_calculator.pb.h" #include "mediapipe/framework/calculator_framework.h" #include "mediapipe/framework/formats/rect.pb.h" @@ -41,8 +42,8 @@ RenderAnnotation::Rectangle* NewRect( annotation->set_thickness(options.thickness()); if (options.has_top_left_thickness()) { - CHECK(!options.oval()); - CHECK(!options.filled()); + ABSL_CHECK(!options.oval()); + ABSL_CHECK(!options.filled()); annotation->mutable_rectangle()->set_top_left_thickness( options.top_left_thickness()); } diff --git a/mediapipe/calculators/video/BUILD b/mediapipe/calculators/video/BUILD index baf5f11f4..f17747d28 100644 --- a/mediapipe/calculators/video/BUILD +++ b/mediapipe/calculators/video/BUILD @@ -170,6 +170,7 @@ cc_library( "//mediapipe/framework/formats/motion:optical_flow_field", "//mediapipe/framework/port:opencv_video", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/synchronization", ], alwayslink = 1, @@ -195,6 +196,7 @@ cc_library( "//mediapipe/util/tracking:motion_estimation", "//mediapipe/util/tracking:motion_models", "//mediapipe/util/tracking:region_flow_cc_proto", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", ], @@ -211,6 +213,7 @@ cc_library( "//mediapipe/util/tracking:camera_motion_cc_proto", "//mediapipe/util/tracking:flow_packager", "//mediapipe/util/tracking:region_flow_cc_proto", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", "@com_google_absl//absl/strings:str_format", @@ -238,6 +241,7 @@ cc_library( "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/container:node_hash_map", "@com_google_absl//absl/container:node_hash_set", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", ], @@ -265,6 +269,7 @@ cc_library( "//mediapipe/util/tracking:box_tracker_cc_proto", "//mediapipe/util/tracking:flow_packager_cc_proto", "//mediapipe/util/tracking:tracking_visualization_utilities", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/memory", "@com_google_absl//absl/strings", @@ -451,6 +456,7 @@ cc_test( "//mediapipe/framework/tool:test_util", "//mediapipe/util/tracking:box_tracker_cc_proto", "//mediapipe/util/tracking:tracking_cc_proto", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", ], ) diff --git a/mediapipe/calculators/video/box_detector_calculator.cc b/mediapipe/calculators/video/box_detector_calculator.cc index edba9372a..51f57b7eb 100644 --- a/mediapipe/calculators/video/box_detector_calculator.cc +++ b/mediapipe/calculators/video/box_detector_calculator.cc @@ -17,6 +17,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/memory/memory.h" #include "absl/strings/numbers.h" @@ -277,8 +278,8 @@ absl::Status BoxDetectorCalculator::Process(CalculatorContext* cc) { ? &(cc->Inputs().Tag(kDescriptorsTag)) : nullptr; - CHECK(track_stream != nullptr || video_stream != nullptr || - (feature_stream != nullptr && descriptor_stream != nullptr)) + ABSL_CHECK(track_stream != nullptr || video_stream != nullptr || + (feature_stream != nullptr && descriptor_stream != nullptr)) << "One and only one of {tracking_data, input image frame, " "feature/descriptor} need to be valid."; @@ -296,7 +297,7 @@ absl::Status BoxDetectorCalculator::Process(CalculatorContext* cc) { const TrackingData& tracking_data = track_stream->Get(); - CHECK(tracked_boxes_stream != nullptr) << "tracked_boxes needed."; + ABSL_CHECK(tracked_boxes_stream != nullptr) << "tracked_boxes needed."; const TimedBoxProtoList tracked_boxes = tracked_boxes_stream->Get(); @@ -360,7 +361,7 @@ absl::Status BoxDetectorCalculator::Process(CalculatorContext* cc) { const auto& descriptors = descriptor_stream->Get>(); const int dims = options_.detector_options().descriptor_dims(); - CHECK_GE(descriptors.size(), feature_size * dims); + ABSL_CHECK_GE(descriptors.size(), feature_size * dims); cv::Mat descriptors_mat(feature_size, dims, CV_32F); for (int j = 0; j < feature_size; ++j) { features_vec[j].Set(features[j].pt.x * inv_scale, diff --git a/mediapipe/calculators/video/box_tracker_calculator.cc b/mediapipe/calculators/video/box_tracker_calculator.cc index 8241a155b..4a8f4543d 100644 --- a/mediapipe/calculators/video/box_tracker_calculator.cc +++ b/mediapipe/calculators/video/box_tracker_calculator.cc @@ -22,6 +22,7 @@ #include "absl/container/flat_hash_set.h" #include "absl/container/node_hash_map.h" #include "absl/container/node_hash_set.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/strings/numbers.h" #include "mediapipe/calculators/video/box_tracker_calculator.pb.h" @@ -315,16 +316,16 @@ void ConvertCoordinateForRotation(float in_top, float in_left, float in_bottom, float in_right, int rotation, float* out_top, float* out_left, float* out_bottom, float* out_right) { - CHECK(out_top != nullptr); - CHECK(out_left != nullptr); - CHECK(out_bottom != nullptr); - CHECK(out_right != nullptr); + ABSL_CHECK(out_top != nullptr); + ABSL_CHECK(out_left != nullptr); + ABSL_CHECK(out_bottom != nullptr); + ABSL_CHECK(out_right != nullptr); const float in_center_x = (in_left + in_right) * 0.5f; const float in_center_y = (in_top + in_bottom) * 0.5f; const float in_width = in_right - in_left; const float in_height = in_bottom - in_top; - CHECK_GT(in_width, 0); - CHECK_GT(in_height, 0); + ABSL_CHECK_GT(in_width, 0); + ABSL_CHECK_GT(in_height, 0); float out_center_x; float out_center_y; float out_width; @@ -373,7 +374,7 @@ void ConvertCoordinateForRotation(float in_top, float in_left, float in_bottom, void AddStateToPath(const MotionBoxState& state, int64_t time_msec, PathSegment* path) { - CHECK(path); + ABSL_CHECK(path); TimedBox result; TimedBoxFromMotionBoxState(state, &result); result.time_msec = time_msec; @@ -651,7 +652,7 @@ absl::Status BoxTrackerCalculator::Process(CalculatorContext* cc) { // present at this frame. TimedBoxProtoList box_track_list; - CHECK(box_tracker_ || track_stream) + ABSL_CHECK(box_tracker_ || track_stream) << "Expected either batch or streaming mode"; // Corresponding list of box states for rendering. For each id present at @@ -1001,7 +1002,7 @@ void BoxTrackerCalculator::OutputRandomAccessTrack( const int init_frame = timestamp_pos - track_timestamps_.begin() + track_timestamps_base_index_; - CHECK_GE(init_frame, 0); + ABSL_CHECK_GE(init_frame, 0); MotionBoxMap single_map = PrepareRandomAccessTrack(start, init_frame, forward_track, start_data); @@ -1168,8 +1169,8 @@ void BoxTrackerCalculator::StreamTrack(const TrackingData& data, int64_t duration_ms, bool forward, MotionBoxMap* box_map, std::vector* failed_ids) { - CHECK(box_map); - CHECK(failed_ids); + ABSL_CHECK(box_map); + ABSL_CHECK(failed_ids); // Cache the actively discarded tracked ids from the new tracking data. for (const int discarded_id : @@ -1235,7 +1236,7 @@ void BoxTrackerCalculator::FastForwardStartPos( // Start at previous frame. const int init_frame = timestamp_pos - track_timestamps_.begin() + track_timestamps_base_index_; - CHECK_GE(init_frame, 0); + ABSL_CHECK_GE(init_frame, 0); // Locate corresponding tracking data. auto start_data = std::find_if( diff --git a/mediapipe/calculators/video/flow_packager_calculator.cc b/mediapipe/calculators/video/flow_packager_calculator.cc index e84733ee6..b04534999 100644 --- a/mediapipe/calculators/video/flow_packager_calculator.cc +++ b/mediapipe/calculators/video/flow_packager_calculator.cc @@ -17,6 +17,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/strings/str_format.h" #include "absl/strings/string_view.h" @@ -160,7 +161,7 @@ absl::Status FlowPackagerCalculator::Process(CalculatorContext* cc) { timestamp.Value() / 1000 / options_.caching_chunk_size_msec(); tracking_chunk_.set_first_chunk(true); } - CHECK_GE(chunk_idx_, 0); + ABSL_CHECK_GE(chunk_idx_, 0); TrackingDataChunk::Item* item = tracking_chunk_.add_item(); item->set_frame_idx(frame_idx_); @@ -267,7 +268,7 @@ void FlowPackagerCalculator::WriteChunk(const TrackingDataChunk& chunk) const { void FlowPackagerCalculator::PrepareCurrentForNextChunk( TrackingDataChunk* chunk) { - CHECK(chunk); + ABSL_CHECK(chunk); if (chunk->item_size() == 0) { ABSL_LOG(ERROR) << "Called with empty chunk. Unexpected."; return; diff --git a/mediapipe/calculators/video/motion_analysis_calculator.cc b/mediapipe/calculators/video/motion_analysis_calculator.cc index 88e5ff96b..601b8b045 100644 --- a/mediapipe/calculators/video/motion_analysis_calculator.cc +++ b/mediapipe/calculators/video/motion_analysis_calculator.cc @@ -17,6 +17,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/strings/numbers.h" #include "absl/strings/str_split.h" @@ -429,7 +430,7 @@ absl::Status MotionAnalysisCalculator::Process(CalculatorContext* cc) { selection_input_ ? &(cc->Inputs().Tag(kSelectionTag)) : nullptr; // Checked on Open. - CHECK(video_stream || selection_stream); + ABSL_CHECK(video_stream || selection_stream); // Lazy init. if (frame_width_ < 0 || frame_height_ < 0) { @@ -473,7 +474,7 @@ absl::Status MotionAnalysisCalculator::Process(CalculatorContext* cc) { // Always use frame if selection is not activated. bool use_frame = !selection_input_; if (selection_input_) { - CHECK(selection_stream); + ABSL_CHECK(selection_stream); // Fill in timestamps we process. if (!selection_stream->Value().IsEmpty()) { @@ -621,7 +622,7 @@ void MotionAnalysisCalculator::OutputMotionAnalyzedFrames( const int num_results = motion_analysis_->GetResults( flush, &features, &camera_motions, with_saliency_ ? &saliency : nullptr); - CHECK_LE(num_results, buffer_size); + ABSL_CHECK_LE(num_results, buffer_size); if (num_results == 0) { return; @@ -696,7 +697,7 @@ void MotionAnalysisCalculator::OutputMotionAnalyzedFrames( if (hybrid_meta_analysis_) { hybrid_meta_offset_ -= num_results; - CHECK_GE(hybrid_meta_offset_, 0); + ABSL_CHECK_GE(hybrid_meta_offset_, 0); } timestamp_buffer_.erase(timestamp_buffer_.begin(), @@ -767,7 +768,7 @@ absl::Status MotionAnalysisCalculator::InitOnProcess( // Filled by CSV file parsing. if (!meta_homographies_.empty()) { - CHECK(csv_file_input_); + ABSL_CHECK(csv_file_input_); AppendCameraMotionsFromHomographies(meta_homographies_, true, // append identity. &meta_motions_, &meta_features_); @@ -814,7 +815,7 @@ bool MotionAnalysisCalculator::ParseModelCSV( bool MotionAnalysisCalculator::HomographiesFromValues( const std::vector& homog_values, std::deque* homographies) { - CHECK(homographies); + ABSL_CHECK(homographies); // Obvious constants are obvious :D constexpr int kHomographyValues = 9; @@ -856,7 +857,7 @@ bool MotionAnalysisCalculator::HomographiesFromValues( void MotionAnalysisCalculator::SubtractMetaMotion( const CameraMotion& meta_motion, RegionFlowFeatureList* features) { if (meta_motion.mixture_homography().model_size() > 0) { - CHECK(row_weights_ != nullptr); + ABSL_CHECK(row_weights_ != nullptr); RegionFlowFeatureListViaTransform(meta_motion.mixture_homography(), features, -1.0f, 1.0f, // subtract transformed. @@ -902,7 +903,7 @@ void MotionAnalysisCalculator::AddMetaMotion( const CameraMotion& meta_motion, const RegionFlowFeatureList& meta_features, RegionFlowFeatureList* features, CameraMotion* motion) { // Restore old feature location. - CHECK_EQ(meta_features.feature_size(), features->feature_size()); + ABSL_CHECK_EQ(meta_features.feature_size(), features->feature_size()); for (int k = 0; k < meta_features.feature_size(); ++k) { auto feature = features->mutable_feature(k); const auto& meta_feature = meta_features.feature(k); @@ -923,8 +924,8 @@ void MotionAnalysisCalculator::AppendCameraMotionsFromHomographies( const std::deque& homographies, bool append_identity, std::deque* camera_motions, std::deque* features) { - CHECK(camera_motions); - CHECK(features); + ABSL_CHECK(camera_motions); + ABSL_CHECK(features); CameraMotion identity; identity.set_frame_width(frame_width_); @@ -948,8 +949,9 @@ void MotionAnalysisCalculator::AppendCameraMotionsFromHomographies( } const int models_per_frame = options_.meta_models_per_frame(); - CHECK_GT(models_per_frame, 0) << "At least one model per frame is needed"; - CHECK_EQ(0, homographies.size() % models_per_frame); + ABSL_CHECK_GT(models_per_frame, 0) + << "At least one model per frame is needed"; + ABSL_CHECK_EQ(0, homographies.size() % models_per_frame); const int num_frames = homographies.size() / models_per_frame; // Heuristic sigma, similar to what we use for rolling shutter removal. diff --git a/mediapipe/calculators/video/tool/BUILD b/mediapipe/calculators/video/tool/BUILD index 408461d2f..2a32c680c 100644 --- a/mediapipe/calculators/video/tool/BUILD +++ b/mediapipe/calculators/video/tool/BUILD @@ -44,6 +44,7 @@ cc_library( "//mediapipe/framework/port:integral_types", "//mediapipe/framework/port:ret_check", "//mediapipe/framework/tool:status_util", + "@com_google_absl//absl/log:absl_check", ], alwayslink = 1, ) diff --git a/mediapipe/calculators/video/tool/flow_quantizer_model.cc b/mediapipe/calculators/video/tool/flow_quantizer_model.cc index f0b00063f..146dc4a70 100644 --- a/mediapipe/calculators/video/tool/flow_quantizer_model.cc +++ b/mediapipe/calculators/video/tool/flow_quantizer_model.cc @@ -14,6 +14,7 @@ #include "mediapipe/calculators/video/tool/flow_quantizer_model.h" +#include "absl/log/absl_check.h" #include "mediapipe/framework/port/ret_check.h" #include "mediapipe/framework/type_map.h" @@ -21,7 +22,7 @@ namespace mediapipe { // Uniform normalization to 0-255. uint8_t FlowQuantizerModel::Apply(const float val, const int channel) const { - CHECK_LT(channel, model_.min_value_size()); + ABSL_CHECK_LT(channel, model_.min_value_size()); const auto& min_value = model_.min_value(channel); const auto& max_value = model_.max_value(channel); QCHECK_GT(max_value, min_value); @@ -51,7 +52,7 @@ const QuantizerModelData& FlowQuantizerModel::GetModelData() const { // TODO: Taking the min and max over all training flow fields might be // sensitive to noise. We should use more robust statistics. void FlowQuantizerModel::AddSampleFlowField(const OpticalFlowField& flow) { - CHECK_EQ(model_.min_value_size(), 2); + ABSL_CHECK_EQ(model_.min_value_size(), 2); const cv::Mat_& flow_mat = flow.flow_data(); for (int i = 0; i != flow.width(); ++i) { for (int j = 0; j != flow.height(); ++j) { diff --git a/mediapipe/calculators/video/tracking_graph_test.cc b/mediapipe/calculators/video/tracking_graph_test.cc index d638d7ae2..1ccc61214 100644 --- a/mediapipe/calculators/video/tracking_graph_test.cc +++ b/mediapipe/calculators/video/tracking_graph_test.cc @@ -19,6 +19,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "mediapipe/calculators/video/box_tracker_calculator.pb.h" #include "mediapipe/framework/calculator.pb.h" @@ -298,7 +299,7 @@ std::unique_ptr TrackingGraphTest::CreateRandomAccessTrackingBoxList( const std::vector& start_timestamps, const std::vector& end_timestamps) const { - CHECK_EQ(start_timestamps.size(), end_timestamps.size()); + ABSL_CHECK_EQ(start_timestamps.size(), end_timestamps.size()); auto ra_boxes = absl::make_unique(); for (int i = 0; i < start_timestamps.size(); ++i) { auto start_box_list = diff --git a/mediapipe/calculators/video/tvl1_optical_flow_calculator.cc b/mediapipe/calculators/video/tvl1_optical_flow_calculator.cc index 56f3253e2..e60df0280 100644 --- a/mediapipe/calculators/video/tvl1_optical_flow_calculator.cc +++ b/mediapipe/calculators/video/tvl1_optical_flow_calculator.cc @@ -13,6 +13,7 @@ // limitations under the License. #include "absl/base/macros.h" +#include "absl/log/absl_check.h" #include "absl/synchronization/mutex.h" #include "mediapipe/framework/calculator_framework.h" #include "mediapipe/framework/formats/image_frame.h" @@ -158,7 +159,7 @@ absl::Status Tvl1OpticalFlowCalculator::Process(CalculatorContext* cc) { absl::Status Tvl1OpticalFlowCalculator::CalculateOpticalFlow( const ImageFrame& current_frame, const ImageFrame& next_frame, OpticalFlowField* flow) { - CHECK(flow); + ABSL_CHECK(flow); if (!ImageSizesMatch(current_frame, next_frame)) { return tool::StatusInvalid("Images are different sizes."); } @@ -182,7 +183,7 @@ absl::Status Tvl1OpticalFlowCalculator::CalculateOpticalFlow( flow->Allocate(first.cols, first.rows); cv::Mat cv_flow(flow->mutable_flow_data()); tvl1_computer->calc(first, second, cv_flow); - CHECK_EQ(flow->mutable_flow_data().data, cv_flow.data); + ABSL_CHECK_EQ(flow->mutable_flow_data().data, cv_flow.data); // Inserts the idle DenseOpticalFlow object back to the cache for reuse. { absl::MutexLock lock(&mutex_); diff --git a/mediapipe/examples/desktop/autoflip/quality/BUILD b/mediapipe/examples/desktop/autoflip/quality/BUILD index d01d41dc5..0aeeffaa4 100644 --- a/mediapipe/examples/desktop/autoflip/quality/BUILD +++ b/mediapipe/examples/desktop/autoflip/quality/BUILD @@ -68,7 +68,7 @@ cc_library( hdrs = ["piecewise_linear_function.h"], deps = [ "//mediapipe/framework/port:status", - "@com_google_absl//absl/log:check", + "@com_google_absl//absl/log:absl_check", ], ) @@ -237,7 +237,7 @@ cc_test( "//mediapipe/framework/port:gtest_main", "//mediapipe/framework/port:status", "@com_google_absl//absl/flags:flag", - "@com_google_absl//absl/log:check", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", ], ) @@ -285,6 +285,7 @@ cc_test( "//mediapipe/framework/port:gtest_main", "//mediapipe/framework/port:opencv_core", "//mediapipe/framework/port:status", + "@com_google_absl//absl/log:absl_check", ], ) diff --git a/mediapipe/examples/desktop/autoflip/quality/piecewise_linear_function.cc b/mediapipe/examples/desktop/autoflip/quality/piecewise_linear_function.cc index 9cc78a32e..6e1fc99e5 100644 --- a/mediapipe/examples/desktop/autoflip/quality/piecewise_linear_function.cc +++ b/mediapipe/examples/desktop/autoflip/quality/piecewise_linear_function.cc @@ -20,7 +20,7 @@ #include #include -#include "absl/log/check.h" +#include "absl/log/absl_check.h" #include "mediapipe/framework/port/status.h" namespace mediapipe { @@ -28,7 +28,7 @@ namespace autoflip { void PiecewiseLinearFunction::AddPoint(double x, double y) { if (!points_.empty()) { - CHECK_GE(x, points_.back().x) + ABSL_CHECK_GE(x, points_.back().x) << "Points must be provided in non-decreasing x order."; } points_.push_back(PiecewiseLinearFunction::Point(x, y)); @@ -46,8 +46,8 @@ PiecewiseLinearFunction::GetIntervalIterator(double input) const { double PiecewiseLinearFunction::Interpolate( const PiecewiseLinearFunction::Point& p1, const PiecewiseLinearFunction::Point& p2, double input) const { - CHECK_LT(p1.x, input); - CHECK_GE(p2.x, input); + ABSL_CHECK_LT(p1.x, input); + ABSL_CHECK_GE(p2.x, input); return p2.y - (p2.x - input) / (p2.x - p1.x) * (p2.y - p1.y); } diff --git a/mediapipe/examples/desktop/autoflip/quality/polynomial_regression_path_solver_test.cc b/mediapipe/examples/desktop/autoflip/quality/polynomial_regression_path_solver_test.cc index c21245cde..7870fb434 100644 --- a/mediapipe/examples/desktop/autoflip/quality/polynomial_regression_path_solver_test.cc +++ b/mediapipe/examples/desktop/autoflip/quality/polynomial_regression_path_solver_test.cc @@ -14,6 +14,7 @@ #include "mediapipe/examples/desktop/autoflip/quality/polynomial_regression_path_solver.h" +#include "absl/log/absl_check.h" #include "mediapipe/examples/desktop/autoflip/quality/focus_point.pb.h" #include "mediapipe/framework/port/gmock.h" #include "mediapipe/framework/port/gtest.h" @@ -145,8 +146,8 @@ void GenerateDataPointsFromRealVideo( const int prior_focus_point_frames_length, std::vector* focus_point_frames, std::vector* prior_focus_point_frames) { - CHECK(focus_point_frames_length + prior_focus_point_frames_length <= - kNumObservations); + ABSL_CHECK(focus_point_frames_length + prior_focus_point_frames_length <= + kNumObservations); for (int i = 0; i < prior_focus_point_frames_length; i++) { FocusPoint sp; sp.set_norm_point_x(data[i]); diff --git a/mediapipe/examples/desktop/autoflip/quality/scene_camera_motion_analyzer.h b/mediapipe/examples/desktop/autoflip/quality/scene_camera_motion_analyzer.h index d7f06a021..a1528a7d7 100644 --- a/mediapipe/examples/desktop/autoflip/quality/scene_camera_motion_analyzer.h +++ b/mediapipe/examples/desktop/autoflip/quality/scene_camera_motion_analyzer.h @@ -43,7 +43,7 @@ namespace autoflip { // SceneCameraMotionAnalyzer analyzer(options); // SceneKeyFrameCropSummary scene_summary; // std::vector focus_point_frames; -// CHECK_OK(analyzer.AnalyzeScenePopulateFocusPointFrames( +// ABSL_CHECK_OK(analyzer.AnalyzeScenePopulateFocusPointFrames( // key_frame_crop_infos, key_frame_crop_options, key_frame_crop_results, // scene_frame_width, scene_frame_height, scene_frame_timestamps, // &scene_summary, &focus_point_frames)); diff --git a/mediapipe/examples/desktop/autoflip/quality/scene_camera_motion_analyzer_test.cc b/mediapipe/examples/desktop/autoflip/quality/scene_camera_motion_analyzer_test.cc index 35cafbbfa..3b286e000 100644 --- a/mediapipe/examples/desktop/autoflip/quality/scene_camera_motion_analyzer_test.cc +++ b/mediapipe/examples/desktop/autoflip/quality/scene_camera_motion_analyzer_test.cc @@ -20,7 +20,7 @@ #include #include "absl/flags/flag.h" -#include "absl/log/check.h" +#include "absl/log/absl_check.h" #include "absl/strings/str_split.h" #include "mediapipe/examples/desktop/autoflip/autoflip_messages.pb.h" #include "mediapipe/examples/desktop/autoflip/quality/focus_point.pb.h" @@ -745,7 +745,7 @@ TEST(SceneCameraMotionAnalyzerTest, std::vector r = absl::StrSplit(line, ','); records.insert(records.end(), r.begin(), r.end()); } - CHECK_EQ(records.size(), kNumSceneFrames * 3 + 1); + ABSL_CHECK_EQ(records.size(), kNumSceneFrames * 3 + 1); std::vector focus_point_frames; MP_EXPECT_OK(analyzer.PopulateFocusPointFrames( diff --git a/mediapipe/examples/desktop/autoflip/quality/scene_cropper.h b/mediapipe/examples/desktop/autoflip/quality/scene_cropper.h index 0e5c332db..c3c8a35cb 100644 --- a/mediapipe/examples/desktop/autoflip/quality/scene_cropper.h +++ b/mediapipe/examples/desktop/autoflip/quality/scene_cropper.h @@ -41,7 +41,7 @@ namespace autoflip { // SceneCropperOptions scene_cropper_options; // SceneCropper scene_cropper(scene_cropper_options); // std::vector cropped_frames; -// CHECK_OK(scene_cropper.CropFrames( +// ABSL_CHECK_OK(scene_cropper.CropFrames( // scene_summary, scene_frames, focus_point_frames, // prior_focus_point_frames, &cropped_frames)); class SceneCropper { diff --git a/mediapipe/examples/desktop/hello_world/BUILD b/mediapipe/examples/desktop/hello_world/BUILD index a1ceae3fc..14eff2dbd 100644 --- a/mediapipe/examples/desktop/hello_world/BUILD +++ b/mediapipe/examples/desktop/hello_world/BUILD @@ -24,6 +24,7 @@ cc_binary( "//mediapipe/framework:calculator_graph", "//mediapipe/framework/port:parse_text_proto", "//mediapipe/framework/port:status", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", ], ) diff --git a/mediapipe/examples/desktop/hello_world/hello_world.cc b/mediapipe/examples/desktop/hello_world/hello_world.cc index 5bd1319ac..85cf6c32a 100644 --- a/mediapipe/examples/desktop/hello_world/hello_world.cc +++ b/mediapipe/examples/desktop/hello_world/hello_world.cc @@ -14,6 +14,7 @@ // // A simple example to print out "Hello World!" from a MediaPipe graph. +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "mediapipe/framework/calculator_graph.h" #include "mediapipe/framework/port/parse_text_proto.h" @@ -62,6 +63,6 @@ absl::Status PrintHelloWorld() { int main(int argc, char** argv) { google::InitGoogleLogging(argv[0]); - CHECK(mediapipe::PrintHelloWorld().ok()); + ABSL_CHECK(mediapipe::PrintHelloWorld().ok()); return 0; } diff --git a/mediapipe/framework/BUILD b/mediapipe/framework/BUILD index bc8a166d4..b289fc582 100644 --- a/mediapipe/framework/BUILD +++ b/mediapipe/framework/BUILD @@ -204,6 +204,7 @@ cc_library( ":timestamp", "//mediapipe/framework/port:any_proto", "//mediapipe/framework/port:status", + "@com_google_absl//absl/log:absl_check", ], ) @@ -220,6 +221,7 @@ cc_library( "//mediapipe/framework/port:status", "//mediapipe/framework/tool:tag_map", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/memory", "@com_google_absl//absl/synchronization", ], @@ -360,6 +362,7 @@ cc_library( "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/memory", "@com_google_absl//absl/status", @@ -432,6 +435,7 @@ cc_library( "//mediapipe/framework/tool:tag_map", "//mediapipe/framework/tool:validate_name", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/memory", "@com_google_absl//absl/status", @@ -463,6 +467,7 @@ cc_library( "//mediapipe/framework/port:status", "//mediapipe/framework/tool:sink", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/memory", "@com_google_absl//absl/strings", @@ -489,6 +494,7 @@ cc_library( "//mediapipe/framework/port:logging", "//mediapipe/framework/tool:options_map", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", ], ) @@ -510,6 +516,7 @@ cc_library( "//mediapipe/framework/tool:tag_map_helper", "//mediapipe/framework/tool:validate_name", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/memory", "@com_google_absl//absl/strings", @@ -544,6 +551,7 @@ cc_library( "//mediapipe/framework/port:integral_types", "//mediapipe/framework/port:map_util", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", "@com_google_absl//absl/synchronization", @@ -618,6 +626,7 @@ cc_library( "//mediapipe/framework/port:ret_check", "//mediapipe/framework/port:status", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", "@com_google_absl//absl/synchronization", @@ -633,6 +642,7 @@ cc_library( "//mediapipe/framework/port:status", "//mediapipe/framework/port:statusor", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", ], ) @@ -651,6 +661,7 @@ cc_library( "//mediapipe/framework/port:ret_check", "//mediapipe/framework/port:status", "//mediapipe/framework/tool:fill_packet_set", + "@com_google_absl//absl/log:absl_check", ], ) @@ -689,6 +700,7 @@ cc_library( "//mediapipe/framework/port:ret_check", "//mediapipe/framework/port:status", "//mediapipe/framework/tool:tag_map", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", ], ) @@ -709,6 +721,7 @@ cc_library( "//mediapipe/framework/port:status", "//mediapipe/framework/tool:status_util", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", "@com_google_absl//absl/synchronization", ], @@ -728,6 +741,7 @@ cc_library( "//mediapipe/framework/port:source_location", "//mediapipe/framework/port:status", "//mediapipe/framework/tool:status_util", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", ], ) @@ -767,6 +781,7 @@ cc_library( "//mediapipe/framework/port:logging", "//mediapipe/framework/port:source_location", "//mediapipe/framework/port:status", + "@com_google_absl//absl/log:absl_check", ], ) @@ -805,6 +820,7 @@ cc_library( "//mediapipe/framework/port:status", "//mediapipe/framework/tool:tag_map", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/synchronization", ], ) @@ -823,6 +839,7 @@ cc_library( ":timestamp", "//mediapipe/framework/port:source_location", "//mediapipe/framework/port:status", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/synchronization", ], ) @@ -833,6 +850,7 @@ cc_library( visibility = ["//visibility:public"], deps = [ ":graph_output_stream", + "@com_google_absl//absl/log:absl_check", ], ) @@ -849,6 +867,7 @@ cc_library( ":timestamp", "//mediapipe/framework/port:source_location", "//mediapipe/framework/port:status", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", ], ) @@ -873,6 +892,7 @@ cc_library( "//mediapipe/framework/port:statusor", "//mediapipe/framework/tool:type_util", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/memory", "@com_google_absl//absl/strings", @@ -954,6 +974,7 @@ cc_library( "//mediapipe/framework/tool:type_util", "//mediapipe/framework/tool:validate_name", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/status", "@com_google_absl//absl/strings", @@ -1031,6 +1052,7 @@ cc_library( "//mediapipe/framework/port:ret_check", "//mediapipe/framework/port:status", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/synchronization", ], ) @@ -1090,6 +1112,7 @@ cc_library( "//mediapipe/framework/port:ret_check", "//mediapipe/framework/port:status", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", "@eigen_archive//:eigen3", ], @@ -1140,6 +1163,7 @@ cc_library( "//mediapipe/framework/port:integral_types", "//mediapipe/framework/port:logging", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", ], @@ -1161,8 +1185,8 @@ cc_library( "//mediapipe/framework/tool:status_util", "//mediapipe/framework/tool:type_util", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", - "@com_google_absl//absl/log:check", "@com_google_absl//absl/synchronization", ], alwayslink = 1, @@ -1216,6 +1240,7 @@ cc_library( "//mediapipe/framework/tool:validate", "//mediapipe/framework/tool:validate_name", "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/memory", "@com_google_absl//absl/strings", @@ -1304,6 +1329,7 @@ cc_test( "//mediapipe/framework/port:parse_text_proto", "//mediapipe/framework/port:status", "//mediapipe/framework/tool:source", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/memory", ], @@ -1475,6 +1501,7 @@ cc_test( "//mediapipe/framework/tool:status_util", "//mediapipe/gpu:gpu_service", "@com_google_absl//absl/container:fixed_array", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/memory", "@com_google_absl//absl/status", @@ -1708,6 +1735,7 @@ cc_test( "//mediapipe/framework/port:gtest_main", "//mediapipe/framework/port:parse_text_proto", "//mediapipe/framework/tool:template_parser", + "@com_google_absl//absl/log:absl_check", ], ) diff --git a/mediapipe/framework/api2/BUILD b/mediapipe/framework/api2/BUILD index d344ff28f..5c5ec04ea 100644 --- a/mediapipe/framework/api2/BUILD +++ b/mediapipe/framework/api2/BUILD @@ -22,6 +22,7 @@ cc_library( "//mediapipe/framework/port:any_proto", "//mediapipe/framework/port:ret_check", "@com_google_absl//absl/container:btree", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", "@com_google_protobuf//:protobuf", ], @@ -126,6 +127,7 @@ cc_library( ":tuple", "//mediapipe/framework:packet", "//mediapipe/framework/port:logging", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/meta:type_traits", ], ) @@ -155,6 +157,7 @@ cc_library( "//mediapipe/framework:output_side_packet", "//mediapipe/framework/port:logging", "//mediapipe/framework/tool:type_util", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", ], ) diff --git a/mediapipe/framework/api2/builder.h b/mediapipe/framework/api2/builder.h index 0c4c82f37..fde281121 100644 --- a/mediapipe/framework/api2/builder.h +++ b/mediapipe/framework/api2/builder.h @@ -11,6 +11,7 @@ #include #include "absl/container/btree_map.h" +#include "absl/log/absl_check.h" #include "absl/strings/string_view.h" #include "google/protobuf/message_lite.h" #include "mediapipe/framework/api2/port.h" @@ -109,7 +110,7 @@ class MultiPort : public Single { : Single(vec), vec_(*vec) {} Single operator[](int index) { - CHECK_GE(index, 0); + ABSL_CHECK_GE(index, 0); return Single{&GetWithAutoGrow(&vec_, index)}; } @@ -193,7 +194,7 @@ class SourceImpl { template {}, int>::type = 0> Src& ConnectTo(const Dst& dest) { - CHECK(dest.base_.source == nullptr); + ABSL_CHECK(dest.base_.source == nullptr); dest.base_.source = base_; base_->dests_.emplace_back(&dest.base_); return *this; @@ -721,14 +722,14 @@ class Graph { config.set_type(type_); } FixUnnamedConnections(); - CHECK_OK(UpdateBoundaryConfig(&config)); + ABSL_CHECK_OK(UpdateBoundaryConfig(&config)); for (const std::unique_ptr& node : nodes_) { auto* out_node = config.add_node(); - CHECK_OK(UpdateNodeConfig(*node, out_node)); + ABSL_CHECK_OK(UpdateNodeConfig(*node, out_node)); } for (const std::unique_ptr& node : packet_gens_) { auto* out_node = config.add_packet_generator(); - CHECK_OK(UpdateNodeConfig(*node, out_node)); + ABSL_CHECK_OK(UpdateNodeConfig(*node, out_node)); } return config; } @@ -782,7 +783,7 @@ class Graph { config->set_calculator(node.type_); node.in_streams_.Visit( [&](const TagIndexLocation& loc, const DestinationBase& endpoint) { - CHECK(endpoint.source != nullptr); + ABSL_CHECK(endpoint.source != nullptr); config->add_input_stream(TaggedName(loc, endpoint.source->name_)); }); node.out_streams_.Visit( @@ -791,7 +792,7 @@ class Graph { }); node.in_sides_.Visit([&](const TagIndexLocation& loc, const DestinationBase& endpoint) { - CHECK(endpoint.source != nullptr); + ABSL_CHECK(endpoint.source != nullptr); config->add_input_side_packet(TaggedName(loc, endpoint.source->name_)); }); node.out_sides_.Visit( @@ -812,7 +813,7 @@ class Graph { config->set_packet_generator(node.type_); node.in_sides_.Visit([&](const TagIndexLocation& loc, const DestinationBase& endpoint) { - CHECK(endpoint.source != nullptr); + ABSL_CHECK(endpoint.source != nullptr); config->add_input_side_packet(TaggedName(loc, endpoint.source->name_)); }); node.out_sides_.Visit( @@ -829,7 +830,7 @@ class Graph { absl::Status UpdateBoundaryConfig(CalculatorGraphConfig* config) { graph_boundary_.in_streams_.Visit( [&](const TagIndexLocation& loc, const DestinationBase& endpoint) { - CHECK(endpoint.source != nullptr); + ABSL_CHECK(endpoint.source != nullptr); config->add_output_stream(TaggedName(loc, endpoint.source->name_)); }); graph_boundary_.out_streams_.Visit( @@ -838,7 +839,7 @@ class Graph { }); graph_boundary_.in_sides_.Visit([&](const TagIndexLocation& loc, const DestinationBase& endpoint) { - CHECK(endpoint.source != nullptr); + ABSL_CHECK(endpoint.source != nullptr); config->add_output_side_packet(TaggedName(loc, endpoint.source->name_)); }); graph_boundary_.out_sides_.Visit( diff --git a/mediapipe/framework/api2/packet.h b/mediapipe/framework/api2/packet.h index c059a988b..f231f4c80 100644 --- a/mediapipe/framework/api2/packet.h +++ b/mediapipe/framework/api2/packet.h @@ -13,6 +13,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/meta/type_traits.h" #include "mediapipe/framework/api2/tuple.h" #include "mediapipe/framework/packet.h" @@ -102,9 +103,9 @@ mediapipe::Packet ToOldPacket(PacketBase&& p); template inline const T& PacketBase::Get() const { - CHECK(payload_); + ABSL_CHECK(payload_); packet_internal::Holder* typed_payload = payload_->As(); - CHECK(typed_payload) << absl::StrCat( + ABSL_CHECK(typed_payload) << absl::StrCat( "The Packet stores \"", payload_->DebugTypeName(), "\", but \"", MediaPipeTypeStringOrDemangled(), "\" was requested."); return typed_payload->data(); @@ -134,17 +135,17 @@ namespace internal { template inline void CheckCompatibleType(const HolderBase& holder, internal::Wrap) { const packet_internal::Holder* typed_payload = holder.As(); - CHECK(typed_payload) << absl::StrCat( + ABSL_CHECK(typed_payload) << absl::StrCat( "The Packet stores \"", holder.DebugTypeName(), "\", but \"", MediaPipeTypeStringOrDemangled(), "\" was requested."); - // CHECK(payload_->has_type()); + // ABSL_CHECK(payload_->has_type()); } template inline void CheckCompatibleType(const HolderBase& holder, internal::Wrap>) { bool compatible = (holder.As() || ...); - CHECK(compatible) + ABSL_CHECK(compatible) << "The Packet stores \"" << holder.DebugTypeName() << "\", but one of " << absl::StrJoin( {absl::StrCat("\"", MediaPipeTypeStringOrDemangled(), "\"")...}, @@ -211,9 +212,9 @@ class Packet : public Packet { Packet At(Timestamp timestamp) &&; const T& Get() const { - CHECK(payload_); + ABSL_CHECK(payload_); packet_internal::Holder* typed_payload = payload_->As(); - CHECK(typed_payload); + ABSL_CHECK(typed_payload); return typed_payload->data(); } const T& operator*() const { return Get(); } @@ -330,9 +331,9 @@ class Packet> : public PacketBase { template > const U& Get() const { - CHECK(payload_); + ABSL_CHECK(payload_); packet_internal::Holder* typed_payload = payload_->As(); - CHECK(typed_payload); + ABSL_CHECK(typed_payload); return typed_payload->data(); } @@ -343,7 +344,7 @@ class Packet> : public PacketBase { template auto Visit(const F&... args) const { - CHECK(payload_); + ABSL_CHECK(payload_); auto f = internal::Overload{args...}; using FirstT = typename internal::First::type; using ResultType = absl::result_of_t; @@ -364,7 +365,7 @@ class Packet> : public PacketBase { template auto ConsumeAndVisit(const F&... args) { - CHECK(payload_); + ABSL_CHECK(payload_); auto f = internal::Overload{args...}; using FirstT = typename internal::First::type; using VisitorResultType = diff --git a/mediapipe/framework/api2/port.h b/mediapipe/framework/api2/port.h index 18a786075..075e88437 100644 --- a/mediapipe/framework/api2/port.h +++ b/mediapipe/framework/api2/port.h @@ -20,6 +20,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" #include "mediapipe/framework/api2/const_str.h" @@ -243,8 +244,8 @@ class MultiplePortAccess { // container? int Count() { return count_; } AccessT operator[](int pos) { - CHECK_GE(pos, 0); - CHECK_LT(pos, count_); + ABSL_CHECK_GE(pos, 0); + ABSL_CHECK_LT(pos, count_); return SinglePortAccess(cc_, &first_[pos]); } diff --git a/mediapipe/framework/calculator_context.cc b/mediapipe/framework/calculator_context.cc index 4452f45e3..25f29222c 100644 --- a/mediapipe/framework/calculator_context.cc +++ b/mediapipe/framework/calculator_context.cc @@ -14,35 +14,37 @@ #include "mediapipe/framework/calculator_context.h" +#include "absl/log/absl_check.h" + namespace mediapipe { const std::string& CalculatorContext::CalculatorType() const { - CHECK(calculator_state_); + ABSL_CHECK(calculator_state_); return calculator_state_->CalculatorType(); } const CalculatorOptions& CalculatorContext::Options() const { - CHECK(calculator_state_); + ABSL_CHECK(calculator_state_); return calculator_state_->Options(); } const std::string& CalculatorContext::NodeName() const { - CHECK(calculator_state_); + ABSL_CHECK(calculator_state_); return calculator_state_->NodeName(); } int CalculatorContext::NodeId() const { - CHECK(calculator_state_); + ABSL_CHECK(calculator_state_); return calculator_state_->NodeId(); } Counter* CalculatorContext::GetCounter(const std::string& name) { - CHECK(calculator_state_); + ABSL_CHECK(calculator_state_); return calculator_state_->GetCounter(name); } CounterFactory* CalculatorContext::GetCounterFactory() { - CHECK(calculator_state_); + ABSL_CHECK(calculator_state_); return calculator_state_->GetCounterFactory(); } diff --git a/mediapipe/framework/calculator_context.h b/mediapipe/framework/calculator_context.h index 9568ba745..315d26511 100644 --- a/mediapipe/framework/calculator_context.h +++ b/mediapipe/framework/calculator_context.h @@ -20,6 +20,7 @@ #include #include +#include "absl/log/absl_check.h" #include "mediapipe/framework/calculator_state.h" #include "mediapipe/framework/counter.h" #include "mediapipe/framework/graph_service.h" @@ -147,7 +148,7 @@ class CalculatorContext { } void PopInputTimestamp() { - CHECK(!input_timestamps_.empty()); + ABSL_CHECK(!input_timestamps_.empty()); input_timestamps_.pop(); } diff --git a/mediapipe/framework/calculator_context_manager.cc b/mediapipe/framework/calculator_context_manager.cc index acd70dd94..7da3d2778 100644 --- a/mediapipe/framework/calculator_context_manager.cc +++ b/mediapipe/framework/calculator_context_manager.cc @@ -16,6 +16,7 @@ #include +#include "absl/log/absl_check.h" #include "absl/memory/memory.h" #include "absl/synchronization/mutex.h" #include "mediapipe/framework/port/logging.h" @@ -27,7 +28,7 @@ void CalculatorContextManager::Initialize( std::shared_ptr input_tag_map, std::shared_ptr output_tag_map, bool calculator_run_in_parallel) { - CHECK(calculator_state); + ABSL_CHECK(calculator_state); calculator_state_ = calculator_state; input_tag_map_ = std::move(input_tag_map); output_tag_map_ = std::move(output_tag_map); @@ -51,15 +52,15 @@ void CalculatorContextManager::CleanupAfterRun() { CalculatorContext* CalculatorContextManager::GetDefaultCalculatorContext() const { - CHECK(default_context_.get()); + ABSL_CHECK(default_context_.get()); return default_context_.get(); } CalculatorContext* CalculatorContextManager::GetFrontCalculatorContext( Timestamp* context_input_timestamp) { - CHECK(calculator_run_in_parallel_); + ABSL_CHECK(calculator_run_in_parallel_); absl::MutexLock lock(&contexts_mutex_); - CHECK(!active_contexts_.empty()); + ABSL_CHECK(!active_contexts_.empty()); *context_input_timestamp = active_contexts_.begin()->first; return active_contexts_.begin()->second.get(); } @@ -70,7 +71,7 @@ CalculatorContext* CalculatorContextManager::PrepareCalculatorContext( return GetDefaultCalculatorContext(); } absl::MutexLock lock(&contexts_mutex_); - CHECK(!mediapipe::ContainsKey(active_contexts_, input_timestamp)) + ABSL_CHECK(!mediapipe::ContainsKey(active_contexts_, input_timestamp)) << "Multiple invocations with the same timestamps are not allowed with " "parallel execution, input_timestamp = " << input_timestamp; diff --git a/mediapipe/framework/calculator_context_manager.h b/mediapipe/framework/calculator_context_manager.h index 6b988b03d..ae697e12f 100644 --- a/mediapipe/framework/calculator_context_manager.h +++ b/mediapipe/framework/calculator_context_manager.h @@ -21,6 +21,7 @@ #include #include "absl/base/thread_annotations.h" +#include "absl/log/absl_check.h" #include "absl/synchronization/mutex.h" #include "mediapipe/framework/calculator_context.h" #include "mediapipe/framework/calculator_state.h" @@ -97,18 +98,18 @@ class CalculatorContextManager { void PushInputTimestampToContext(CalculatorContext* calculator_context, Timestamp input_timestamp) { - CHECK(calculator_context); + ABSL_CHECK(calculator_context); calculator_context->PushInputTimestamp(input_timestamp); } void PopInputTimestampFromContext(CalculatorContext* calculator_context) { - CHECK(calculator_context); + ABSL_CHECK(calculator_context); calculator_context->PopInputTimestamp(); } void SetGraphStatusInContext(CalculatorContext* calculator_context, const absl::Status& status) { - CHECK(calculator_context); + ABSL_CHECK(calculator_context); calculator_context->SetGraphStatus(status); } diff --git a/mediapipe/framework/calculator_graph.cc b/mediapipe/framework/calculator_graph.cc index 3be4fd798..03c5d2296 100644 --- a/mediapipe/framework/calculator_graph.cc +++ b/mediapipe/framework/calculator_graph.cc @@ -26,6 +26,7 @@ #include #include "absl/container/flat_hash_set.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/memory/memory.h" #include "absl/status/status.h" @@ -172,7 +173,7 @@ absl::Status CalculatorGraph::InitializePacketGeneratorGraph( Executor* default_executor = nullptr; if (!use_application_thread_) { default_executor = executors_[""].get(); - CHECK(default_executor); + ABSL_CHECK(default_executor); } // If default_executor is nullptr, then packet_generator_graph_ will create // its own DelegatingExecutor to use the application thread. @@ -925,7 +926,7 @@ absl::Status CalculatorGraph::AddPacketToInputStreamInternal( "graph input stream.", stream_name); int node_id = mediapipe::FindOrDie(graph_input_stream_node_ids_, stream_name); - CHECK_GE(node_id, validated_graph_->CalculatorInfos().size()); + ABSL_CHECK_GE(node_id, validated_graph_->CalculatorInfos().size()); { absl::MutexLock lock(&full_input_streams_mutex_); if (full_input_streams_.empty()) { @@ -1113,7 +1114,8 @@ void CalculatorGraph::CallStatusHandlers(GraphRunState graph_run_state, absl::StatusOr> static_access_statusor = internal::StaticAccessToStatusHandlerRegistry:: CreateByNameInNamespace(validated_graph_->Package(), handler_type); - CHECK(static_access_statusor.ok()) << handler_type << " is not registered."; + ABSL_CHECK(static_access_statusor.ok()) + << handler_type << " is not registered."; auto static_access = std::move(static_access_statusor).value(); absl::Status handler_result; if (graph_run_state == GraphRunState::PRE_RUN) { @@ -1154,7 +1156,7 @@ void CalculatorGraph::UpdateThrottledNodes(InputStreamManager* stream, upstream_nodes = &validated_graph_->CalculatorInfos()[node_index].AncestorSources(); } - CHECK(upstream_nodes); + ABSL_CHECK(upstream_nodes); std::vector nodes_to_schedule; { @@ -1176,10 +1178,10 @@ void CalculatorGraph::UpdateThrottledNodes(InputStreamManager* stream, .set_stream_id(&stream->Name())); bool was_throttled = !full_input_streams_[node_id].empty(); if (stream_is_full) { - DCHECK_EQ(full_input_streams_[node_id].count(stream), 0); + ABSL_DCHECK_EQ(full_input_streams_[node_id].count(stream), 0); full_input_streams_[node_id].insert(stream); } else { - DCHECK_EQ(full_input_streams_[node_id].count(stream), 1); + ABSL_DCHECK_EQ(full_input_streams_[node_id].count(stream), 1); full_input_streams_[node_id].erase(stream); } @@ -1363,7 +1365,7 @@ void CalculatorGraph::CleanupAfterRun(absl::Status* status) { // Obtain the combined status again, so that it includes the new errors // added by CallStatusHandlers. GetCombinedErrors(status); - CHECK(!status->ok()); + ABSL_CHECK(!status->ok()); } else { MEDIAPIPE_CHECK_OK(*status); } diff --git a/mediapipe/framework/calculator_graph_test.cc b/mediapipe/framework/calculator_graph_test.cc index ba949e093..91bf72e31 100644 --- a/mediapipe/framework/calculator_graph_test.cc +++ b/mediapipe/framework/calculator_graph_test.cc @@ -29,6 +29,7 @@ #include #include "absl/container/fixed_array.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/memory/memory.h" #include "absl/status/status.h" @@ -729,13 +730,13 @@ class SlowCountingSinkCalculator : public CalculatorBase { absl::Status Process(CalculatorContext* cc) override { absl::SleepFor(absl::Milliseconds(10)); int value = cc->Inputs().Index(0).Get(); - CHECK_EQ(value, counter_); + ABSL_CHECK_EQ(value, counter_); ++counter_; return absl::OkStatus(); } absl::Status Close(CalculatorContext* cc) override { - CHECK_EQ(10, counter_); + ABSL_CHECK_EQ(10, counter_); return absl::OkStatus(); } @@ -1018,7 +1019,7 @@ class CheckInputTimestampSourceCalculator : public CalculatorBase { absl::Status Close(CalculatorContext* cc) final { // Must use CHECK instead of RET_CHECK in Close(), because the framework // may call the Close() method of a source node with .IgnoreError(). - CHECK_EQ(cc->InputTimestamp(), Timestamp::Done()); + ABSL_CHECK_EQ(cc->InputTimestamp(), Timestamp::Done()); return absl::OkStatus(); } @@ -1096,7 +1097,7 @@ class CheckInputTimestamp2SourceCalculator : public CalculatorBase { absl::Status Close(CalculatorContext* cc) final { // Must use CHECK instead of RET_CHECK in Close(), because the framework // may call the Close() method of a source node with .IgnoreError(). - CHECK_EQ(cc->InputTimestamp(), Timestamp::Done()); + ABSL_CHECK_EQ(cc->InputTimestamp(), Timestamp::Done()); return absl::OkStatus(); } @@ -1246,8 +1247,8 @@ REGISTER_STATUS_HANDLER(IncrementingStatusHandler); class CurrentThreadExecutor : public Executor { public: ~CurrentThreadExecutor() override { - CHECK(!executing_); - CHECK(tasks_.empty()); + ABSL_CHECK(!executing_); + ABSL_CHECK(tasks_.empty()); } void Schedule(std::function task) override { @@ -1258,7 +1259,7 @@ class CurrentThreadExecutor : public Executor { // running) to avoid an indefinitely-deep call stack. tasks_.emplace_back(std::move(task)); } else { - CHECK(tasks_.empty()); + ABSL_CHECK(tasks_.empty()); executing_ = true; task(); while (!tasks_.empty()) { @@ -3594,7 +3595,7 @@ REGISTER_CALCULATOR(::mediapipe::nested_ns::ProcessCallbackCalculator); TEST(CalculatorGraph, CalculatorInNamepsace) { CalculatorGraphConfig config; - CHECK(proto_ns::TextFormat::ParseFromString(R"( + ABSL_CHECK(proto_ns::TextFormat::ParseFromString(R"( input_stream: 'in_a' node { calculator: 'mediapipe.nested_ns.ProcessCallbackCalculator' @@ -3603,7 +3604,7 @@ TEST(CalculatorGraph, CalculatorInNamepsace) { input_side_packet: 'callback_1' } )", - &config)); + &config)); CalculatorGraph graph; MP_ASSERT_OK(graph.Initialize(config)); nested_ns::ProcessFunction callback_1; diff --git a/mediapipe/framework/calculator_node.cc b/mediapipe/framework/calculator_node.cc index e6a28a30a..c0aff3b13 100644 --- a/mediapipe/framework/calculator_node.cc +++ b/mediapipe/framework/calculator_node.cc @@ -19,6 +19,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/memory/memory.h" #include "absl/status/status.h" @@ -60,7 +61,7 @@ const PacketType* GetPacketType(const PacketTypeSet& packet_type_set, } else { id = packet_type_set.GetId(tag, 0); } - CHECK(id.IsValid()) << "Internal mediapipe error."; + ABSL_CHECK(id.IsValid()) << "Internal mediapipe error."; return &packet_type_set.Get(id); } @@ -342,7 +343,7 @@ absl::Status CalculatorNode::ConnectShardsToStreams( void CalculatorNode::SetExecutor(const std::string& executor) { absl::MutexLock status_lock(&status_mutex_); - CHECK_LT(status_, kStateOpened); + ABSL_CHECK_LT(status_, kStateOpened); executor_ = executor; } @@ -367,7 +368,7 @@ bool CalculatorNode::Closed() const { } void CalculatorNode::SetMaxInputStreamQueueSize(int max_queue_size) { - CHECK(input_stream_handler_); + ABSL_CHECK(input_stream_handler_); input_stream_handler_->SetMaxQueueSize(max_queue_size); } @@ -540,7 +541,7 @@ absl::Status CalculatorNode::OpenNode() { void CalculatorNode::ActivateNode() { absl::MutexLock status_lock(&status_mutex_); - CHECK_EQ(status_, kStateOpened) << DebugName(); + ABSL_CHECK_EQ(status_, kStateOpened) << DebugName(); status_ = kStateActive; } @@ -695,8 +696,8 @@ void CalculatorNode::InputStreamHeadersReady() { bool ready_for_open = false; { absl::MutexLock lock(&status_mutex_); - CHECK_EQ(status_, kStatePrepared) << DebugName(); - CHECK(!input_stream_headers_ready_called_); + ABSL_CHECK_EQ(status_, kStatePrepared) << DebugName(); + ABSL_CHECK(!input_stream_headers_ready_called_); input_stream_headers_ready_called_ = true; input_stream_headers_ready_ = true; ready_for_open = input_side_packets_ready_; @@ -710,8 +711,8 @@ void CalculatorNode::InputSidePacketsReady() { bool ready_for_open = false; { absl::MutexLock lock(&status_mutex_); - CHECK_EQ(status_, kStatePrepared) << DebugName(); - CHECK(!input_side_packets_ready_called_); + ABSL_CHECK_EQ(status_, kStatePrepared) << DebugName(); + ABSL_CHECK(!input_side_packets_ready_called_); input_side_packets_ready_called_ = true; input_side_packets_ready_ = true; ready_for_open = input_stream_headers_ready_; @@ -761,7 +762,7 @@ void CalculatorNode::EndScheduling() { return; } --current_in_flight_; - CHECK_GE(current_in_flight_, 0); + ABSL_CHECK_GE(current_in_flight_, 0); if (scheduling_state_ == kScheduling) { // Changes the state to scheduling pending if another thread is doing the @@ -791,7 +792,7 @@ std::string CalculatorNode::DebugInputStreamNames() const { } std::string CalculatorNode::DebugName() const { - DCHECK(calculator_state_); + ABSL_DCHECK(calculator_state_); return calculator_state_->NodeName(); } @@ -894,9 +895,9 @@ absl::Status CalculatorNode::ProcessNode( // open input streams for Process(). So this node needs to be closed // too. // If the streams are closed, there shouldn't be more input. - CHECK_EQ(calculator_context_manager_.NumberOfContextTimestamps( - *calculator_context), - 1); + ABSL_CHECK_EQ(calculator_context_manager_.NumberOfContextTimestamps( + *calculator_context), + 1); return CloseNode(absl::OkStatus(), /*graph_run_ended=*/false); } else { RET_CHECK_FAIL() @@ -911,7 +912,7 @@ absl::Status CalculatorNode::ProcessNode( void CalculatorNode::SetQueueSizeCallbacks( InputStreamManager::QueueSizeCallback becomes_full_callback, InputStreamManager::QueueSizeCallback becomes_not_full_callback) { - CHECK(input_stream_handler_); + ABSL_CHECK(input_stream_handler_); input_stream_handler_->SetQueueSizeCallbacks( std::move(becomes_full_callback), std::move(becomes_not_full_callback)); } diff --git a/mediapipe/framework/calculator_node_test.cc b/mediapipe/framework/calculator_node_test.cc index 5c358dce7..deac61f13 100644 --- a/mediapipe/framework/calculator_node_test.cc +++ b/mediapipe/framework/calculator_node_test.cc @@ -18,6 +18,7 @@ #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/memory/memory.h" #include "mediapipe/framework/calculator_framework.h" @@ -104,7 +105,7 @@ class CalculatorNodeTest : public ::testing::Test { void ReadyForOpen(int* count) { ++(*count); } void Notification(CalculatorContext* cc, int* count) { - CHECK(cc); + ABSL_CHECK(cc); cc_ = cc; ++(*count); } diff --git a/mediapipe/framework/calculator_runner.cc b/mediapipe/framework/calculator_runner.cc index e89f98048..800f041cc 100644 --- a/mediapipe/framework/calculator_runner.cc +++ b/mediapipe/framework/calculator_runner.cc @@ -16,6 +16,7 @@ #include "mediapipe/framework/calculator_runner.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/memory/memory.h" #include "absl/strings/str_cat.h" @@ -139,7 +140,7 @@ CalculatorRunner::CalculatorRunner(const std::string& calculator_type, #if !defined(MEDIAPIPE_PROTO_LITE) CalculatorRunner::CalculatorRunner(const std::string& node_config_string) { CalculatorGraphConfig::Node node_config; - CHECK( + ABSL_CHECK( proto_ns::TextFormat::ParseFromString(node_config_string, &node_config)); MEDIAPIPE_CHECK_OK(InitializeFromNodeConfig(node_config)); } @@ -149,8 +150,8 @@ CalculatorRunner::CalculatorRunner(const std::string& calculator_type, int num_inputs, int num_outputs, int num_side_packets) { node_config_.set_calculator(calculator_type); - CHECK(proto_ns::TextFormat::ParseFromString(options_string, - node_config_.mutable_options())); + ABSL_CHECK(proto_ns::TextFormat::ParseFromString( + options_string, node_config_.mutable_options())); SetNumInputs(num_inputs); SetNumOutputs(num_outputs); SetNumInputSidePackets(num_side_packets); @@ -188,7 +189,7 @@ void CalculatorRunner::SetNumInputSidePackets(int n) { } void CalculatorRunner::InitializeInputs(const tool::TagAndNameInfo& info) { - CHECK(graph_ == nullptr); + ABSL_CHECK(graph_ == nullptr); MEDIAPIPE_CHECK_OK( tool::SetFromTagAndNameInfo(info, node_config_.mutable_input_stream())); inputs_.reset(new StreamContentsSet(info)); @@ -196,7 +197,7 @@ void CalculatorRunner::InitializeInputs(const tool::TagAndNameInfo& info) { } void CalculatorRunner::InitializeOutputs(const tool::TagAndNameInfo& info) { - CHECK(graph_ == nullptr); + ABSL_CHECK(graph_ == nullptr); MEDIAPIPE_CHECK_OK( tool::SetFromTagAndNameInfo(info, node_config_.mutable_output_stream())); outputs_.reset(new StreamContentsSet(info)); @@ -205,7 +206,7 @@ void CalculatorRunner::InitializeOutputs(const tool::TagAndNameInfo& info) { void CalculatorRunner::InitializeInputSidePackets( const tool::TagAndNameInfo& info) { - CHECK(graph_ == nullptr); + ABSL_CHECK(graph_ == nullptr); MEDIAPIPE_CHECK_OK(tool::SetFromTagAndNameInfo( info, node_config_.mutable_input_side_packet())); input_side_packets_.reset(new PacketSet(info)); diff --git a/mediapipe/framework/calculator_state.cc b/mediapipe/framework/calculator_state.cc index 3b0264e97..9ff478688 100644 --- a/mediapipe/framework/calculator_state.cc +++ b/mediapipe/framework/calculator_state.cc @@ -18,6 +18,7 @@ #include +#include "absl/log/absl_check.h" #include "absl/strings/str_cat.h" #include "mediapipe/framework/port/logging.h" @@ -46,23 +47,23 @@ void CalculatorState::ResetBetweenRuns() { } void CalculatorState::SetInputSidePackets(const PacketSet* input_side_packets) { - CHECK(input_side_packets); + ABSL_CHECK(input_side_packets); input_side_packets_ = input_side_packets; } void CalculatorState::SetOutputSidePackets( OutputSidePacketSet* output_side_packets) { - CHECK(output_side_packets); + ABSL_CHECK(output_side_packets); output_side_packets_ = output_side_packets; } Counter* CalculatorState::GetCounter(const std::string& name) { - CHECK(counter_factory_); + ABSL_CHECK(counter_factory_); return counter_factory_->GetCounter(absl::StrCat(NodeName(), "-", name)); } CounterFactory* CalculatorState::GetCounterFactory() { - CHECK(counter_factory_); + ABSL_CHECK(counter_factory_); return counter_factory_; } diff --git a/mediapipe/framework/collection.h b/mediapipe/framework/collection.h index 7c55de8d5..d955c9cbe 100644 --- a/mediapipe/framework/collection.h +++ b/mediapipe/framework/collection.h @@ -24,6 +24,7 @@ #include #include "absl/base/macros.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/memory/memory.h" #include "absl/strings/str_cat.h" @@ -413,16 +414,16 @@ bool Collection::UsesTags() const { template typename Collection::value_type& Collection::Get(CollectionItemId id) { - CHECK_LE(BeginId(), id); - CHECK_LT(id, EndId()); + ABSL_CHECK_LE(BeginId(), id); + ABSL_CHECK_LT(id, EndId()); return begin()[id.value()]; } template const typename Collection::value_type& Collection::Get(CollectionItemId id) const { - CHECK_LE(BeginId(), id); - CHECK_LT(id, EndId()); + ABSL_CHECK_LE(BeginId(), id); + ABSL_CHECK_LT(id, EndId()); return begin()[id.value()]; } @@ -433,8 +434,8 @@ Collection::GetPtr(CollectionItemId id) { "mediapipe::internal::Collection::GetPtr() is only " "available for collections that were defined with template " "argument storage == CollectionStorage::kStorePointer."); - CHECK_LE(BeginId(), id); - CHECK_LT(id, EndId()); + ABSL_CHECK_LE(BeginId(), id); + ABSL_CHECK_LT(id, EndId()); return data_[id.value()]; } @@ -445,8 +446,8 @@ Collection::GetPtr(CollectionItemId id) const { "mediapipe::internal::Collection::GetPtr() is only " "available for collections that were defined with template " "argument storage == CollectionStorage::kStorePointer."); - CHECK_LE(BeginId(), id); - CHECK_LT(id, EndId()); + ABSL_CHECK_LE(BeginId(), id); + ABSL_CHECK_LT(id, EndId()); return data_[id.value()]; } diff --git a/mediapipe/framework/deps/BUILD b/mediapipe/framework/deps/BUILD index 80cf77e59..6b6709526 100644 --- a/mediapipe/framework/deps/BUILD +++ b/mediapipe/framework/deps/BUILD @@ -78,8 +78,8 @@ cc_library( visibility = ["//visibility:public"], deps = [ "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", - "@com_google_absl//absl/log:check", "@com_google_absl//absl/synchronization", "@com_google_absl//absl/time", ], @@ -132,8 +132,8 @@ cc_library( "//mediapipe/framework/port", "//mediapipe/framework/port:integral_types", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", - "@com_google_absl//absl/log:check", ], ) @@ -151,7 +151,10 @@ cc_library( # Use this library through "mediapipe/framework/port:map_util". visibility = ["//mediapipe/framework/port:__pkg__"], - deps = ["//mediapipe/framework/port:logging"], + deps = [ + "//mediapipe/framework/port:logging", + "@com_google_absl//absl/log:absl_check", + ], ) cc_library( @@ -162,7 +165,7 @@ cc_library( ], deps = [ "//mediapipe/framework/port:integral_types", - "//mediapipe/framework/port:logging", + "@com_google_absl//absl/log:absl_check", ], ) @@ -235,8 +238,8 @@ cc_library( "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", - "@com_google_absl//absl/log:check", "@com_google_absl//absl/meta:type_traits", "@com_google_absl//absl/strings", "@com_google_absl//absl/synchronization", @@ -347,6 +350,7 @@ cc_library( deps = [ ":thread_options", "//mediapipe/framework/port:logging", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", "@com_google_absl//absl/synchronization", @@ -362,6 +366,7 @@ cc_library( visibility = ["//mediapipe/framework/port:__pkg__"], deps = [ "//mediapipe/framework/port:logging", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", ], ) @@ -374,7 +379,7 @@ cc_library( visibility = ["//mediapipe/framework/port:__pkg__"], deps = [ "//mediapipe/framework/port:integral_types", - "//mediapipe/framework/port:logging", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/utility", ], ) diff --git a/mediapipe/framework/deps/map_util.h b/mediapipe/framework/deps/map_util.h index 05d47b7e7..940ff03f8 100644 --- a/mediapipe/framework/deps/map_util.h +++ b/mediapipe/framework/deps/map_util.h @@ -27,6 +27,7 @@ #include #include +#include "absl/log/absl_check.h" #include "mediapipe/framework/port/logging.h" namespace mediapipe { @@ -53,7 +54,7 @@ template const typename M::value_type::second_type& FindOrDie( const M& m, const typename M::value_type::first_type& key) { auto it = m.find(key); - CHECK(it != m.end()) << "Map key not found: " << key; + ABSL_CHECK(it != m.end()) << "Map key not found: " << key; return it->second; } @@ -63,7 +64,7 @@ typename M::value_type::second_type& FindOrDie( M& m, // NOLINT const typename M::value_type::first_type& key) { auto it = m.find(key); - CHECK(it != m.end()) << "Map key not found: " << key; + ABSL_CHECK(it != m.end()) << "Map key not found: " << key; return it->second; } @@ -138,7 +139,7 @@ bool InsertIfNotPresent(M* m, const typename M::value_type::first_type& key, // inserted. template bool ReverseMap(const M& m, ReverseM* reverse) { - CHECK(reverse != nullptr); + ABSL_CHECK(reverse != nullptr); for (const auto& kv : m) { if (!InsertIfNotPresent(reverse, kv.second, kv.first)) { return false; diff --git a/mediapipe/framework/deps/mathutil.h b/mediapipe/framework/deps/mathutil.h index 315b78c42..a3d8b6e80 100644 --- a/mediapipe/framework/deps/mathutil.h +++ b/mediapipe/framework/deps/mathutil.h @@ -23,8 +23,8 @@ #include #include +#include "absl/log/absl_check.h" #include "mediapipe/framework/port/integral_types.h" -#include "mediapipe/framework/port/logging.h" namespace mediapipe { @@ -354,7 +354,7 @@ class MathUtil { template // T models LessThanComparable. static const T& Clamp(const T& low, const T& high, const T& value) { // Prevents errors in ordering the arguments. - DCHECK(!(high < low)); + ABSL_DCHECK(!(high < low)); if (high < value) return high; if (value < low) return low; return value; @@ -364,7 +364,7 @@ class MathUtil { // absolute margin of error. template static bool WithinMargin(const T x, const T y, const T margin) { - DCHECK_GE(margin, 0); + ABSL_DCHECK_GE(margin, 0); return (std::abs(x) <= std::abs(y) + margin) && (std::abs(x) >= std::abs(y) - margin); } diff --git a/mediapipe/framework/deps/monotonic_clock.cc b/mediapipe/framework/deps/monotonic_clock.cc index bf0dea758..17542b6f6 100644 --- a/mediapipe/framework/deps/monotonic_clock.cc +++ b/mediapipe/framework/deps/monotonic_clock.cc @@ -16,8 +16,8 @@ #include "absl/base/macros.h" #include "absl/base/thread_annotations.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" -#include "absl/log/check.h" #include "absl/synchronization/mutex.h" #include "absl/time/time.h" @@ -61,7 +61,7 @@ class MonotonicClockImpl : public MonotonicClock { // Absolve this object of responsibility for state_. void ReleaseState() { - CHECK(state_owned_); + ABSL_CHECK(state_owned_); state_owned_ = false; } @@ -81,7 +81,7 @@ class MonotonicClockImpl : public MonotonicClock { absl::MutexLock m(&state_->lock); // Check consistency of internal data with state_. - CHECK_LE(last_raw_time_, state_->max_time) + ABSL_CHECK_LE(last_raw_time_, state_->max_time) << "non-monotonic behavior: last_raw_time_=" << last_raw_time_ << ", max_time=" << state_->max_time; @@ -108,7 +108,7 @@ class MonotonicClockImpl : public MonotonicClock { // First, update correction metrics. ++correction_count_; absl::Duration delta = state_->max_time - raw_time; - CHECK_LT(absl::ZeroDuration(), delta); + ABSL_CHECK_LT(absl::ZeroDuration(), delta); if (delta > max_correction_) { max_correction_ = delta; } diff --git a/mediapipe/framework/deps/registration.h b/mediapipe/framework/deps/registration.h index aa199f02a..f974d6896 100644 --- a/mediapipe/framework/deps/registration.h +++ b/mediapipe/framework/deps/registration.h @@ -28,8 +28,8 @@ #include "absl/base/thread_annotations.h" #include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" -#include "absl/log/check.h" #include "absl/meta/type_traits.h" #include "absl/strings/str_join.h" #include "absl/strings/str_split.h" @@ -271,7 +271,7 @@ class FunctionRegistry { if (names[0].empty()) { names.erase(names.begin()); } else { - CHECK_EQ(1u, names.size()) + ABSL_CHECK_EQ(1u, names.size()) << "A registered class name must be either fully qualified " << "with a leading :: or unqualified, got: " << name << "."; } diff --git a/mediapipe/framework/deps/safe_int.h b/mediapipe/framework/deps/safe_int.h index eb3e9318d..37d8663cc 100644 --- a/mediapipe/framework/deps/safe_int.h +++ b/mediapipe/framework/deps/safe_int.h @@ -44,8 +44,8 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" -#include "absl/log/check.h" #include "mediapipe/framework/deps/strong_int.h" namespace mediapipe { @@ -68,17 +68,17 @@ class SafeIntStrongIntValidator { // Check that the underlying integral type provides a range that is // compatible with two's complement. if (std::numeric_limits::is_signed) { - CHECK_EQ(-1, - std::numeric_limits::min() + std::numeric_limits::max()) + ABSL_CHECK_EQ( + -1, std::numeric_limits::min() + std::numeric_limits::max()) << "unexpected integral bounds"; } // Check that division truncates towards 0 (implementation defined in // C++'03, but standard in C++'11). - CHECK_EQ(12, 127 / 10) << "division does not truncate towards 0"; - CHECK_EQ(-12, -127 / 10) << "division does not truncate towards 0"; - CHECK_EQ(-12, 127 / -10) << "division does not truncate towards 0"; - CHECK_EQ(12, -127 / -10) << "division does not truncate towards 0"; + ABSL_CHECK_EQ(12, 127 / 10) << "division does not truncate towards 0"; + ABSL_CHECK_EQ(-12, -127 / 10) << "division does not truncate towards 0"; + ABSL_CHECK_EQ(-12, 127 / -10) << "division does not truncate towards 0"; + ABSL_CHECK_EQ(12, -127 / -10) << "division does not truncate towards 0"; } public: diff --git a/mediapipe/framework/deps/threadpool_pthread_impl.cc b/mediapipe/framework/deps/threadpool_pthread_impl.cc index 98d558158..5033b7522 100644 --- a/mediapipe/framework/deps/threadpool_pthread_impl.cc +++ b/mediapipe/framework/deps/threadpool_pthread_impl.cc @@ -18,6 +18,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" @@ -49,7 +50,7 @@ ThreadPool::WorkerThread::WorkerThread(ThreadPool* pool, const std::string& name_prefix) : pool_(pool), name_prefix_(name_prefix) { int res = pthread_create(&thread_, nullptr, ThreadBody, this); - CHECK_EQ(res, 0) << "pthread_create failed"; + ABSL_CHECK_EQ(res, 0) << "pthread_create failed"; } ThreadPool::WorkerThread::~WorkerThread() {} diff --git a/mediapipe/framework/deps/topologicalsorter.cc b/mediapipe/framework/deps/topologicalsorter.cc index 67fc6adc4..ba906ea65 100644 --- a/mediapipe/framework/deps/topologicalsorter.cc +++ b/mediapipe/framework/deps/topologicalsorter.cc @@ -16,18 +16,19 @@ #include +#include "absl/log/absl_check.h" #include "mediapipe/framework/port/logging.h" namespace mediapipe { TopologicalSorter::TopologicalSorter(int num_nodes) : num_nodes_(num_nodes) { - CHECK_GE(num_nodes_, 0); + ABSL_CHECK_GE(num_nodes_, 0); adjacency_lists_.resize(num_nodes_); } void TopologicalSorter::AddEdge(int from, int to) { - CHECK(!traversal_started_ && from < num_nodes_ && to < num_nodes_ && - from >= 0 && to >= 0); + ABSL_CHECK(!traversal_started_ && from < num_nodes_ && to < num_nodes_ && + from >= 0 && to >= 0); adjacency_lists_[from].push_back(to); } diff --git a/mediapipe/framework/deps/vector.h b/mediapipe/framework/deps/vector.h index 2d4de82f3..5d1400ef5 100644 --- a/mediapipe/framework/deps/vector.h +++ b/mediapipe/framework/deps/vector.h @@ -24,9 +24,9 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/utility/utility.h" #include "mediapipe/framework/port/integral_types.h" -#include "mediapipe/framework/port/logging.h" template class Vector2; @@ -78,13 +78,13 @@ class BasicVector { void Clear() { AsD() = D(); } T& operator[](int b) { - DCHECK_GE(b, 0); - DCHECK_LT(b, SIZE); + ABSL_DCHECK_GE(b, 0); + ABSL_DCHECK_LT(b, SIZE); return static_cast(*this).Data()[b]; } T operator[](int b) const { - DCHECK_GE(b, 0); - DCHECK_LT(b, SIZE); + ABSL_DCHECK_GE(b, 0); + ABSL_DCHECK_LT(b, SIZE); return static_cast(*this).Data()[b]; } diff --git a/mediapipe/framework/formats/BUILD b/mediapipe/framework/formats/BUILD index 3f440e868..9a570d524 100644 --- a/mediapipe/framework/formats/BUILD +++ b/mediapipe/framework/formats/BUILD @@ -119,6 +119,7 @@ cc_library( "//mediapipe/framework/port:logging", "//mediapipe/framework/port:ret_check", "//mediapipe/framework/port:status", + "@com_google_absl//absl/log:absl_check", "@eigen_archive//:eigen3", ], ) @@ -159,8 +160,8 @@ cc_library( "//mediapipe/framework/tool:type_util", "@com_google_absl//absl/base", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", - "@com_google_absl//absl/log:check", "@com_google_absl//absl/memory", "@com_google_absl//absl/strings", ] + select({ @@ -214,6 +215,7 @@ cc_library( "//mediapipe/framework/port:statusor", "//mediapipe/framework/tool:status_util", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/memory", "@com_google_absl//absl/strings", @@ -341,6 +343,7 @@ cc_library( "//mediapipe/framework/port:logging", "//mediapipe/gpu:gpu_buffer", "//mediapipe/gpu:gpu_buffer_format", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/synchronization", ] + select({ "//conditions:default": [ @@ -365,6 +368,7 @@ cc_library( ":image_frame_pool", "//mediapipe/framework:port", "//mediapipe/framework/port:logging", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/memory", "@com_google_absl//absl/synchronization", ] + select({ @@ -402,6 +406,7 @@ cc_library( "//mediapipe/framework/port:logging", "//mediapipe/framework/port:opencv_core", "//mediapipe/framework/port:statusor", + "@com_google_absl//absl/log:absl_check", ], ) @@ -488,6 +493,7 @@ cc_library( deps = [ "//mediapipe/framework:port", "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/memory", "@com_google_absl//absl/synchronization", @@ -522,7 +528,7 @@ cc_library( hdrs = ["frame_buffer.h"], deps = [ "//mediapipe/framework/port:integral_types", - "@com_google_absl//absl/log:check", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", ], diff --git a/mediapipe/framework/formats/frame_buffer.h b/mediapipe/framework/formats/frame_buffer.h index 21a5f537f..71e154572 100644 --- a/mediapipe/framework/formats/frame_buffer.h +++ b/mediapipe/framework/formats/frame_buffer.h @@ -18,7 +18,7 @@ limitations under the License. #include -#include "absl/log/check.h" +#include "absl/log/absl_check.h" #include "absl/status/statusor.h" #include "mediapipe/framework/port/integral_types.h" @@ -147,15 +147,15 @@ class FrameBuffer { // Returns plane indexed by the input `index`. const Plane& plane(int index) const { - CHECK_GE(index, 0); - CHECK_LT(static_cast(index), planes_.size()); + ABSL_CHECK_GE(index, 0); + ABSL_CHECK_LT(static_cast(index), planes_.size()); return planes_[index]; } // Returns mutable plane indexed by the input `index`. Plane mutable_plane(int index) { - CHECK_GE(index, 0); - CHECK_LT(static_cast(index), planes_.size()); + ABSL_CHECK_GE(index, 0); + ABSL_CHECK_LT(static_cast(index), planes_.size()); return planes_[index]; } diff --git a/mediapipe/framework/formats/image.cc b/mediapipe/framework/formats/image.cc index 1ef7e3cb9..b37d95aad 100644 --- a/mediapipe/framework/formats/image.cc +++ b/mediapipe/framework/formats/image.cc @@ -14,6 +14,7 @@ #include "mediapipe/framework/formats/image.h" +#include "absl/log/absl_check.h" #include "mediapipe/framework/type_map.h" #if !MEDIAPIPE_DISABLE_GPU diff --git a/mediapipe/framework/formats/image_frame.cc b/mediapipe/framework/formats/image_frame.cc index 8d570e1ce..472da76a9 100644 --- a/mediapipe/framework/formats/image_frame.cc +++ b/mediapipe/framework/formats/image_frame.cc @@ -23,8 +23,8 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" -#include "absl/log/check.h" #include "absl/strings/str_cat.h" #include "mediapipe/framework/formats/image_format.pb.h" #include "mediapipe/framework/port/aligned_malloc_and_free.h" @@ -99,8 +99,8 @@ void ImageFrame::Reset(ImageFormat::Format format, int width, int height, format_ = format; width_ = width; height_ = height; - CHECK_NE(ImageFormat::UNKNOWN, format_); - CHECK(IsValidAlignmentNumber(alignment_boundary)); + ABSL_CHECK_NE(ImageFormat::UNKNOWN, format_); + ABSL_CHECK(IsValidAlignmentNumber(alignment_boundary)); width_step_ = width * NumberOfChannels() * ByteDepth(); if (alignment_boundary == 1) { pixel_data_ = {new uint8_t[height * width_step_], @@ -125,8 +125,8 @@ void ImageFrame::AdoptPixelData(ImageFormat::Format format, int width, height_ = height; width_step_ = width_step; - CHECK_NE(ImageFormat::UNKNOWN, format_); - CHECK_GE(width_step_, width * NumberOfChannels() * ByteDepth()); + ABSL_CHECK_NE(ImageFormat::UNKNOWN, format_); + ABSL_CHECK_GE(width_step_, width * NumberOfChannels() * ByteDepth()); pixel_data_ = {pixel_data, deleter}; } @@ -137,8 +137,8 @@ std::unique_ptr ImageFrame::Release() { void ImageFrame::InternalCopyFrom(int width, int height, int width_step, int channel_size, const uint8_t* pixel_data) { - CHECK_EQ(width_, width); - CHECK_EQ(height_, height); + ABSL_CHECK_EQ(width_, width); + ABSL_CHECK_EQ(height_, height); // row_bytes = channel_size * num_channels * width const int row_bytes = channel_size * NumberOfChannels() * width; if (width_step == 0) { @@ -188,8 +188,8 @@ void ImageFrame::SetAlignmentPaddingAreas() { if (!pixel_data_) { return; } - CHECK_GE(width_, 1); - CHECK_GE(height_, 1); + ABSL_CHECK_GE(width_, 1); + ABSL_CHECK_GE(height_, 1); const int pixel_size = ByteDepth() * NumberOfChannels(); const int padding_size = width_step_ - width_ * pixel_size; @@ -223,7 +223,7 @@ bool ImageFrame::IsContiguous() const { } bool ImageFrame::IsAligned(uint32_t alignment_boundary) const { - CHECK(IsValidAlignmentNumber(alignment_boundary)); + ABSL_CHECK(IsValidAlignmentNumber(alignment_boundary)); if (!pixel_data_) { return false; } @@ -360,7 +360,7 @@ void ImageFrame::CopyFrom(const ImageFrame& image_frame, Reset(image_frame.Format(), image_frame.Width(), image_frame.Height(), alignment_boundary); - CHECK_EQ(format_, image_frame.Format()); + ABSL_CHECK_EQ(format_, image_frame.Format()); InternalCopyFrom(image_frame.Width(), image_frame.Height(), image_frame.WidthStep(), image_frame.ChannelSize(), image_frame.PixelData()); @@ -383,10 +383,10 @@ void ImageFrame::CopyPixelData(ImageFormat::Format format, int width, } void ImageFrame::CopyToBuffer(uint8_t* buffer, int buffer_size) const { - CHECK(buffer); - CHECK_EQ(1, ByteDepth()); + ABSL_CHECK(buffer); + ABSL_CHECK_EQ(1, ByteDepth()); const int data_size = width_ * height_ * NumberOfChannels(); - CHECK_LE(data_size, buffer_size); + ABSL_CHECK_LE(data_size, buffer_size); if (IsContiguous()) { // The data is stored contiguously, we can just copy. const uint8_t* src = reinterpret_cast(pixel_data_.get()); @@ -398,10 +398,10 @@ void ImageFrame::CopyToBuffer(uint8_t* buffer, int buffer_size) const { } void ImageFrame::CopyToBuffer(uint16_t* buffer, int buffer_size) const { - CHECK(buffer); - CHECK_EQ(2, ByteDepth()); + ABSL_CHECK(buffer); + ABSL_CHECK_EQ(2, ByteDepth()); const int data_size = width_ * height_ * NumberOfChannels(); - CHECK_LE(data_size, buffer_size); + ABSL_CHECK_LE(data_size, buffer_size); if (IsContiguous()) { // The data is stored contiguously, we can just copy. const uint16_t* src = reinterpret_cast(pixel_data_.get()); @@ -413,10 +413,10 @@ void ImageFrame::CopyToBuffer(uint16_t* buffer, int buffer_size) const { } void ImageFrame::CopyToBuffer(float* buffer, int buffer_size) const { - CHECK(buffer); - CHECK_EQ(4, ByteDepth()); + ABSL_CHECK(buffer); + ABSL_CHECK_EQ(4, ByteDepth()); const int data_size = width_ * height_ * NumberOfChannels(); - CHECK_LE(data_size, buffer_size); + ABSL_CHECK_LE(data_size, buffer_size); if (IsContiguous()) { // The data is stored contiguously, we can just copy. const float* src = reinterpret_cast(pixel_data_.get()); diff --git a/mediapipe/framework/formats/image_multi_pool.cc b/mediapipe/framework/formats/image_multi_pool.cc index 655064d36..a38e30a67 100644 --- a/mediapipe/framework/formats/image_multi_pool.cc +++ b/mediapipe/framework/formats/image_multi_pool.cc @@ -16,6 +16,7 @@ #include +#include "absl/log/absl_check.h" #include "absl/memory/memory.h" #include "absl/synchronization/mutex.h" #include "mediapipe/framework/port/logging.h" @@ -43,7 +44,7 @@ ImageMultiPool::SimplePoolGpu ImageMultiPool::MakeSimplePoolGpu( IBufferSpec spec) { OSType cv_format = mediapipe::CVPixelFormatForGpuBufferFormat( GpuBufferFormatForImageFormat(spec.format)); - CHECK_NE(cv_format, -1) << "unsupported pixel format"; + ABSL_CHECK_NE(cv_format, -1) << "unsupported pixel format"; return MakeCFHolderAdopting(mediapipe::CreateCVPixelBufferPool( spec.width, spec.height, cv_format, kKeepCount, 0.1 /* max age in seconds */)); @@ -61,11 +62,11 @@ Image ImageMultiPool::GetBufferFromSimplePool( // pool to give us contiguous data. OSType cv_format = mediapipe::CVPixelFormatForGpuBufferFormat( mediapipe::GpuBufferFormatForImageFormat(spec.format)); - CHECK_NE(cv_format, -1) << "unsupported pixel format"; + ABSL_CHECK_NE(cv_format, -1) << "unsupported pixel format"; CVPixelBufferRef buffer; CVReturn err = mediapipe::CreateCVPixelBufferWithoutPool( spec.width, spec.height, cv_format, &buffer); - CHECK(!err) << "Error creating pixel buffer: " << err; + ABSL_CHECK(!err) << "Error creating pixel buffer: " << err; return Image(MakeCFHolderAdopting(buffer)); #else CVPixelBufferRef buffer; @@ -87,7 +88,7 @@ Image ImageMultiPool::GetBufferFromSimplePool( } }, &buffer); - CHECK(!err) << "Error creating pixel buffer: " << err; + ABSL_CHECK(!err) << "Error creating pixel buffer: " << err; return Image(MakeCFHolderAdopting(buffer)); #endif // TARGET_IPHONE_SIMULATOR } @@ -188,7 +189,7 @@ Image ImageMultiPool::GetBuffer(int width, int height, bool use_gpu, ImageMultiPool::~ImageMultiPool() { #if !MEDIAPIPE_DISABLE_GPU #ifdef __APPLE__ - CHECK_EQ(texture_caches_.size(), 0) + ABSL_CHECK_EQ(texture_caches_.size(), 0) << "Failed to unregister texture caches before deleting pool"; #endif // defined(__APPLE__) #endif // !MEDIAPIPE_DISABLE_GPU @@ -199,8 +200,8 @@ ImageMultiPool::~ImageMultiPool() { void ImageMultiPool::RegisterTextureCache(mediapipe::CVTextureCacheType cache) { absl::MutexLock lock(&mutex_gpu_); - CHECK(std::find(texture_caches_.begin(), texture_caches_.end(), cache) == - texture_caches_.end()) + ABSL_CHECK(std::find(texture_caches_.begin(), texture_caches_.end(), cache) == + texture_caches_.end()) << "Attempting to register a texture cache twice"; texture_caches_.emplace_back(cache); } @@ -210,7 +211,7 @@ void ImageMultiPool::UnregisterTextureCache( absl::MutexLock lock(&mutex_gpu_); auto it = std::find(texture_caches_.begin(), texture_caches_.end(), cache); - CHECK(it != texture_caches_.end()) + ABSL_CHECK(it != texture_caches_.end()) << "Attempting to unregister an unknown texture cache"; texture_caches_.erase(it); } diff --git a/mediapipe/framework/formats/image_opencv.cc b/mediapipe/framework/formats/image_opencv.cc index 498c7831f..387afb5e8 100644 --- a/mediapipe/framework/formats/image_opencv.cc +++ b/mediapipe/framework/formats/image_opencv.cc @@ -14,6 +14,7 @@ #include "mediapipe/framework/formats/image_opencv.h" +#include "absl/log/absl_check.h" #include "mediapipe/framework/formats/image_format.pb.h" #include "mediapipe/framework/port/logging.h" @@ -100,7 +101,7 @@ std::shared_ptr MatView(const mediapipe::Image* image) { auto owner = std::make_shared(const_cast(image)); uint8_t* data_ptr = owner->lock.Pixels(); - CHECK(data_ptr != nullptr); + ABSL_CHECK(data_ptr != nullptr); // Use Image to initialize in-place. Image still owns memory. if (steps[0] == sizes[1] * image->channels() * ImageFrame::ByteDepthForFormat(image->image_format())) { diff --git a/mediapipe/framework/formats/location.cc b/mediapipe/framework/formats/location.cc index d810a9cb8..b9dd97e74 100644 --- a/mediapipe/framework/formats/location.cc +++ b/mediapipe/framework/formats/location.cc @@ -18,6 +18,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/memory/memory.h" #include "absl/strings/substitute.h" @@ -39,7 +40,7 @@ namespace { // the location_data, the tightest bounding box, that contains all pixels // encoded in the rasterizations. Rectangle_i MaskToRectangle(const LocationData& location_data) { - CHECK(location_data.mask().has_rasterization()); + ABSL_CHECK(location_data.mask().has_rasterization()); const auto& rasterization = location_data.mask().rasterization(); if (rasterization.interval_size() == 0) { return Rectangle_i(0, 0, 0, 0); @@ -63,7 +64,7 @@ Location::Location() {} Location::Location(const LocationData& location_data) : location_data_(location_data) { - CHECK(IsValidLocationData(location_data_)); + ABSL_CHECK(IsValidLocationData(location_data_)); } Location Location::CreateGlobalLocation() { @@ -152,15 +153,15 @@ bool Location::IsValidLocationData(const LocationData& location_data) { template <> Rectangle_i Location::GetBBox() const { - CHECK_EQ(LocationData::BOUNDING_BOX, location_data_.format()); + ABSL_CHECK_EQ(LocationData::BOUNDING_BOX, location_data_.format()); const auto& box = location_data_.bounding_box(); return Rectangle_i(box.xmin(), box.ymin(), box.width(), box.height()); } Location& Location::Scale(const float scale) { - CHECK(!location_data_.has_mask()) + ABSL_CHECK(!location_data_.has_mask()) << "Location mask scaling is not implemented."; - CHECK_GT(scale, 0.0f); + ABSL_CHECK_GT(scale, 0.0f); switch (location_data_.format()) { case LocationData::GLOBAL: { // Do nothing. @@ -249,7 +250,7 @@ namespace { // This function is inteded to shift boundaries of intervals such that they // best fit within an image. float BestShift(float min_value, float max_value, float range) { - CHECK_LE(min_value, max_value); + ABSL_CHECK_LE(min_value, max_value); const float value_range = max_value - min_value; if (value_range > range) { return 0.5f * (range - min_value - max_value); @@ -296,8 +297,8 @@ Location& Location::ShiftToFitBestIntoImage(int image_width, int image_height) { const float y_shift = BestShift(mask_bounding_box.xmin(), mask_bounding_box.xmax(), image_height); auto* mask = location_data_.mutable_mask(); - CHECK_EQ(image_width, mask->width()); - CHECK_EQ(image_height, mask->height()); + ABSL_CHECK_EQ(image_width, mask->width()); + ABSL_CHECK_EQ(image_height, mask->height()); for (auto& interval : *mask->mutable_rasterization()->mutable_interval()) { interval.set_y(interval.y() + y_shift); @@ -421,7 +422,7 @@ Rectangle_i Location::ConvertToBBox(int image_width, } Rectangle_f Location::GetRelativeBBox() const { - CHECK_EQ(LocationData::RELATIVE_BOUNDING_BOX, location_data_.format()); + ABSL_CHECK_EQ(LocationData::RELATIVE_BOUNDING_BOX, location_data_.format()); const auto& box = location_data_.relative_bounding_box(); return Rectangle_f(box.xmin(), box.ymin(), box.width(), box.height()); } @@ -460,7 +461,7 @@ Rectangle_f Location::ConvertToRelativeBBox(int image_width, template <> ::mediapipe::BoundingBox Location::GetBBox<::mediapipe::BoundingBox>() const { - CHECK_EQ(LocationData::BOUNDING_BOX, location_data_.format()); + ABSL_CHECK_EQ(LocationData::BOUNDING_BOX, location_data_.format()); const auto& box = location_data_.bounding_box(); ::mediapipe::BoundingBox bounding_box; bounding_box.set_left_x(box.xmin()); @@ -483,7 +484,7 @@ template <> } std::vector Location::GetRelativeKeypoints() const { - CHECK_EQ(LocationData::RELATIVE_BOUNDING_BOX, location_data_.format()); + ABSL_CHECK_EQ(LocationData::RELATIVE_BOUNDING_BOX, location_data_.format()); std::vector keypoints; for (const auto& keypoint : location_data_.relative_keypoints()) { keypoints.emplace_back(Point2_f(keypoint.x(), keypoint.y())); diff --git a/mediapipe/framework/formats/location_opencv.cc b/mediapipe/framework/formats/location_opencv.cc index 8f73faf5a..4b69cc6dc 100644 --- a/mediapipe/framework/formats/location_opencv.cc +++ b/mediapipe/framework/formats/location_opencv.cc @@ -14,6 +14,7 @@ #include "mediapipe/framework/formats/location_opencv.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/memory/memory.h" #include "absl/strings/substitute.h" @@ -26,7 +27,7 @@ namespace mediapipe { namespace { Rectangle_i MaskToRectangle(const LocationData& location_data) { - CHECK(location_data.mask().has_rasterization()); + ABSL_CHECK(location_data.mask().has_rasterization()); const auto& rasterization = location_data.mask().rasterization(); if (rasterization.interval_size() == 0) { return Rectangle_i(0, 0, 0, 0); @@ -85,7 +86,7 @@ Location CreateBBoxLocation(const cv::Rect& rect) { std::unique_ptr GetCvMask(const Location& location) { const auto location_data = location.ConvertToProto(); - CHECK_EQ(LocationData::MASK, location_data.format()); + ABSL_CHECK_EQ(LocationData::MASK, location_data.format()); const auto& mask = location_data.mask(); std::unique_ptr mat( new cv::Mat(mask.height(), mask.width(), CV_8UC1, cv::Scalar(0))); @@ -128,7 +129,7 @@ std::unique_ptr ConvertToCvMask(const Location& location, } void EnlargeLocation(Location& location, const float factor) { - CHECK_GT(factor, 0.0f); + ABSL_CHECK_GT(factor, 0.0f); if (factor == 1.0f) return; auto location_data = location.ConvertToProto(); switch (location_data.format()) { @@ -183,7 +184,7 @@ void EnlargeLocation(Location& location, const float factor) { template Location CreateCvMaskLocation(const cv::Mat_& mask) { - CHECK_EQ(1, mask.channels()) + ABSL_CHECK_EQ(1, mask.channels()) << "The specified cv::Mat mask should be single-channel."; LocationData location_data; diff --git a/mediapipe/framework/formats/matrix.cc b/mediapipe/framework/formats/matrix.cc index 42f2df5f8..34ffc6e74 100644 --- a/mediapipe/framework/formats/matrix.cc +++ b/mediapipe/framework/formats/matrix.cc @@ -15,6 +15,7 @@ #include +#include "absl/log/absl_check.h" #include "mediapipe/framework/port/core_proto_inc.h" #include "mediapipe/framework/port/logging.h" #include "mediapipe/framework/port/proto_ns.h" @@ -33,8 +34,8 @@ void MatrixDataProtoFromMatrix(const Matrix& matrix, MatrixData* matrix_data) { } void MatrixFromMatrixDataProto(const MatrixData& matrix_data, Matrix* matrix) { - CHECK_EQ(matrix_data.rows() * matrix_data.cols(), - matrix_data.packed_data_size()); + ABSL_CHECK_EQ(matrix_data.rows() * matrix_data.cols(), + matrix_data.packed_data_size()); if (matrix_data.layout() == MatrixData::ROW_MAJOR) { matrix->resize(matrix_data.cols(), matrix_data.rows()); } else { @@ -56,9 +57,9 @@ std::string MatrixAsTextProto(const Matrix& matrix) { } void MatrixFromTextProto(const std::string& text_proto, Matrix* matrix) { - CHECK(matrix); + ABSL_CHECK(matrix); MatrixData matrix_data; - CHECK(proto_ns::TextFormat::ParseFromString(text_proto, &matrix_data)); + ABSL_CHECK(proto_ns::TextFormat::ParseFromString(text_proto, &matrix_data)); MatrixFromMatrixDataProto(matrix_data, matrix); } #endif // !defined(MEDIAPIPE_MOBILE) && !defined(MEDIAPIPE_LITE) diff --git a/mediapipe/framework/formats/motion/BUILD b/mediapipe/framework/formats/motion/BUILD index 66a8a5213..8f40202cf 100644 --- a/mediapipe/framework/formats/motion/BUILD +++ b/mediapipe/framework/formats/motion/BUILD @@ -43,6 +43,7 @@ cc_library( "//mediapipe/framework/port:point", "//mediapipe/framework/port:ret_check", "//mediapipe/framework/port:status", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", "@org_tensorflow//tensorflow/core:framework", @@ -62,6 +63,7 @@ cc_test( "//mediapipe/framework/port:gtest_main", "//mediapipe/framework/port:integral_types", "@com_google_absl//absl/flags:flag", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@org_tensorflow//tensorflow/core:framework", ], diff --git a/mediapipe/framework/formats/motion/optical_flow_field.cc b/mediapipe/framework/formats/motion/optical_flow_field.cc index d044e3540..fd9b8e300 100644 --- a/mediapipe/framework/formats/motion/optical_flow_field.cc +++ b/mediapipe/framework/formats/motion/optical_flow_field.cc @@ -18,6 +18,7 @@ #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" @@ -40,8 +41,8 @@ const float kFloFileHeaderOnRead = 202021.25; void CartesianToPolarCoordinates(const cv::Mat& cartesian, cv::Mat* magnitudes, cv::Mat* angles) { - CHECK(magnitudes != nullptr); - CHECK(angles != nullptr); + ABSL_CHECK(magnitudes != nullptr); + ABSL_CHECK(angles != nullptr); cv::Mat cartesian_components[2]; cv::split(cartesian, cartesian_components); cv::cartToPolar(cartesian_components[0], cartesian_components[1], *magnitudes, @@ -105,7 +106,7 @@ cv::Mat OpticalFlowField::GetVisualizationInternal( std::max(std::numeric_limits::epsilon(), MaxAbsoluteValueIgnoringHuge(magnitudes, kHugeToIgnore)); } - CHECK_LT(0, max_magnitude); + ABSL_CHECK_LT(0, max_magnitude); cv::Mat hsv = MakeVisualizationHsv(angles, magnitudes, max_magnitude); cv::Mat viz; cv::cvtColor(hsv, viz, 71 /*cv::COLOR_HSV2RGB_FULL*/); @@ -119,7 +120,7 @@ cv::Mat OpticalFlowField::GetVisualization() const { cv::Mat OpticalFlowField::GetVisualizationSaturatedAt( float max_magnitude) const { - CHECK_LT(0, max_magnitude) + ABSL_CHECK_LT(0, max_magnitude) << "Specified saturation magnitude must be positive."; return GetVisualizationInternal(max_magnitude, true); } @@ -147,9 +148,9 @@ void OpticalFlowField::Resize(int new_width, int new_height) { } void OpticalFlowField::CopyFromTensor(const tensorflow::Tensor& tensor) { - CHECK_EQ(tensorflow::DT_FLOAT, tensor.dtype()); - CHECK_EQ(3, tensor.dims()) << "Tensor must be height x width x 2."; - CHECK_EQ(2, tensor.dim_size(2)) << "Tensor must be height x width x 2."; + ABSL_CHECK_EQ(tensorflow::DT_FLOAT, tensor.dtype()); + ABSL_CHECK_EQ(3, tensor.dims()) << "Tensor must be height x width x 2."; + ABSL_CHECK_EQ(2, tensor.dim_size(2)) << "Tensor must be height x width x 2."; const int height = tensor.dim_size(0); const int width = tensor.dim_size(1); Allocate(width, height); @@ -163,8 +164,8 @@ void OpticalFlowField::CopyFromTensor(const tensorflow::Tensor& tensor) { } void OpticalFlowField::SetFromProto(const OpticalFlowFieldData& proto) { - CHECK_EQ(proto.width() * proto.height(), proto.dx_size()); - CHECK_EQ(proto.width() * proto.height(), proto.dy_size()); + ABSL_CHECK_EQ(proto.width() * proto.height(), proto.dx_size()); + ABSL_CHECK_EQ(proto.width() * proto.height(), proto.dy_size()); flow_data_.create(proto.height(), proto.width()); int i = 0; for (int r = 0; r < flow_data_.rows; ++r) { @@ -191,8 +192,8 @@ void OpticalFlowField::ConvertToProto(OpticalFlowFieldData* proto) const { bool OpticalFlowField::FollowFlow(float x, float y, float* new_x, float* new_y) const { - CHECK(new_x); - CHECK(new_y); + ABSL_CHECK(new_x); + ABSL_CHECK(new_y); if (x < 0 || x > flow_data_.cols - 1 || // horizontal bounds y < 0 || y > flow_data_.rows - 1) { // vertical bounds return false; @@ -205,10 +206,10 @@ bool OpticalFlowField::FollowFlow(float x, float y, float* new_x, cv::Point2f OpticalFlowField::InterpolatedFlowAt(float x, float y) const { // Sanity bounds checks. - CHECK_GE(x, 0); - CHECK_GE(y, 0); - CHECK_LE(x, flow_data_.cols - 1); - CHECK_LE(y, flow_data_.rows - 1); + ABSL_CHECK_GE(x, 0); + ABSL_CHECK_GE(y, 0); + ABSL_CHECK_LE(x, flow_data_.cols - 1); + ABSL_CHECK_LE(y, flow_data_.rows - 1); const int x0 = static_cast(std::floor(x)); const int y0 = static_cast(std::floor(y)); @@ -265,9 +266,9 @@ void OpticalFlowField::EstimateMotionConsistencyOcclusions( const OpticalFlowField& forward, const OpticalFlowField& backward, double spatial_distance_threshold, Location* occluded_mask, Location* disoccluded_mask) { - CHECK_EQ(forward.width(), backward.width()) + ABSL_CHECK_EQ(forward.width(), backward.width()) << "Flow fields have different widths."; - CHECK_EQ(forward.height(), backward.height()) + ABSL_CHECK_EQ(forward.height(), backward.height()) << "Flow fields have different heights."; if (occluded_mask != nullptr) { *occluded_mask = FindMotionInconsistentPixels(forward, backward, diff --git a/mediapipe/framework/formats/motion/optical_flow_field_test.cc b/mediapipe/framework/formats/motion/optical_flow_field_test.cc index 4d9ee4861..2647c2613 100644 --- a/mediapipe/framework/formats/motion/optical_flow_field_test.cc +++ b/mediapipe/framework/formats/motion/optical_flow_field_test.cc @@ -19,6 +19,7 @@ #include #include "absl/flags/flag.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "mediapipe/framework/deps/file_path.h" #include "mediapipe/framework/formats/location_opencv.h" diff --git a/mediapipe/framework/formats/tensor.cc b/mediapipe/framework/formats/tensor.cc index a38f7652b..2f2bfaae4 100644 --- a/mediapipe/framework/formats/tensor.cc +++ b/mediapipe/framework/formats/tensor.cc @@ -17,6 +17,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/synchronization/mutex.h" #include "mediapipe/framework/port.h" @@ -347,7 +348,7 @@ Tensor::OpenGlBufferView Tensor::GetOpenGlBufferReadView() const { void* ptr = glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, bytes(), GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_WRITE_BIT); - CHECK(ptr) << "glMapBufferRange failed: " << glGetError(); + ABSL_CHECK(ptr) << "glMapBufferRange failed: " << glGetError(); std::memcpy(ptr, cpu_buffer_, bytes()); glUnmapBuffer(GL_SHADER_STORAGE_BUFFER); } @@ -537,7 +538,7 @@ Tensor::CpuReadView Tensor::GetCpuReadView() const { valid_ |= kValidCpu; return {ptr, std::move(lock), [ahwb = ahwb_] { auto error = AHardwareBuffer_unlock(ahwb, nullptr); - CHECK(error == 0) << "AHardwareBuffer_unlock " << error; + ABSL_CHECK(error == 0) << "AHardwareBuffer_unlock " << error; }}; } } @@ -621,7 +622,7 @@ Tensor::CpuWriteView Tensor::GetCpuWriteView( if (ptr) { return {ptr, std::move(lock), [ahwb = ahwb_, fence_fd = &fence_fd_] { auto error = AHardwareBuffer_unlock(ahwb, fence_fd); - CHECK(error == 0) << "AHardwareBuffer_unlock " << error; + ABSL_CHECK(error == 0) << "AHardwareBuffer_unlock " << error; }}; } } diff --git a/mediapipe/framework/formats/tensor.h b/mediapipe/framework/formats/tensor.h index fea200f94..701707ded 100644 --- a/mediapipe/framework/formats/tensor.h +++ b/mediapipe/framework/formats/tensor.h @@ -25,6 +25,7 @@ #include #include "absl/container/flat_hash_map.h" +#include "absl/log/absl_check.h" #include "absl/synchronization/mutex.h" #include "mediapipe/framework/formats/tensor/internal.h" #include "mediapipe/framework/port.h" @@ -204,12 +205,12 @@ class Tensor { } int file_descriptor() const { return file_descriptor_; } void SetReadingFinishedFunc(FinishingFunc&& func) { - CHECK(ahwb_written_) + ABSL_CHECK(ahwb_written_) << "AHWB write view can't accept 'reading finished callback'"; *ahwb_written_ = std::move(func); } void SetWritingFinishedFD(int fd, FinishingFunc func = nullptr) { - CHECK(fence_fd_) + ABSL_CHECK(fence_fd_) << "AHWB read view can't accept 'writing finished file descriptor'"; *fence_fd_ = fd; *ahwb_written_ = std::move(func); diff --git a/mediapipe/framework/formats/tensor_ahwb.cc b/mediapipe/framework/formats/tensor_ahwb.cc index a72b481e0..339148e94 100644 --- a/mediapipe/framework/formats/tensor_ahwb.cc +++ b/mediapipe/framework/formats/tensor_ahwb.cc @@ -7,6 +7,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/synchronization/mutex.h" #include "mediapipe/framework/port.h" @@ -208,12 +209,13 @@ class DelayedReleaser { Tensor::AHardwareBufferView Tensor::GetAHardwareBufferReadView() const { auto lock(absl::make_unique(&view_mutex_)); - CHECK(valid_ != kValidNone) << "Tensor must be written prior to read from."; - CHECK(!(valid_ & kValidOpenGlTexture2d)) + ABSL_CHECK(valid_ != kValidNone) + << "Tensor must be written prior to read from."; + ABSL_CHECK(!(valid_ & kValidOpenGlTexture2d)) << "Tensor conversion between OpenGL texture and AHardwareBuffer is not " "supported."; bool transfer = !ahwb_; - CHECK(AllocateAHardwareBuffer()) + ABSL_CHECK(AllocateAHardwareBuffer()) << "AHardwareBuffer is not supported on the target system."; valid_ |= kValidAHardwareBuffer; if (transfer) { @@ -253,7 +255,7 @@ void Tensor::CreateEglSyncAndFd() const { Tensor::AHardwareBufferView Tensor::GetAHardwareBufferWriteView( int size_alignment) const { auto lock(absl::make_unique(&view_mutex_)); - CHECK(AllocateAHardwareBuffer(size_alignment)) + ABSL_CHECK(AllocateAHardwareBuffer(size_alignment)) << "AHardwareBuffer is not supported on the target system."; valid_ = kValidAHardwareBuffer; return {ahwb_, @@ -319,7 +321,7 @@ void Tensor::MoveCpuOrSsboToAhwb() const { if (__builtin_available(android 26, *)) { auto error = AHardwareBuffer_lock( ahwb_, AHARDWAREBUFFER_USAGE_CPU_WRITE_RARELY, -1, nullptr, &dest); - CHECK(error == 0) << "AHardwareBuffer_lock " << error; + ABSL_CHECK(error == 0) << "AHardwareBuffer_lock " << error; } if (valid_ & kValidCpu) { std::memcpy(dest, cpu_buffer_, bytes()); @@ -347,7 +349,7 @@ void Tensor::MoveCpuOrSsboToAhwb() const { } if (__builtin_available(android 26, *)) { auto error = AHardwareBuffer_unlock(ahwb_, nullptr); - CHECK(error == 0) << "AHardwareBuffer_unlock " << error; + ABSL_CHECK(error == 0) << "AHardwareBuffer_unlock " << error; } } @@ -422,9 +424,10 @@ void* Tensor::MapAhwbToCpuRead() const { // TODO: Use tflite::gpu::GlBufferSync and GlActiveSync. gl_context_->Run([]() { glFinish(); }); } else if (valid_ & kValidAHardwareBuffer) { - CHECK(ahwb_written_) << "Ahwb-to-Cpu synchronization requires the " - "completion function to be set"; - CHECK(ahwb_written_(true)) + ABSL_CHECK(ahwb_written_) + << "Ahwb-to-Cpu synchronization requires the " + "completion function to be set"; + ABSL_CHECK(ahwb_written_(true)) << "An error oqcured while waiting for the buffer to be written"; } } @@ -432,7 +435,7 @@ void* Tensor::MapAhwbToCpuRead() const { auto error = AHardwareBuffer_lock(ahwb_, AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN, ssbo_written_, nullptr, &ptr); - CHECK(error == 0) << "AHardwareBuffer_lock " << error; + ABSL_CHECK(error == 0) << "AHardwareBuffer_lock " << error; close(ssbo_written_); ssbo_written_ = -1; return ptr; @@ -450,7 +453,7 @@ void* Tensor::MapAhwbToCpuWrite() const { void* ptr; auto error = AHardwareBuffer_lock( ahwb_, AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN, -1, nullptr, &ptr); - CHECK(error == 0) << "AHardwareBuffer_lock " << error; + ABSL_CHECK(error == 0) << "AHardwareBuffer_lock " << error; return ptr; } } diff --git a/mediapipe/framework/graph_output_stream.cc b/mediapipe/framework/graph_output_stream.cc index de024dfe5..e456c6535 100644 --- a/mediapipe/framework/graph_output_stream.cc +++ b/mediapipe/framework/graph_output_stream.cc @@ -14,6 +14,7 @@ #include "mediapipe/framework/graph_output_stream.h" +#include "absl/log/absl_check.h" #include "absl/synchronization/mutex.h" #include "mediapipe/framework/port/status.h" @@ -153,7 +154,7 @@ void OutputStreamPollerImpl::Reset() { } void OutputStreamPollerImpl::SetMaxQueueSize(int queue_size) { - CHECK(queue_size >= -1) + ABSL_CHECK(queue_size >= -1) << "Max queue size must be either -1 or non-negative."; input_stream_handler_->SetMaxQueueSize(queue_size); } @@ -175,7 +176,7 @@ void OutputStreamPollerImpl::NotifyError() { } bool OutputStreamPollerImpl::Next(Packet* packet) { - CHECK(packet); + ABSL_CHECK(packet); bool empty_queue = true; bool timestamp_bound_changed = false; Timestamp min_timestamp = Timestamp::Unset(); @@ -212,7 +213,7 @@ bool OutputStreamPollerImpl::Next(Packet* packet) { bool stream_is_done = false; *packet = input_stream_->PopPacketAtTimestamp( min_timestamp, &num_packets_dropped, &stream_is_done); - CHECK_EQ(num_packets_dropped, 0) + ABSL_CHECK_EQ(num_packets_dropped, 0) << absl::Substitute("Dropped $0 packet(s) on input stream \"$1\".", num_packets_dropped, input_stream_->Name()); } else if (timestamp_bound_changed) { diff --git a/mediapipe/framework/graph_service.h b/mediapipe/framework/graph_service.h index 12b2ccb3a..95f55bbd1 100644 --- a/mediapipe/framework/graph_service.h +++ b/mediapipe/framework/graph_service.h @@ -19,6 +19,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/strings/str_cat.h" #include "mediapipe/framework/packet.h" #include "mediapipe/framework/port/status.h" @@ -125,7 +126,7 @@ class ServiceBinding { public: bool IsAvailable() { return service_ != nullptr; } T& GetObject() { - CHECK(service_) << "Service is unavailable."; + ABSL_CHECK(service_) << "Service is unavailable."; return *service_; } diff --git a/mediapipe/framework/graph_validation_test.cc b/mediapipe/framework/graph_validation_test.cc index c98983838..3982adbe5 100644 --- a/mediapipe/framework/graph_validation_test.cc +++ b/mediapipe/framework/graph_validation_test.cc @@ -19,6 +19,7 @@ #include +#include "absl/log/absl_check.h" #include "mediapipe/framework/calculator_framework.h" #include "mediapipe/framework/port/gmock.h" #include "mediapipe/framework/port/gtest.h" @@ -121,7 +122,7 @@ TEST(GraphValidationTest, InitializeGraphFromLinker) { TEST(GraphValidationTest, InitializeTemplateFromProtos) { mediapipe::tool::TemplateParser::Parser parser; CalculatorGraphTemplate config_1; - CHECK(parser.ParseFromString(R"( + ABSL_CHECK(parser.ParseFromString(R"( type: "PassThroughGraph" input_stream: % "INPUT:" + in_name % output_stream: "OUTPUT:stream_2" @@ -132,7 +133,7 @@ TEST(GraphValidationTest, InitializeTemplateFromProtos) { output_stream: "stream_2" # Same as input. } )", - &config_1)); + &config_1)); auto config_2 = ParseTextProtoOrDie(R"pb( input_stream: "INPUT:stream_1" output_stream: "OUTPUT:stream_2" diff --git a/mediapipe/framework/input_side_packet_handler.cc b/mediapipe/framework/input_side_packet_handler.cc index 9b01cc31a..b2eccf0db 100644 --- a/mediapipe/framework/input_side_packet_handler.cc +++ b/mediapipe/framework/input_side_packet_handler.cc @@ -14,6 +14,7 @@ #include "mediapipe/framework/input_side_packet_handler.h" +#include "absl/log/absl_check.h" #include "mediapipe/framework/port/logging.h" #include "mediapipe/framework/port/ret_check.h" #include "mediapipe/framework/port/status_builder.h" @@ -82,7 +83,7 @@ absl::Status InputSidePacketHandler::SetInternal(CollectionItemId id, void InputSidePacketHandler::TriggerErrorCallback( const absl::Status& status) const { - CHECK(error_callback_); + ABSL_CHECK(error_callback_); error_callback_(status); } diff --git a/mediapipe/framework/input_stream_handler.cc b/mediapipe/framework/input_stream_handler.cc index a7bd9ef43..e222c2e6c 100644 --- a/mediapipe/framework/input_stream_handler.cc +++ b/mediapipe/framework/input_stream_handler.cc @@ -14,6 +14,7 @@ #include "mediapipe/framework/input_stream_handler.h" +#include "absl/log/absl_check.h" #include "absl/strings/str_join.h" #include "absl/strings/substitute.h" #include "mediapipe/framework/collection_item_id.h" @@ -102,7 +103,7 @@ void InputStreamHandler::SetHeader(CollectionItemId id, const Packet& header) { return; } if (!input_stream_managers_.Get(id)->BackEdge()) { - CHECK_GT(unset_header_count_, 0); + ABSL_CHECK_GT(unset_header_count_, 0); if (unset_header_count_.fetch_sub(1, std::memory_order_acq_rel) == 1) { headers_ready_callback_(); } @@ -111,7 +112,7 @@ void InputStreamHandler::SetHeader(CollectionItemId id, const Packet& header) { void InputStreamHandler::UpdateInputShardHeaders( InputStreamShardSet* input_shards) { - CHECK(input_shards); + ABSL_CHECK(input_shards); for (CollectionItemId id = input_stream_managers_.BeginId(); id < input_stream_managers_.EndId(); ++id) { input_shards->Get(id).SetHeader(input_stream_managers_.Get(id)->Header()); @@ -198,7 +199,7 @@ bool InputStreamHandler::ScheduleInvocations(int max_allowance, TraceEvent(TraceEvent::READY_FOR_PROCESS) .set_node_id(calculator_context->NodeId())); } else { - CHECK(node_readiness == NodeReadiness::kReadyForClose); + ABSL_CHECK(node_readiness == NodeReadiness::kReadyForClose); // If any parallel invocations are in progress or a calculator context has // been prepared for Close(), we shouldn't prepare another calculator // context for Close(). @@ -302,7 +303,7 @@ void InputStreamHandler::SetNextTimestampBound(CollectionItemId id, void InputStreamHandler::ClearCurrentInputs( CalculatorContext* calculator_context) { - CHECK(calculator_context); + ABSL_CHECK(calculator_context); calculator_context_manager_->PopInputTimestampFromContext(calculator_context); for (auto& input : calculator_context->Inputs()) { // Invokes InputStreamShard's private method to clear packet. @@ -317,18 +318,20 @@ void InputStreamHandler::Close() { } void InputStreamHandler::SetBatchSize(int batch_size) { - CHECK(!calculator_run_in_parallel_ || batch_size == 1) + ABSL_CHECK(!calculator_run_in_parallel_ || batch_size == 1) << "Batching cannot be combined with parallel execution."; - CHECK(!late_preparation_ || batch_size == 1) + ABSL_CHECK(!late_preparation_ || batch_size == 1) << "Batching cannot be combined with late preparation."; - CHECK_GE(batch_size, 1) << "Batch size has to be greater than or equal to 1."; + ABSL_CHECK_GE(batch_size, 1) + << "Batch size has to be greater than or equal to 1."; // Source nodes shouldn't specify batch_size even if it's set to 1. - CHECK_GE(NumInputStreams(), 0) << "Source nodes cannot batch input packets."; + ABSL_CHECK_GE(NumInputStreams(), 0) + << "Source nodes cannot batch input packets."; batch_size_ = batch_size; } void InputStreamHandler::SetLatePreparation(bool late_preparation) { - CHECK(batch_size_ == 1 || !late_preparation_) + ABSL_CHECK(batch_size_ == 1 || !late_preparation_) << "Batching cannot be combined with late preparation."; late_preparation_ = late_preparation; } @@ -404,15 +407,15 @@ Timestamp SyncSet::MinPacketTimestamp() const { void SyncSet::FillInputSet(Timestamp input_timestamp, InputStreamShardSet* input_set) { - CHECK(input_timestamp.IsAllowedInStream()); - CHECK(input_set); + ABSL_CHECK(input_timestamp.IsAllowedInStream()); + ABSL_CHECK(input_set); for (CollectionItemId id : stream_ids_) { const auto& stream = input_stream_handler_->input_stream_managers_.Get(id); int num_packets_dropped = 0; bool stream_is_done = false; Packet current_packet = stream->PopPacketAtTimestamp( input_timestamp, &num_packets_dropped, &stream_is_done); - CHECK_EQ(num_packets_dropped, 0) + ABSL_CHECK_EQ(num_packets_dropped, 0) << absl::Substitute("Dropped $0 packet(s) on input stream \"$1\".", num_packets_dropped, stream->Name()); input_stream_handler_->AddPacketToShard( diff --git a/mediapipe/framework/input_stream_manager.cc b/mediapipe/framework/input_stream_manager.cc index 1af2e2cc8..fe63b62e3 100644 --- a/mediapipe/framework/input_stream_manager.cc +++ b/mediapipe/framework/input_stream_manager.cc @@ -17,6 +17,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/strings/str_cat.h" #include "absl/synchronization/mutex.h" #include "mediapipe/framework/packet.h" @@ -244,7 +245,7 @@ Timestamp InputStreamManager::MinTimestampOrBoundHelper() const Packet InputStreamManager::PopPacketAtTimestamp(Timestamp timestamp, int* num_packets_dropped, bool* stream_is_done) { - CHECK(enable_timestamps_); + ABSL_CHECK(enable_timestamps_); *num_packets_dropped = -1; *stream_is_done = false; bool queue_became_non_full = false; @@ -252,7 +253,7 @@ Packet InputStreamManager::PopPacketAtTimestamp(Timestamp timestamp, { absl::MutexLock stream_lock(&stream_mutex_); // Make sure timestamp didn't decrease from last time. - CHECK_LE(last_select_timestamp_, timestamp); + ABSL_CHECK_LE(last_select_timestamp_, timestamp); last_select_timestamp_ = timestamp; // Make sure AddPacket and SetNextTimestampBound are not called with @@ -299,7 +300,7 @@ Packet InputStreamManager::PopPacketAtTimestamp(Timestamp timestamp, } Packet InputStreamManager::PopQueueHead(bool* stream_is_done) { - CHECK(!enable_timestamps_); + ABSL_CHECK(!enable_timestamps_); *stream_is_done = false; bool queue_became_non_full = false; Packet packet; diff --git a/mediapipe/framework/input_stream_shard.cc b/mediapipe/framework/input_stream_shard.cc index 8e3348dd6..c7d1df8a3 100644 --- a/mediapipe/framework/input_stream_shard.cc +++ b/mediapipe/framework/input_stream_shard.cc @@ -14,12 +14,14 @@ #include "mediapipe/framework/input_stream_shard.h" +#include "absl/log/absl_check.h" + namespace mediapipe { void InputStreamShard::AddPacket(Packet&& value, bool is_done) { // A packet can be added if the shard is still active or the packet being // added is empty. An empty packet corresponds to absence of a packet. - CHECK(!is_done_ || value.IsEmpty()); + ABSL_CHECK(!is_done_ || value.IsEmpty()); packet_queue_.emplace(std::move(value)); is_done_ = is_done; } diff --git a/mediapipe/framework/output_side_packet_impl.cc b/mediapipe/framework/output_side_packet_impl.cc index 94bc518f8..dcb541408 100644 --- a/mediapipe/framework/output_side_packet_impl.cc +++ b/mediapipe/framework/output_side_packet_impl.cc @@ -14,6 +14,7 @@ #include "mediapipe/framework/output_side_packet_impl.h" +#include "absl/log/absl_check.h" #include "mediapipe/framework/port/logging.h" #include "mediapipe/framework/port/source_location.h" #include "mediapipe/framework/port/status_builder.h" @@ -42,7 +43,7 @@ void OutputSidePacketImpl::Set(const Packet& packet) { void OutputSidePacketImpl::AddMirror( InputSidePacketHandler* input_side_packet_handler, CollectionItemId id) { - CHECK(input_side_packet_handler); + ABSL_CHECK(input_side_packet_handler); mirrors_.emplace_back(input_side_packet_handler, id); } @@ -81,7 +82,7 @@ absl::Status OutputSidePacketImpl::SetInternal(const Packet& packet) { void OutputSidePacketImpl::TriggerErrorCallback( const absl::Status& status) const { - CHECK(error_callback_); + ABSL_CHECK(error_callback_); error_callback_(status); } diff --git a/mediapipe/framework/output_stream_handler.cc b/mediapipe/framework/output_stream_handler.cc index ba8f46718..377de6c88 100644 --- a/mediapipe/framework/output_stream_handler.cc +++ b/mediapipe/framework/output_stream_handler.cc @@ -14,6 +14,7 @@ #include "mediapipe/framework/output_stream_handler.h" +#include "absl/log/absl_check.h" #include "absl/synchronization/mutex.h" #include "mediapipe/framework/collection_item_id.h" #include "mediapipe/framework/output_stream_shard.h" @@ -31,7 +32,7 @@ absl::Status OutputStreamHandler::InitializeOutputStreamManagers( absl::Status OutputStreamHandler::SetupOutputShards( OutputStreamShardSet* output_shards) { - CHECK(output_shards); + ABSL_CHECK(output_shards); for (CollectionItemId id = output_stream_managers_.BeginId(); id < output_stream_managers_.EndId(); ++id) { OutputStreamManager* manager = output_stream_managers_.Get(id); @@ -52,7 +53,7 @@ void OutputStreamHandler::PrepareForRun( } void OutputStreamHandler::Open(OutputStreamShardSet* output_shards) { - CHECK(output_shards); + ABSL_CHECK(output_shards); PropagateOutputPackets(Timestamp::Unstarted(), output_shards); for (auto& manager : output_stream_managers_) { manager->PropagateHeader(); @@ -62,7 +63,7 @@ void OutputStreamHandler::Open(OutputStreamShardSet* output_shards) { void OutputStreamHandler::PrepareOutputs(Timestamp input_timestamp, OutputStreamShardSet* output_shards) { - CHECK(output_shards); + ABSL_CHECK(output_shards); for (CollectionItemId id = output_stream_managers_.BeginId(); id < output_stream_managers_.EndId(); ++id) { output_stream_managers_.Get(id)->ResetShard(&output_shards->Get(id)); @@ -79,7 +80,7 @@ void OutputStreamHandler::UpdateTaskTimestampBound(Timestamp timestamp) { if (task_timestamp_bound_ == timestamp) { return; } - CHECK_GT(timestamp, task_timestamp_bound_); + ABSL_CHECK_GT(timestamp, task_timestamp_bound_); task_timestamp_bound_ = timestamp; if (propagation_state_ == kPropagatingBound) { propagation_state_ = kPropagationPending; @@ -149,7 +150,7 @@ void OutputStreamHandler::Close(OutputStreamShardSet* output_shards) { void OutputStreamHandler::PropagateOutputPackets( Timestamp input_timestamp, OutputStreamShardSet* output_shards) { - CHECK(output_shards); + ABSL_CHECK(output_shards); for (CollectionItemId id = output_stream_managers_.BeginId(); id < output_stream_managers_.EndId(); ++id) { OutputStreamManager* manager = output_stream_managers_.Get(id); diff --git a/mediapipe/framework/output_stream_handler.h b/mediapipe/framework/output_stream_handler.h index 0b8dbed2c..cb6b2d6e1 100644 --- a/mediapipe/framework/output_stream_handler.h +++ b/mediapipe/framework/output_stream_handler.h @@ -25,6 +25,7 @@ // TODO: Move protos in another CL after the C++ code migration. #include "absl/base/thread_annotations.h" +#include "absl/log/absl_check.h" #include "absl/synchronization/mutex.h" #include "mediapipe/framework/calculator_context_manager.h" #include "mediapipe/framework/collection.h" @@ -63,7 +64,7 @@ class OutputStreamHandler { calculator_context_manager_(calculator_context_manager), options_(options), calculator_run_in_parallel_(calculator_run_in_parallel) { - CHECK(calculator_context_manager_); + ABSL_CHECK(calculator_context_manager_); } virtual ~OutputStreamHandler() = default; diff --git a/mediapipe/framework/output_stream_manager.cc b/mediapipe/framework/output_stream_manager.cc index b092313e2..0cb592943 100644 --- a/mediapipe/framework/output_stream_manager.cc +++ b/mediapipe/framework/output_stream_manager.cc @@ -14,6 +14,7 @@ #include "mediapipe/framework/output_stream_manager.h" +#include "absl/log/absl_check.h" #include "absl/synchronization/mutex.h" #include "mediapipe/framework/input_stream_handler.h" #include "mediapipe/framework/port/status_builder.h" @@ -80,7 +81,7 @@ void OutputStreamManager::PropagateHeader() { void OutputStreamManager::AddMirror(InputStreamHandler* input_stream_handler, CollectionItemId id) { - CHECK(input_stream_handler); + ABSL_CHECK(input_stream_handler); mirrors_.emplace_back(input_stream_handler, id); } @@ -163,7 +164,7 @@ Timestamp OutputStreamManager::ComputeOutputTimestampBound( // TODO Consider moving the propagation logic to OutputStreamHandler. void OutputStreamManager::PropagateUpdatesToMirrors( Timestamp next_timestamp_bound, OutputStreamShard* output_stream_shard) { - CHECK(output_stream_shard); + ABSL_CHECK(output_stream_shard); { if (next_timestamp_bound != Timestamp::Unset()) { absl::MutexLock lock(&stream_mutex_); diff --git a/mediapipe/framework/output_stream_poller.h b/mediapipe/framework/output_stream_poller.h index 26c0e72b2..98ebda313 100644 --- a/mediapipe/framework/output_stream_poller.h +++ b/mediapipe/framework/output_stream_poller.h @@ -17,6 +17,7 @@ #include +#include "absl/log/absl_check.h" #include "mediapipe/framework/graph_output_stream.h" namespace mediapipe { @@ -34,7 +35,7 @@ class OutputStreamPoller { // Resets OutputStramPollerImpl and cleans the internal packet queue. void Reset() { auto poller = internal_poller_impl_.lock(); - CHECK(poller) << "OutputStreamPollerImpl is already destroyed."; + ABSL_CHECK(poller) << "OutputStreamPollerImpl is already destroyed."; poller->Reset(); } @@ -50,14 +51,14 @@ class OutputStreamPoller { void SetMaxQueueSize(int queue_size) { auto poller = internal_poller_impl_.lock(); - CHECK(poller) << "OutputStreamPollerImpl is already destroyed."; + ABSL_CHECK(poller) << "OutputStreamPollerImpl is already destroyed."; return poller->SetMaxQueueSize(queue_size); } // Returns the number of packets in the queue. int QueueSize() { auto poller = internal_poller_impl_.lock(); - CHECK(poller) << "OutputStreamPollerImpl is already destroyed."; + ABSL_CHECK(poller) << "OutputStreamPollerImpl is already destroyed."; return poller->QueueSize(); } diff --git a/mediapipe/framework/output_stream_shard.cc b/mediapipe/framework/output_stream_shard.cc index 682c704c0..3b24321fb 100644 --- a/mediapipe/framework/output_stream_shard.cc +++ b/mediapipe/framework/output_stream_shard.cc @@ -14,6 +14,7 @@ #include "mediapipe/framework/output_stream_shard.h" +#include "absl/log/absl_check.h" #include "mediapipe/framework/port/source_location.h" #include "mediapipe/framework/port/status.h" #include "mediapipe/framework/port/status_builder.h" @@ -23,7 +24,7 @@ namespace mediapipe { OutputStreamShard::OutputStreamShard() : closed_(false) {} void OutputStreamShard::SetSpec(OutputStreamSpec* output_stream_spec) { - CHECK(output_stream_spec); + ABSL_CHECK(output_stream_spec); output_stream_spec_ = output_stream_spec; } diff --git a/mediapipe/framework/output_stream_shard.h b/mediapipe/framework/output_stream_shard.h index 718174c45..81a897591 100644 --- a/mediapipe/framework/output_stream_shard.h +++ b/mediapipe/framework/output_stream_shard.h @@ -18,6 +18,7 @@ #include #include +#include "absl/log/absl_check.h" #include "mediapipe/framework/output_stream.h" #include "mediapipe/framework/packet.h" #include "mediapipe/framework/packet_type.h" @@ -34,7 +35,7 @@ struct OutputStreamSpec { // Triggers the error callback with absl::Status info when an error // occurs. void TriggerErrorCallback(const absl::Status& status) const { - CHECK(error_callback); + ABSL_CHECK(error_callback); error_callback(status); } diff --git a/mediapipe/framework/packet.cc b/mediapipe/framework/packet.cc index 05d3c6c52..edcdaf19f 100644 --- a/mediapipe/framework/packet.cc +++ b/mediapipe/framework/packet.cc @@ -14,6 +14,7 @@ #include "mediapipe/framework/packet.h" +#include "absl/log/absl_check.h" #include "absl/strings/str_cat.h" #include "mediapipe/framework/port.h" #include "mediapipe/framework/port/canonical_errors.h" @@ -135,10 +136,11 @@ absl::Status Packet::ValidateAsProtoMessageLite() const { } const proto_ns::MessageLite& Packet::GetProtoMessageLite() const { - CHECK(holder_ != nullptr) << "The packet is empty."; + ABSL_CHECK(holder_ != nullptr) << "The packet is empty."; const proto_ns::MessageLite* proto = holder_->GetProtoMessageLite(); - CHECK(proto != nullptr) << "The Packet stores '" << holder_->DebugTypeName() - << "', it cannot be converted to MessageLite type."; + ABSL_CHECK(proto != nullptr) + << "The Packet stores '" << holder_->DebugTypeName() + << "', it cannot be converted to MessageLite type."; return *proto; } diff --git a/mediapipe/framework/packet.h b/mediapipe/framework/packet.h index f42164000..770dd9d4c 100644 --- a/mediapipe/framework/packet.h +++ b/mediapipe/framework/packet.h @@ -24,6 +24,7 @@ #include #include "absl/base/macros.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/memory/memory.h" #include "absl/strings/str_cat.h" @@ -725,7 +726,7 @@ inline Packet& Packet::operator=(Packet&& packet) { inline bool Packet::IsEmpty() const { return holder_ == nullptr; } inline TypeId Packet::GetTypeId() const { - CHECK(holder_); + ABSL_CHECK(holder_); return holder_->GetTypeId(); } @@ -744,13 +745,13 @@ inline Timestamp Packet::Timestamp() const { return timestamp_; } template Packet Adopt(const T* ptr) { - CHECK(ptr != nullptr); + ABSL_CHECK(ptr != nullptr); return packet_internal::Create(new packet_internal::Holder(ptr)); } template Packet PointToForeign(const T* ptr) { - CHECK(ptr != nullptr); + ABSL_CHECK(ptr != nullptr); return packet_internal::Create(new packet_internal::ForeignHolder(ptr)); } diff --git a/mediapipe/framework/packet_type.h b/mediapipe/framework/packet_type.h index ee1074c34..10496f052 100644 --- a/mediapipe/framework/packet_type.h +++ b/mediapipe/framework/packet_type.h @@ -23,6 +23,7 @@ #include #include "absl/base/macros.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/status/status.h" #include "absl/strings/str_split.h" @@ -163,7 +164,7 @@ class PacketTypeSetErrorHandler { if (!missing_) { missing_ = absl::make_unique(); } - CHECK(!missing_->initialized_errors); + ABSL_CHECK(!missing_->initialized_errors); std::string key = absl::StrCat(tag, ":", index); return missing_->entries[key]; } @@ -182,9 +183,9 @@ class PacketTypeSetErrorHandler { // Get the error messages that have been deferred. // This function can only be called if HasError() is true. const std::vector& ErrorMessages() const { - CHECK(missing_) << "ErrorMessages() can only be called if errors have " - "occurred. Call HasError() before calling this " - "function."; + ABSL_CHECK(missing_) << "ErrorMessages() can only be called if errors have " + "occurred. Call HasError() before calling this " + "function."; if (!missing_->initialized_errors) { for (const auto& entry : missing_->entries) { // Optional entries that were missing are not considered errors. diff --git a/mediapipe/framework/port/BUILD b/mediapipe/framework/port/BUILD index 5894e4715..f8c95d68b 100644 --- a/mediapipe/framework/port/BUILD +++ b/mediapipe/framework/port/BUILD @@ -326,6 +326,7 @@ cc_library( ":core_proto", ":logging", "//mediapipe/framework:port", + "@com_google_absl//absl/log:absl_check", ], ) diff --git a/mediapipe/framework/port/parse_text_proto.h b/mediapipe/framework/port/parse_text_proto.h index c352d4f01..722ded6ea 100644 --- a/mediapipe/framework/port/parse_text_proto.h +++ b/mediapipe/framework/port/parse_text_proto.h @@ -15,6 +15,7 @@ #ifndef MEDIAPIPE_PORT_PARSE_TEXT_PROTO_H_ #define MEDIAPIPE_PORT_PARSE_TEXT_PROTO_H_ +#include "absl/log/absl_check.h" #include "mediapipe/framework/port/core_proto_inc.h" #include "mediapipe/framework/port/logging.h" #include "mediapipe/framework/port/proto_ns.h" @@ -29,7 +30,7 @@ bool ParseTextProto(const std::string& input, T* proto) { template T ParseTextProtoOrDie(const std::string& input) { T result; - CHECK(ParseTextProto(input, &result)); + ABSL_CHECK(ParseTextProto(input, &result)); return result; } diff --git a/mediapipe/framework/profiler/BUILD b/mediapipe/framework/profiler/BUILD index 434072f5b..99699f2cd 100644 --- a/mediapipe/framework/profiler/BUILD +++ b/mediapipe/framework/profiler/BUILD @@ -122,6 +122,7 @@ cc_library( "//mediapipe/framework/tool:name_util", "//mediapipe/framework/tool:tag_map", "//mediapipe/framework/tool:validate_name", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/memory", "@com_google_absl//absl/strings", @@ -257,6 +258,7 @@ cc_test( "//mediapipe/framework/tool:simulation_clock_executor", "//mediapipe/framework/tool:status_util", "@com_google_absl//absl/flags:flag", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/time", ], ) diff --git a/mediapipe/framework/profiler/gl_context_profiler.cc b/mediapipe/framework/profiler/gl_context_profiler.cc index ffd939f41..667d153da 100644 --- a/mediapipe/framework/profiler/gl_context_profiler.cc +++ b/mediapipe/framework/profiler/gl_context_profiler.cc @@ -14,6 +14,7 @@ #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/memory/memory.h" #include "absl/time/clock.h" diff --git a/mediapipe/framework/profiler/graph_profiler.cc b/mediapipe/framework/profiler/graph_profiler.cc index 068da3a09..949955111 100644 --- a/mediapipe/framework/profiler/graph_profiler.cc +++ b/mediapipe/framework/profiler/graph_profiler.cc @@ -17,6 +17,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/strings/substitute.h" #include "absl/synchronization/mutex.h" @@ -158,7 +159,7 @@ void GraphProfiler::Initialize( const ValidatedGraphConfig& validated_graph_config) { absl::WriterMutexLock lock(&profiler_mutex_); validated_graph_ = &validated_graph_config; - CHECK(!is_initialized_) + ABSL_CHECK(!is_initialized_) << "Cannot initialize the profiler for the same graph multiple times."; profiler_config_ = validated_graph_config.Config().profiler_config(); int64 interval_size_usec = profiler_config_.histogram_interval_size_usec(); @@ -190,7 +191,7 @@ void GraphProfiler::Initialize( } auto iter = calculator_profiles_.insert({node_name, profile}); - CHECK(iter.second) << absl::Substitute( + ABSL_CHECK(iter.second) << absl::Substitute( "Calculator \"$0\" has already been added.", node_name); } profile_builder_ = std::make_unique(this); @@ -201,7 +202,7 @@ void GraphProfiler::Initialize( void GraphProfiler::SetClock(const std::shared_ptr& clock) { absl::WriterMutexLock lock(&profiler_mutex_); - CHECK(clock) << "GraphProfiler::SetClock() is called with a nullptr."; + ABSL_CHECK(clock) << "GraphProfiler::SetClock() is called with a nullptr."; clock_ = clock; } @@ -386,7 +387,7 @@ std::set GraphProfiler::GetBackEdgeIds( tool::ParseTagIndex(input_stream_info.tag_index(), &tag, &index)) << absl::Substitute("Cannot parse TAG or index for the backedge \"$0\"", input_stream_info.tag_index()); - CHECK(0 <= index && index < input_tag_map.NumEntries(tag)) + ABSL_CHECK(0 <= index && index < input_tag_map.NumEntries(tag)) << absl::Substitute( "The input_stream_info for tag \"$0\" (index " "$1) does not match any input_stream.", @@ -445,7 +446,7 @@ void GraphProfiler::SetOpenRuntime(const CalculatorContext& calculator_context, const std::string& node_name = calculator_context.NodeName(); int64 time_usec = end_time_usec - start_time_usec; auto profile_iter = calculator_profiles_.find(node_name); - CHECK(profile_iter != calculator_profiles_.end()) << absl::Substitute( + ABSL_CHECK(profile_iter != calculator_profiles_.end()) << absl::Substitute( "Calculator \"$0\" has not been added during initialization.", calculator_context.NodeName()); CalculatorProfile* calculator_profile = &profile_iter->second; @@ -467,7 +468,7 @@ void GraphProfiler::SetCloseRuntime(const CalculatorContext& calculator_context, const std::string& node_name = calculator_context.NodeName(); int64 time_usec = end_time_usec - start_time_usec; auto profile_iter = calculator_profiles_.find(node_name); - CHECK(profile_iter != calculator_profiles_.end()) << absl::Substitute( + ABSL_CHECK(profile_iter != calculator_profiles_.end()) << absl::Substitute( "Calculator \"$0\" has not been added during initialization.", calculator_context.NodeName()); CalculatorProfile* calculator_profile = &profile_iter->second; @@ -545,7 +546,7 @@ void GraphProfiler::AddProcessSample( const std::string& node_name = calculator_context.NodeName(); auto profile_iter = calculator_profiles_.find(node_name); - CHECK(profile_iter != calculator_profiles_.end()) << absl::Substitute( + ABSL_CHECK(profile_iter != calculator_profiles_.end()) << absl::Substitute( "Calculator \"$0\" has not been added during initialization.", calculator_context.NodeName()); CalculatorProfile* calculator_profile = &profile_iter->second; diff --git a/mediapipe/framework/profiler/graph_tracer_test.cc b/mediapipe/framework/profiler/graph_tracer_test.cc index 07518aa6c..4fe9826c0 100644 --- a/mediapipe/framework/profiler/graph_tracer_test.cc +++ b/mediapipe/framework/profiler/graph_tracer_test.cc @@ -22,6 +22,7 @@ #include #include "absl/flags/flag.h" +#include "absl/log/absl_check.h" #include "absl/time/time.h" #include "mediapipe/framework/calculator.pb.h" #include "mediapipe/framework/calculator_framework.h" @@ -332,7 +333,7 @@ TEST_F(GraphTracerTest, GraphTrace) { class GraphTracerE2ETest : public ::testing::Test { protected: void SetUpPassThroughGraph() { - CHECK(proto_ns::TextFormat::ParseFromString(R"( + ABSL_CHECK(proto_ns::TextFormat::ParseFromString(R"( input_stream: "input_0" node { calculator: "LambdaCalculator" @@ -346,11 +347,11 @@ class GraphTracerE2ETest : public ::testing::Test { trace_enabled: true } )", - &graph_config_)); + &graph_config_)); } void SetUpDemuxInFlightGraph() { - CHECK(proto_ns::TextFormat::ParseFromString(R"( + ABSL_CHECK(proto_ns::TextFormat::ParseFromString(R"( node { calculator: "LambdaCalculator" input_side_packet: 'callback_2' @@ -404,7 +405,7 @@ class GraphTracerE2ETest : public ::testing::Test { trace_enabled: true } )", - &graph_config_)); + &graph_config_)); } absl::Time ParseTime(const std::string& date_time_str) { @@ -1372,7 +1373,7 @@ TEST_F(GraphTracerE2ETest, GpuTaskTrace) { // Show that trace_enabled activates the GlContextProfiler. TEST_F(GraphTracerE2ETest, GpuTracing) { - CHECK(proto_ns::TextFormat::ParseFromString(R"( + ABSL_CHECK(proto_ns::TextFormat::ParseFromString(R"( input_stream: "input_buffer" input_stream: "render_data" output_stream: "annotated_buffer" @@ -1386,7 +1387,7 @@ TEST_F(GraphTracerE2ETest, GpuTracing) { trace_enabled: true } )", - &graph_config_)); + &graph_config_)); // Create the CalculatorGraph with only trace_enabled set. MP_ASSERT_OK(graph_.Initialize(graph_config_, {})); diff --git a/mediapipe/framework/scheduler.cc b/mediapipe/framework/scheduler.cc index 23dc684cc..36effe016 100644 --- a/mediapipe/framework/scheduler.cc +++ b/mediapipe/framework/scheduler.cc @@ -19,6 +19,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/memory/memory.h" #include "absl/synchronization/mutex.h" #include "mediapipe/framework/calculator_graph.h" @@ -77,7 +78,7 @@ void Scheduler::Reset() { void Scheduler::CloseAllSourceNodes() { shared_.stopping = true; } void Scheduler::SetExecutor(Executor* executor) { - CHECK_EQ(state_, STATE_NOT_STARTED) + ABSL_CHECK_EQ(state_, STATE_NOT_STARTED) << "SetExecutor must not be called after the scheduler has started"; default_queue_.SetExecutor(executor); } @@ -147,7 +148,7 @@ void Scheduler::HandleIdle() { // Note: TryToScheduleNextSourceLayer unlocks and locks state_mutex_ // internally. bool did_activate = TryToScheduleNextSourceLayer(); - CHECK(did_activate || active_sources_.empty()); + ABSL_CHECK(did_activate || active_sources_.empty()); continue; } @@ -183,7 +184,7 @@ void Scheduler::HandleIdle() { void Scheduler::Quit() { // All calls to Calculator::Process() have returned (even if we had an // error). - CHECK(state_ == STATE_RUNNING || state_ == STATE_CANCELLING); + ABSL_CHECK(state_ == STATE_RUNNING || state_ == STATE_CANCELLING); SetQueuesRunning(false); shared_.timer.EndRun(); @@ -198,7 +199,7 @@ void Scheduler::Start() { shared_.timer.StartRun(); { absl::MutexLock lock(&state_mutex_); - CHECK_EQ(state_, STATE_NOT_STARTED); + ABSL_CHECK_EQ(state_, STATE_NOT_STARTED); state_ = STATE_RUNNING; SetQueuesRunning(true); @@ -326,15 +327,15 @@ void Scheduler::ClosedAllGraphInputStreams() { // container. void Scheduler::ScheduleNodeIfNotThrottled( CalculatorNode* node, CalculatorContext* calculator_context) { - DCHECK(node); - DCHECK(calculator_context); + ABSL_DCHECK(node); + ABSL_DCHECK(calculator_context); if (!graph_->IsNodeThrottled(node->Id())) { node->GetSchedulerQueue()->AddNode(node, calculator_context); } } void Scheduler::ScheduleNodeForOpen(CalculatorNode* node) { - DCHECK(node); + ABSL_DCHECK(node); VLOG(1) << "Scheduling OpenNode of calculator " << node->DebugName(); node->GetSchedulerQueue()->AddNodeForOpen(node); } @@ -344,7 +345,7 @@ void Scheduler::ScheduleUnthrottledReadyNodes( for (CalculatorNode* node : nodes_to_schedule) { // Source nodes always reuse the default calculator context because they // can't be executed in parallel. - CHECK(node->IsSource()); + ABSL_CHECK(node->IsSource()); CalculatorContext* default_context = node->GetDefaultCalculatorContext(); node->GetSchedulerQueue()->AddNode(node, default_context); } @@ -367,8 +368,8 @@ void Scheduler::CleanupActiveSources() { bool Scheduler::TryToScheduleNextSourceLayer() { VLOG(3) << "TryToScheduleNextSourceLayer"; - CHECK(active_sources_.empty()); - CHECK(!sources_queue_.empty()); + ABSL_CHECK(active_sources_.empty()); + ABSL_CHECK(!sources_queue_.empty()); if (!unopened_sources_.empty() && (*unopened_sources_.begin())->source_layer() < @@ -420,8 +421,9 @@ bool Scheduler::TryToScheduleNextSourceLayer() { } void Scheduler::AddUnopenedSourceNode(CalculatorNode* node) { - CHECK_EQ(state_, STATE_NOT_STARTED) << "AddUnopenedSourceNode can only be " - "called before starting the scheduler"; + ABSL_CHECK_EQ(state_, STATE_NOT_STARTED) + << "AddUnopenedSourceNode can only be " + "called before starting the scheduler"; unopened_sources_.insert(node); } @@ -438,7 +440,7 @@ void Scheduler::AssignNodeToSchedulerQueue(CalculatorNode* node) { SchedulerQueue* queue; if (!node->Executor().empty()) { auto iter = non_default_queues_.find(node->Executor()); - CHECK(iter != non_default_queues_.end()); + ABSL_CHECK(iter != non_default_queues_.end()); queue = iter->second.get(); } else { queue = &default_queue_; @@ -521,7 +523,7 @@ void Scheduler::CleanupAfterRun() { while (!sources_queue_.empty()) { sources_queue_.pop(); } - CHECK(app_thread_tasks_.empty()); + ABSL_CHECK(app_thread_tasks_.empty()); } for (auto queue : scheduler_queues_) { queue->CleanupAfterRun(); @@ -532,7 +534,7 @@ void Scheduler::CleanupAfterRun() { } internal::SchedulerTimes Scheduler::GetSchedulerTimes() { - CHECK_EQ(state_, STATE_TERMINATED); + ABSL_CHECK_EQ(state_, STATE_TERMINATED); return shared_.timer.GetSchedulerTimes(); } diff --git a/mediapipe/framework/scheduler_queue.cc b/mediapipe/framework/scheduler_queue.cc index 33214cf64..557d7e40e 100644 --- a/mediapipe/framework/scheduler_queue.cc +++ b/mediapipe/framework/scheduler_queue.cc @@ -18,6 +18,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/synchronization/mutex.h" #include "mediapipe/framework/calculator_node.h" #include "mediapipe/framework/executor.h" @@ -36,8 +37,8 @@ namespace internal { SchedulerQueue::Item::Item(CalculatorNode* node, CalculatorContext* cc) : node_(node), cc_(cc) { - CHECK(node); - CHECK(cc); + ABSL_CHECK(node); + ABSL_CHECK(cc); is_source_ = node->IsSource(); id_ = node->Id(); if (is_source_) { @@ -48,7 +49,7 @@ SchedulerQueue::Item::Item(CalculatorNode* node, CalculatorContext* cc) SchedulerQueue::Item::Item(CalculatorNode* node) : node_(node), cc_(nullptr), is_open_node_(true) { - CHECK(node); + ABSL_CHECK(node); is_source_ = node->IsSource(); id_ = node->Id(); if (is_source_) { @@ -104,7 +105,7 @@ bool SchedulerQueue::IsIdle() { void SchedulerQueue::SetRunning(bool running) { absl::MutexLock lock(&mutex_); running_count_ += running ? 1 : -1; - DCHECK_LE(running_count_, 1); + ABSL_DCHECK_LE(running_count_, 1); } void SchedulerQueue::AddNode(CalculatorNode* node, CalculatorContext* cc) { @@ -117,7 +118,7 @@ void SchedulerQueue::AddNode(CalculatorNode* node, CalculatorContext* cc) { // Only happens when the framework tries to schedule an unthrottled source // node while it's running. For non-source nodes, if a calculator context is // prepared, it is committed to be scheduled. - CHECK(node->IsSource()) << node->DebugName(); + ABSL_CHECK(node->IsSource()) << node->DebugName(); return; } AddItemToQueue(Item(node, cc)); @@ -192,15 +193,16 @@ void SchedulerQueue::RunNextTask() { { absl::MutexLock lock(&mutex_); - CHECK(!queue_.empty()) << "Called RunNextTask when the queue is empty. " - "This should not happen."; + ABSL_CHECK(!queue_.empty()) + << "Called RunNextTask when the queue is empty. " + "This should not happen."; node = queue_.top().Node(); calculator_context = queue_.top().Context(); is_open_node = queue_.top().IsOpenNode(); queue_.pop(); - CHECK(!node->Closed()) + ABSL_CHECK(!node->Closed()) << "Scheduled a node that was closed. This should not happen."; } @@ -211,7 +213,7 @@ void SchedulerQueue::RunNextTask() { // do it here to ensure all executors are covered. AUTORELEASEPOOL { if (is_open_node) { - DCHECK(!calculator_context); + ABSL_DCHECK(!calculator_context); OpenCalculatorNode(node); } else { RunCalculatorNode(node, calculator_context); @@ -221,7 +223,7 @@ void SchedulerQueue::RunNextTask() { bool is_idle; { absl::MutexLock lock(&mutex_); - DCHECK_GT(num_pending_tasks_, 0); + ABSL_DCHECK_GT(num_pending_tasks_, 0); --num_pending_tasks_; is_idle = IsIdle(); } @@ -266,8 +268,8 @@ void SchedulerQueue::RunCalculatorNode(CalculatorNode* node, // that all sources will be closed and no further sources should be // scheduled. The graph will be terminated as soon as its scheduler // queue becomes empty. - CHECK(!node->IsSource()); // ProcessNode takes care of StatusStop() - // from sources. + ABSL_CHECK(!node->IsSource()); // ProcessNode takes care of + // StatusStop() from sources. shared_->stopping = true; } else { // If we have an error in this calculator. @@ -299,8 +301,8 @@ void SchedulerQueue::CleanupAfterRun() { { absl::MutexLock lock(&mutex_); was_idle = IsIdle(); - CHECK_EQ(num_pending_tasks_, 0); - CHECK_EQ(num_tasks_to_add_, queue_.size()); + ABSL_CHECK_EQ(num_pending_tasks_, 0); + ABSL_CHECK_EQ(num_tasks_to_add_, queue_.size()); num_tasks_to_add_ = 0; while (!queue_.empty()) { queue_.pop(); diff --git a/mediapipe/framework/stream_handler/BUILD b/mediapipe/framework/stream_handler/BUILD index 1d0b237da..c3eb334fa 100644 --- a/mediapipe/framework/stream_handler/BUILD +++ b/mediapipe/framework/stream_handler/BUILD @@ -61,7 +61,7 @@ cc_library( "//mediapipe/framework:input_stream_handler", "//mediapipe/framework:mediapipe_options_cc_proto", "//mediapipe/framework/tool:tag_map", - "@com_google_absl//absl/log:check", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/status", ], alwayslink = 1, @@ -90,7 +90,7 @@ cc_library( "//mediapipe/framework:input_stream_handler", "//mediapipe/framework:mediapipe_options_cc_proto", "//mediapipe/framework/tool:tag_map", - "@com_google_absl//absl/log:check", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", ], alwayslink = 1, @@ -111,8 +111,8 @@ cc_library( "//mediapipe/framework:packet", "//mediapipe/framework/tool:tag_map", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", - "@com_google_absl//absl/log:check", "@com_google_absl//absl/synchronization", ], alwayslink = 1, @@ -130,7 +130,7 @@ cc_library( "//mediapipe/framework:mediapipe_options_cc_proto", "//mediapipe/framework/tool:tag_map", "@com_google_absl//absl/base:core_headers", - "@com_google_absl//absl/log:check", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/status", "@com_google_absl//absl/synchronization", ], @@ -151,6 +151,7 @@ cc_library( "//mediapipe/framework:packet_set", "//mediapipe/framework:timestamp", "//mediapipe/framework/tool:tag_map", + "@com_google_absl//absl/log:absl_check", ], alwayslink = 1, ) @@ -164,7 +165,7 @@ cc_library( "//mediapipe/framework:calculator_framework", "//mediapipe/framework:collection_item_id", "//mediapipe/framework:input_stream_handler", - "@com_google_absl//absl/log:check", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", "@com_google_absl//absl/synchronization", ], @@ -188,8 +189,8 @@ cc_library( "//mediapipe/framework/port:status", "//mediapipe/framework/tool:tag_map", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", - "@com_google_absl//absl/log:check", "@com_google_absl//absl/status", "@com_google_absl//absl/synchronization", ], @@ -210,7 +211,7 @@ cc_library( "//mediapipe/framework:timestamp", "//mediapipe/framework/tool:validate_name", "@com_google_absl//absl/base:core_headers", - "@com_google_absl//absl/log:check", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/status", "@com_google_absl//absl/strings", "@com_google_absl//absl/synchronization", @@ -230,6 +231,7 @@ cc_test( "//mediapipe/framework/tool:tag_map", "//mediapipe/framework/tool:tag_map_helper", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/memory", ], ) @@ -248,6 +250,7 @@ cc_test( "//mediapipe/framework/tool:tag_map", "//mediapipe/framework/tool:tag_map_helper", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/memory", ], ) diff --git a/mediapipe/framework/stream_handler/barrier_input_stream_handler.cc b/mediapipe/framework/stream_handler/barrier_input_stream_handler.cc index b483693c0..4150fafac 100644 --- a/mediapipe/framework/stream_handler/barrier_input_stream_handler.cc +++ b/mediapipe/framework/stream_handler/barrier_input_stream_handler.cc @@ -16,7 +16,7 @@ #include #include -#include "absl/log/check.h" +#include "absl/log/absl_check.h" #include "absl/status/status.h" #include "mediapipe/framework/calculator_framework.h" #include "mediapipe/framework/collection_item_id.h" @@ -39,7 +39,7 @@ void BarrierInputStreamHandler::PrepareForRun( NodeReadiness BarrierInputStreamHandler::GetNodeReadiness( Timestamp* min_stream_timestamp) { - DCHECK(min_stream_timestamp); + ABSL_DCHECK(min_stream_timestamp); *min_stream_timestamp = Timestamp::Done(); bool all_available = true; for (const auto& stream : input_stream_managers_) { @@ -55,7 +55,7 @@ NodeReadiness BarrierInputStreamHandler::GetNodeReadiness( *min_stream_timestamp = std::min(*min_stream_timestamp, stream_timestamp); } - CHECK_NE(*min_stream_timestamp, Timestamp::Done()); + ABSL_CHECK_NE(*min_stream_timestamp, Timestamp::Done()); if (all_available) { return NodeReadiness::kReadyForProcess; } @@ -64,8 +64,8 @@ NodeReadiness BarrierInputStreamHandler::GetNodeReadiness( void BarrierInputStreamHandler::FillInputSet(Timestamp input_timestamp, InputStreamShardSet* input_set) { - CHECK(input_timestamp.IsAllowedInStream()); - CHECK(input_set); + ABSL_CHECK(input_timestamp.IsAllowedInStream()); + ABSL_CHECK(input_set); for (CollectionItemId id = input_stream_managers_.BeginId(); id < input_stream_managers_.EndId(); ++id) { auto& stream = input_stream_managers_.Get(id); diff --git a/mediapipe/framework/stream_handler/barrier_input_stream_handler_test.cc b/mediapipe/framework/stream_handler/barrier_input_stream_handler_test.cc index 9f341ba54..deb04fc39 100644 --- a/mediapipe/framework/stream_handler/barrier_input_stream_handler_test.cc +++ b/mediapipe/framework/stream_handler/barrier_input_stream_handler_test.cc @@ -18,6 +18,7 @@ #include #include "absl/base/macros.h" +#include "absl/log/absl_check.h" #include "absl/memory/memory.h" #include "mediapipe/framework/calculator_context.h" #include "mediapipe/framework/calculator_context_manager.h" @@ -105,7 +106,7 @@ class BarrierInputStreamHandlerTest : public ::testing::Test { void NotifyNoOp() {} void Schedule(CalculatorContext* calculator_context) { - CHECK(calculator_context); + ABSL_CHECK(calculator_context); calculator_context_ = calculator_context; } diff --git a/mediapipe/framework/stream_handler/early_close_input_stream_handler.cc b/mediapipe/framework/stream_handler/early_close_input_stream_handler.cc index 5c448a340..3a7dd8678 100644 --- a/mediapipe/framework/stream_handler/early_close_input_stream_handler.cc +++ b/mediapipe/framework/stream_handler/early_close_input_stream_handler.cc @@ -15,7 +15,7 @@ #include -#include "absl/log/check.h" +#include "absl/log/absl_check.h" #include "absl/strings/substitute.h" #include "mediapipe/framework/calculator_framework.h" #include "mediapipe/framework/collection_item_id.h" @@ -30,7 +30,7 @@ namespace mediapipe { // that will be available at the next timestamp. NodeReadiness EarlyCloseInputStreamHandler::GetNodeReadiness( Timestamp* min_stream_timestamp) { - DCHECK(min_stream_timestamp); + ABSL_DCHECK(min_stream_timestamp); *min_stream_timestamp = Timestamp::Done(); Timestamp min_bound = Timestamp::Done(); for (const auto& stream : input_stream_managers_) { @@ -46,21 +46,21 @@ NodeReadiness EarlyCloseInputStreamHandler::GetNodeReadiness( *min_stream_timestamp = std::min(*min_stream_timestamp, stream_timestamp); } - CHECK_NE(*min_stream_timestamp, Timestamp::Done()); + ABSL_CHECK_NE(*min_stream_timestamp, Timestamp::Done()); if (min_bound > *min_stream_timestamp) { return NodeReadiness::kReadyForProcess; } - CHECK_EQ(min_bound, *min_stream_timestamp); + ABSL_CHECK_EQ(min_bound, *min_stream_timestamp); return NodeReadiness::kNotReady; } // Only invoked when associated GetNodeReadiness() returned kReadyForProcess. void EarlyCloseInputStreamHandler::FillInputSet( Timestamp input_timestamp, InputStreamShardSet* input_set) { - CHECK(input_timestamp.IsAllowedInStream()); - CHECK(input_set); + ABSL_CHECK(input_timestamp.IsAllowedInStream()); + ABSL_CHECK(input_set); for (CollectionItemId id = input_stream_managers_.BeginId(); id < input_stream_managers_.EndId(); ++id) { auto& stream = input_stream_managers_.Get(id); @@ -68,7 +68,7 @@ void EarlyCloseInputStreamHandler::FillInputSet( bool stream_is_done = false; Packet current_packet = stream->PopPacketAtTimestamp( input_timestamp, &num_packets_dropped, &stream_is_done); - CHECK_EQ(num_packets_dropped, 0) + ABSL_CHECK_EQ(num_packets_dropped, 0) << absl::Substitute("Dropped $0 packet(s) on input stream \"$1\".", num_packets_dropped, stream->Name()); AddPacketToShard(&input_set->Get(id), std::move(current_packet), diff --git a/mediapipe/framework/stream_handler/fixed_size_input_stream_handler.cc b/mediapipe/framework/stream_handler/fixed_size_input_stream_handler.cc index 16119430b..cb4e0fafa 100644 --- a/mediapipe/framework/stream_handler/fixed_size_input_stream_handler.cc +++ b/mediapipe/framework/stream_handler/fixed_size_input_stream_handler.cc @@ -19,8 +19,8 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" -#include "absl/log/check.h" #include "absl/synchronization/mutex.h" #include "mediapipe/framework/calculator_context_manager.h" #include "mediapipe/framework/calculator_framework.h" @@ -135,7 +135,7 @@ void FixedSizeInputStreamHandler::EraseSurplusPackets(bool keep_one) { NodeReadiness FixedSizeInputStreamHandler::GetNodeReadiness( Timestamp* min_stream_timestamp) { - DCHECK(min_stream_timestamp); + ABSL_DCHECK(min_stream_timestamp); absl::MutexLock lock(&erase_mutex_); // kReadyForProcess is returned only once until FillInputSet completes. // In late_preparation mode, GetNodeReadiness must return kReadyForProcess @@ -179,7 +179,7 @@ void FixedSizeInputStreamHandler::MovePackets(CollectionItemId id, void FixedSizeInputStreamHandler::FillInputSet(Timestamp input_timestamp, InputStreamShardSet* input_set) { - CHECK(input_set); + ABSL_CHECK(input_set); absl::MutexLock lock(&erase_mutex_); if (!pending_) { ABSL_LOG(ERROR) << "FillInputSet called without GetNodeReadiness."; diff --git a/mediapipe/framework/stream_handler/immediate_input_stream_handler.cc b/mediapipe/framework/stream_handler/immediate_input_stream_handler.cc index 2d48c1a76..b2fc1aa8d 100644 --- a/mediapipe/framework/stream_handler/immediate_input_stream_handler.cc +++ b/mediapipe/framework/stream_handler/immediate_input_stream_handler.cc @@ -18,7 +18,7 @@ #include #include -#include "absl/log/check.h" +#include "absl/log/absl_check.h" #include "absl/status/status.h" #include "absl/synchronization/mutex.h" #include "mediapipe/framework/calculator_context_manager.h" @@ -83,7 +83,7 @@ NodeReadiness ImmediateInputStreamHandler::GetNodeReadiness( ready_timestamps_[i] = stream_ts; input_timestamp = std::min(input_timestamp, stream_ts); } else if (readiness == NodeReadiness::kReadyForClose) { - CHECK_EQ(stream_ts, Timestamp::Done()); + ABSL_CHECK_EQ(stream_ts, Timestamp::Done()); if (ProcessTimestampBounds()) { // With kReadyForClose, the timestamp-bound Done is returned. // TODO: Make all InputStreamHandlers process Done() like this. diff --git a/mediapipe/framework/stream_handler/immediate_input_stream_handler_test.cc b/mediapipe/framework/stream_handler/immediate_input_stream_handler_test.cc index e5de7f0c9..04b1c490b 100644 --- a/mediapipe/framework/stream_handler/immediate_input_stream_handler_test.cc +++ b/mediapipe/framework/stream_handler/immediate_input_stream_handler_test.cc @@ -18,6 +18,7 @@ #include #include "absl/base/macros.h" +#include "absl/log/absl_check.h" #include "absl/memory/memory.h" #include "mediapipe/framework/calculator_context.h" #include "mediapipe/framework/calculator_context_manager.h" @@ -104,7 +105,7 @@ class ImmediateInputStreamHandlerTest : public ::testing::Test { void NotifyNoOp() {} void Schedule(CalculatorContext* cc) { - CHECK(cc); + ABSL_CHECK(cc); cc_ = cc; } @@ -132,7 +133,7 @@ class ImmediateInputStreamHandlerTest : public ::testing::Test { } const InputStream& Input(const CollectionItemId& id) { - CHECK(cc_); + ABSL_CHECK(cc_); return cc_->Inputs().Get(id); } diff --git a/mediapipe/framework/stream_handler/in_order_output_stream_handler.cc b/mediapipe/framework/stream_handler/in_order_output_stream_handler.cc index 9af38ecdd..8faaacebe 100644 --- a/mediapipe/framework/stream_handler/in_order_output_stream_handler.cc +++ b/mediapipe/framework/stream_handler/in_order_output_stream_handler.cc @@ -14,6 +14,7 @@ #include "mediapipe/framework/stream_handler/in_order_output_stream_handler.h" +#include "absl/log/absl_check.h" #include "mediapipe/framework/collection.h" #include "mediapipe/framework/collection_item_id.h" #include "mediapipe/framework/output_stream_shard.h" @@ -23,7 +24,7 @@ namespace mediapipe { REGISTER_OUTPUT_STREAM_HANDLER(InOrderOutputStreamHandler); void InOrderOutputStreamHandler::PropagationLoop() { - CHECK_EQ(propagation_state_, kIdle); + ABSL_CHECK_EQ(propagation_state_, kIdle); Timestamp context_timestamp; CalculatorContext* calculator_context; if (!calculator_context_manager_->HasActiveContexts()) { @@ -34,7 +35,7 @@ void InOrderOutputStreamHandler::PropagationLoop() { if (!completed_input_timestamps_.empty()) { Timestamp completed_timestamp = *completed_input_timestamps_.begin(); if (context_timestamp != completed_timestamp) { - CHECK_LT(context_timestamp, completed_timestamp); + ABSL_CHECK_LT(context_timestamp, completed_timestamp); return; } propagation_state_ = kPropagatingPackets; @@ -45,7 +46,7 @@ void InOrderOutputStreamHandler::PropagationLoop() { if (propagation_state_ == kPropagatingPackets) { PropagatePackets(&calculator_context, &context_timestamp); } else { - CHECK_EQ(kPropagatingBound, propagation_state_); + ABSL_CHECK_EQ(kPropagatingBound, propagation_state_); PropagationBound(&calculator_context, &context_timestamp); } } @@ -105,12 +106,12 @@ void InOrderOutputStreamHandler::PropagationBound( } // Some recent changes require the propagation thread to recheck if any // new packets can be propagated. - CHECK_EQ(propagation_state_, kPropagationPending); + ABSL_CHECK_EQ(propagation_state_, kPropagationPending); // task_timestamp_bound_ was updated while the propagation thread was // doing timestamp propagation. This thread will redo timestamp // propagation for the new task_timestamp_bound_. if (!calculator_context_manager_->HasActiveContexts()) { - CHECK_LT(bound_to_propagate, task_timestamp_bound_); + ABSL_CHECK_LT(bound_to_propagate, task_timestamp_bound_); propagation_state_ = kPropagatingBound; return; } diff --git a/mediapipe/framework/stream_handler/mux_input_stream_handler.cc b/mediapipe/framework/stream_handler/mux_input_stream_handler.cc index fbf033a4c..a0253b9cd 100644 --- a/mediapipe/framework/stream_handler/mux_input_stream_handler.cc +++ b/mediapipe/framework/stream_handler/mux_input_stream_handler.cc @@ -15,7 +15,7 @@ #include -#include "absl/log/check.h" +#include "absl/log/absl_check.h" #include "absl/strings/substitute.h" #include "absl/synchronization/mutex.h" #include "mediapipe/framework/calculator_framework.h" @@ -41,7 +41,7 @@ void MuxInputStreamHandler::RemoveOutdatedDataPackets(Timestamp timestamp) { // stream at the next timestamp. NodeReadiness MuxInputStreamHandler::GetNodeReadiness( Timestamp* min_stream_timestamp) { - DCHECK(min_stream_timestamp); + ABSL_DCHECK(min_stream_timestamp); absl::MutexLock lock(&input_streams_mutex_); const auto& control_stream = input_stream_managers_.Get(GetControlStreamId()); @@ -63,10 +63,10 @@ NodeReadiness MuxInputStreamHandler::GetNodeReadiness( } Packet control_packet = control_stream->QueueHead(); - CHECK(!control_packet.IsEmpty()); + ABSL_CHECK(!control_packet.IsEmpty()); int control_value = control_packet.Get(); - CHECK_LE(0, control_value); - CHECK_LT(control_value, input_stream_managers_.NumEntries() - 1); + ABSL_CHECK_LE(0, control_value); + ABSL_CHECK_LT(control_value, input_stream_managers_.NumEntries() - 1); const auto& data_stream = input_stream_managers_.Get( input_stream_managers_.BeginId() + control_value); @@ -87,15 +87,15 @@ NodeReadiness MuxInputStreamHandler::GetNodeReadiness( // indicated as timestamp boun update. return NodeReadiness::kReadyForProcess; } - CHECK_EQ(stream_timestamp, *min_stream_timestamp); + ABSL_CHECK_EQ(stream_timestamp, *min_stream_timestamp); return NodeReadiness::kReadyForProcess; } // Only invoked when associated GetNodeReadiness() returned kReadyForProcess. void MuxInputStreamHandler::FillInputSet(Timestamp input_timestamp, InputStreamShardSet* input_set) { - CHECK(input_timestamp.IsAllowedInStream()); - CHECK(input_set); + ABSL_CHECK(input_timestamp.IsAllowedInStream()); + ABSL_CHECK(input_set); absl::MutexLock lock(&input_streams_mutex_); const CollectionItemId control_stream_id = GetControlStreamId(); @@ -104,23 +104,23 @@ void MuxInputStreamHandler::FillInputSet(Timestamp input_timestamp, bool stream_is_done = false; Packet control_packet = control_stream->PopPacketAtTimestamp( input_timestamp, &num_packets_dropped, &stream_is_done); - CHECK_EQ(num_packets_dropped, 0) + ABSL_CHECK_EQ(num_packets_dropped, 0) << absl::Substitute("Dropped $0 packet(s) on input stream \"$1\".", num_packets_dropped, control_stream->Name()); - CHECK(!control_packet.IsEmpty()); + ABSL_CHECK(!control_packet.IsEmpty()); int control_value = control_packet.Get(); AddPacketToShard(&input_set->Get(control_stream_id), std::move(control_packet), stream_is_done); const CollectionItemId data_stream_id = input_stream_managers_.BeginId() + control_value; - CHECK_LE(input_stream_managers_.BeginId(), data_stream_id); - CHECK_LT(data_stream_id, control_stream_id); + ABSL_CHECK_LE(input_stream_managers_.BeginId(), data_stream_id); + ABSL_CHECK_LT(data_stream_id, control_stream_id); auto& data_stream = input_stream_managers_.Get(data_stream_id); stream_is_done = false; Packet data_packet = data_stream->PopPacketAtTimestamp( input_timestamp, &num_packets_dropped, &stream_is_done); - CHECK_EQ(num_packets_dropped, 0) + ABSL_CHECK_EQ(num_packets_dropped, 0) << absl::Substitute("Dropped $0 packet(s) on input stream \"$1\".", num_packets_dropped, data_stream->Name()); AddPacketToShard(&input_set->Get(data_stream_id), std::move(data_packet), diff --git a/mediapipe/framework/stream_handler/sync_set_input_stream_handler.cc b/mediapipe/framework/stream_handler/sync_set_input_stream_handler.cc index b5b49831f..f6356c17e 100644 --- a/mediapipe/framework/stream_handler/sync_set_input_stream_handler.cc +++ b/mediapipe/framework/stream_handler/sync_set_input_stream_handler.cc @@ -19,7 +19,7 @@ #include #include -#include "absl/log/check.h" +#include "absl/log/absl_check.h" #include "absl/synchronization/mutex.h" #include "mediapipe/framework/calculator_framework.h" #include "mediapipe/framework/collection_item_id.h" @@ -47,14 +47,15 @@ void SyncSetInputStreamHandler::PrepareForRun( std::set used_ids; for (const auto& sync_set : handler_options.sync_set()) { std::vector stream_ids; - CHECK_LT(0, sync_set.tag_index_size()); + ABSL_CHECK_LT(0, sync_set.tag_index_size()); for (const auto& tag_index : sync_set.tag_index()) { std::string tag; int index; MEDIAPIPE_CHECK_OK(tool::ParseTagIndex(tag_index, &tag, &index)); CollectionItemId id = input_stream_managers_.GetId(tag, index); - CHECK(id.IsValid()) << "stream \"" << tag_index << "\" is not found."; - CHECK(!mediapipe::ContainsKey(used_ids, id)) + ABSL_CHECK(id.IsValid()) + << "stream \"" << tag_index << "\" is not found."; + ABSL_CHECK(!mediapipe::ContainsKey(used_ids, id)) << "stream \"" << tag_index << "\" is in more than one sync set."; used_ids.insert(id); stream_ids.push_back(id); @@ -82,7 +83,7 @@ void SyncSetInputStreamHandler::PrepareForRun( NodeReadiness SyncSetInputStreamHandler::GetNodeReadiness( Timestamp* min_stream_timestamp) { - DCHECK(min_stream_timestamp); + ABSL_DCHECK(min_stream_timestamp); absl::MutexLock lock(&mutex_); if (ready_sync_set_index_ >= 0) { *min_stream_timestamp = ready_timestamp_; @@ -130,7 +131,7 @@ void SyncSetInputStreamHandler::FillInputSet(Timestamp input_timestamp, InputStreamShardSet* input_set) { // Assume that all current packets are already cleared. absl::MutexLock lock(&mutex_); - CHECK_LE(0, ready_sync_set_index_); + ABSL_CHECK_LE(0, ready_sync_set_index_); sync_sets_[ready_sync_set_index_].FillInputSet(input_timestamp, input_set); for (int i = 0; i < sync_sets_.size(); ++i) { if (i != ready_sync_set_index_) { diff --git a/mediapipe/framework/stream_handler/timestamp_align_input_stream_handler.cc b/mediapipe/framework/stream_handler/timestamp_align_input_stream_handler.cc index 3e68b1618..1ab5e4e75 100644 --- a/mediapipe/framework/stream_handler/timestamp_align_input_stream_handler.cc +++ b/mediapipe/framework/stream_handler/timestamp_align_input_stream_handler.cc @@ -21,7 +21,7 @@ #include #include -#include "absl/log/check.h" +#include "absl/log/absl_check.h" #include "absl/strings/substitute.h" #include "absl/synchronization/mutex.h" #include "mediapipe/framework/calculator_context_manager.h" @@ -50,7 +50,7 @@ TimestampAlignInputStreamHandler::TimestampAlignInputStreamHandler( MEDIAPIPE_CHECK_OK(tool::ParseTagIndex( handler_options.timestamp_base_tag_index(), &tag, &index)); timestamp_base_stream_id_ = input_stream_managers_.GetId(tag, index); - CHECK(timestamp_base_stream_id_.IsValid()) + ABSL_CHECK(timestamp_base_stream_id_.IsValid()) << "stream \"" << handler_options.timestamp_base_tag_index() << "\" is not found."; timestamp_offsets_[timestamp_base_stream_id_.value()] = 0; @@ -73,7 +73,7 @@ void TimestampAlignInputStreamHandler::PrepareForRun( NodeReadiness TimestampAlignInputStreamHandler::GetNodeReadiness( Timestamp* min_stream_timestamp) { - DCHECK(min_stream_timestamp); + ABSL_DCHECK(min_stream_timestamp); *min_stream_timestamp = Timestamp::Done(); Timestamp min_bound = Timestamp::Done(); @@ -132,14 +132,14 @@ NodeReadiness TimestampAlignInputStreamHandler::GetNodeReadiness( return NodeReadiness::kReadyForProcess; } - CHECK_EQ(min_bound, *min_stream_timestamp); + ABSL_CHECK_EQ(min_bound, *min_stream_timestamp); return NodeReadiness::kNotReady; } void TimestampAlignInputStreamHandler::FillInputSet( Timestamp input_timestamp, InputStreamShardSet* input_set) { - CHECK(input_timestamp.IsAllowedInStream()); - CHECK(input_set); + ABSL_CHECK(input_timestamp.IsAllowedInStream()); + ABSL_CHECK(input_set); { absl::MutexLock lock(&mutex_); if (!offsets_initialized_) { @@ -152,7 +152,7 @@ void TimestampAlignInputStreamHandler::FillInputSet( if (id == timestamp_base_stream_id_) { current_packet = stream->PopPacketAtTimestamp( input_timestamp, &num_packets_dropped, &stream_is_done); - CHECK_EQ(num_packets_dropped, 0) << absl::Substitute( + ABSL_CHECK_EQ(num_packets_dropped, 0) << absl::Substitute( "Dropped $0 packet(s) on input stream \"$1\".", num_packets_dropped, stream->Name()); } @@ -172,10 +172,10 @@ void TimestampAlignInputStreamHandler::FillInputSet( Packet current_packet = stream->PopPacketAtTimestamp( stream_timestamp, &num_packets_dropped, &stream_is_done); if (!current_packet.IsEmpty()) { - CHECK_EQ(current_packet.Timestamp(), stream_timestamp); + ABSL_CHECK_EQ(current_packet.Timestamp(), stream_timestamp); current_packet = current_packet.At(input_timestamp); } - CHECK_EQ(num_packets_dropped, 0) + ABSL_CHECK_EQ(num_packets_dropped, 0) << absl::Substitute("Dropped $0 packet(s) on input stream \"$1\".", num_packets_dropped, stream->Name()); AddPacketToShard(&input_set->Get(id), std::move(current_packet), diff --git a/mediapipe/framework/test_calculators.cc b/mediapipe/framework/test_calculators.cc index 6cb300855..1ed1e61b1 100644 --- a/mediapipe/framework/test_calculators.cc +++ b/mediapipe/framework/test_calculators.cc @@ -20,6 +20,7 @@ #include #include "Eigen/Core" +#include "absl/log/absl_check.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" #include "mediapipe/framework/calculator_framework.h" @@ -203,7 +204,7 @@ class RangeCalculator : public CalculatorBase { // Initializes this object. void Initialize(CalculatorContext* cc) { - CHECK(!initialized_); + ABSL_CHECK(!initialized_); cc->Options(); // Ensure Options() can be called here. std::tie(n_, k_) = @@ -380,10 +381,10 @@ class RandomMatrixCalculator : public CalculatorBase { absl::Status Open(CalculatorContext* cc) override { auto& options = cc->Options(); - CHECK_LT(0, options.timestamp_step()); - CHECK_LT(0, options.rows()); - CHECK_LT(0, options.cols()); - CHECK_LT(options.start_timestamp(), options.limit_timestamp()); + ABSL_CHECK_LT(0, options.timestamp_step()); + ABSL_CHECK_LT(0, options.rows()); + ABSL_CHECK_LT(0, options.cols()); + ABSL_CHECK_LT(options.start_timestamp(), options.limit_timestamp()); current_timestamp_ = Timestamp(options.start_timestamp()); cc->Outputs().Index(0).SetNextTimestampBound(current_timestamp_); @@ -447,13 +448,13 @@ class MeanAndCovarianceCalculator : public CalculatorBase { absl::Status Process(CalculatorContext* cc) override { const Eigen::MatrixXd sample = cc->Inputs().Index(0).Get().cast(); - CHECK_EQ(1, sample.cols()); + ABSL_CHECK_EQ(1, sample.cols()); if (num_samples_ == 0) { rows_ = sample.rows(); sum_vector_ = Eigen::VectorXd::Zero(rows_); outer_product_sum_ = Eigen::MatrixXd::Zero(rows_, rows_); } else { - CHECK_EQ(sample.rows(), rows_); + ABSL_CHECK_EQ(sample.rows(), rows_); } sum_vector_ += sample; outer_product_sum_ += sample * sample.transpose(); diff --git a/mediapipe/framework/timestamp.cc b/mediapipe/framework/timestamp.cc index 0b4ff77ed..9183b3c81 100644 --- a/mediapipe/framework/timestamp.cc +++ b/mediapipe/framework/timestamp.cc @@ -16,6 +16,7 @@ #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/strings/str_cat.h" @@ -27,7 +28,7 @@ constexpr double Timestamp::kTimestampUnitsPerSecond; // - The safe int type will check for overflow/underflow and other errors. // - The CHECK in the constructor will disallow special values. TimestampDiff Timestamp::operator-(const Timestamp other) const { - CHECK(IsRangeValue() && other.IsRangeValue()) + ABSL_CHECK(IsRangeValue() && other.IsRangeValue()) << "This timestamp is " << DebugString() << " and other was " << other.DebugString(); TimestampBaseType tmp_base = timestamp_ - other.timestamp_; @@ -44,7 +45,7 @@ TimestampDiff TimestampDiff::operator-(const TimestampDiff other) const { // Clamp the addition to the range [Timestamp::Min(), Timestamp::Max()]. Timestamp Timestamp::operator+(const TimestampDiff offset) const { - CHECK(IsRangeValue()) << "Timestamp is: " << DebugString(); + ABSL_CHECK(IsRangeValue()) << "Timestamp is: " << DebugString(); TimestampBaseType offset_base(offset.Value()); if (offset_base >= TimestampBaseType(0)) { if (timestamp_.value() >= Timestamp::Max().Value() - offset_base.value()) { diff --git a/mediapipe/framework/timestamp.h b/mediapipe/framework/timestamp.h index d125d28bb..8949dcc80 100644 --- a/mediapipe/framework/timestamp.h +++ b/mediapipe/framework/timestamp.h @@ -47,6 +47,7 @@ #include #include +#include "absl/log/absl_check.h" #include "mediapipe/framework/deps/safe_int.h" #include "mediapipe/framework/port/integral_types.h" #include "mediapipe/framework/port/logging.h" @@ -270,14 +271,14 @@ std::ostream& operator<<(std::ostream& os, TimestampDiff arg); inline Timestamp::Timestamp() : timestamp_(kint64min) {} inline Timestamp::Timestamp(int64 timestamp) : timestamp_(timestamp) { - CHECK(!IsSpecialValue()) + ABSL_CHECK(!IsSpecialValue()) << "Cannot directly create a Timestamp with a special value: " << CreateNoErrorChecking(timestamp); } inline Timestamp::Timestamp(TimestampBaseType timestamp) : timestamp_(timestamp) { - CHECK(!IsSpecialValue()) + ABSL_CHECK(!IsSpecialValue()) << "Cannot directly create a Timestamp with a special value: " << CreateNoErrorChecking(timestamp.value()); } diff --git a/mediapipe/framework/tool/BUILD b/mediapipe/framework/tool/BUILD index c086eee54..b13dba9b9 100644 --- a/mediapipe/framework/tool/BUILD +++ b/mediapipe/framework/tool/BUILD @@ -142,6 +142,7 @@ cc_library( "//mediapipe/framework:calculator_cc_proto", "//mediapipe/framework/port:map_util", "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", "@com_google_absl//absl/strings:str_format", ], @@ -167,6 +168,7 @@ cc_test( ":executor_util", "//mediapipe/framework/port:gtest_main", "//mediapipe/framework/port:parse_text_proto", + "@com_google_absl//absl/log:absl_check", ], ) @@ -283,6 +285,7 @@ cc_binary( "//mediapipe/framework/port:logging", "@com_google_absl//absl/flags:flag", "@com_google_absl//absl/flags:parse", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", ], ) @@ -366,6 +369,7 @@ cc_library( "//mediapipe/framework/port:ret_check", "//mediapipe/framework/port:status", "//mediapipe/framework/port:statusor", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", ], ) @@ -405,8 +409,8 @@ cc_library( "//mediapipe/framework/port:source_location", "//mediapipe/framework/port:status", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", - "@com_google_absl//absl/log:check", "@com_google_absl//absl/status", "@com_google_absl//absl/strings", ], @@ -460,6 +464,7 @@ cc_library( deps = [ "//mediapipe/framework/port:status", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", ], ) @@ -512,8 +517,8 @@ cc_library( "//mediapipe/framework/port:numbers", "//mediapipe/framework/port:ret_check", "//mediapipe/framework/port:status", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", - "@com_google_absl//absl/log:check", "@com_google_absl//absl/strings", ], ) @@ -539,6 +544,7 @@ cc_library( "//mediapipe/framework/port:status", "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/memory", "@com_google_absl//absl/strings", @@ -674,6 +680,7 @@ cc_library( "//mediapipe/framework/port:status", "//mediapipe/framework/port:threadpool", "//mediapipe/util:cpu_util", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", "@com_google_absl//absl/synchronization", ], @@ -797,8 +804,8 @@ cc_library( "//mediapipe/framework/port:status", "@com_google_absl//absl/cleanup", "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", - "@com_google_absl//absl/log:check", "@com_google_absl//absl/memory", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", @@ -932,6 +939,7 @@ cc_library( "//mediapipe/framework/port:core_proto", "//mediapipe/framework/port:ret_check", "//mediapipe/framework/port:status", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", ], alwayslink = 1, diff --git a/mediapipe/framework/tool/message_type_util.cc b/mediapipe/framework/tool/message_type_util.cc index fe505ee0f..3bc5ea8d3 100644 --- a/mediapipe/framework/tool/message_type_util.cc +++ b/mediapipe/framework/tool/message_type_util.cc @@ -4,6 +4,7 @@ #include "absl/flags/flag.h" #include "absl/flags/parse.h" +#include "absl/log/absl_check.h" #include "absl/strings/ascii.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_replace.h" @@ -118,14 +119,14 @@ class DescriptorReader { static FileDescriptorSet ReadFileDescriptorSet(const std::string& path) { std::string contents; - CHECK_OK(file::GetContents(path, &contents)); + ABSL_CHECK_OK(file::GetContents(path, &contents)); proto_ns::FileDescriptorSet result; result.ParseFromString(contents); return result; } static void WriteFile(const std::string& path, const std::string& contents) { - CHECK_OK(file::SetContents(path, contents)); + ABSL_CHECK_OK(file::SetContents(path, contents)); } static void WriteMessageTypeName(const std::string& path, diff --git a/mediapipe/framework/tool/proto_util_lite.cc b/mediapipe/framework/tool/proto_util_lite.cc index 745f4a13b..285aa2205 100644 --- a/mediapipe/framework/tool/proto_util_lite.cc +++ b/mediapipe/framework/tool/proto_util_lite.cc @@ -16,6 +16,7 @@ #include +#include "absl/log/absl_check.h" #include "absl/strings/match.h" #include "absl/strings/numbers.h" #include "absl/strings/str_cat.h" @@ -411,7 +412,7 @@ static absl::Status DeserializeValue(const FieldValue& bytes, } case W::TYPE_GROUP: case W::TYPE_MESSAGE: - CHECK(false) << "DeserializeValue cannot deserialize a Message."; + ABSL_CHECK(false) << "DeserializeValue cannot deserialize a Message."; case W::TYPE_UINT32: return ReadPrimitive(&input, result); case W::TYPE_ENUM: diff --git a/mediapipe/framework/tool/sink.cc b/mediapipe/framework/tool/sink.cc index 254c6063e..b97d27ea7 100644 --- a/mediapipe/framework/tool/sink.cc +++ b/mediapipe/framework/tool/sink.cc @@ -27,8 +27,8 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" -#include "absl/log/check.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" @@ -75,8 +75,8 @@ REGISTER_CALCULATOR(MediaPipeInternalSidePacketToPacketStreamCalculator); void AddVectorSink(const std::string& stream_name, // CalculatorGraphConfig* config, // std::vector* dumped_data) { - CHECK(config); - CHECK(dumped_data); + ABSL_CHECK(config); + ABSL_CHECK(dumped_data); std::string input_side_packet_name; tool::AddCallbackCalculator(stream_name, config, &input_side_packet_name, @@ -95,15 +95,15 @@ void AddVectorSink(const std::string& stream_name, // // Up to 64-bit pointer in hex (16 characters) and an optional "0x" prepended. char address[19]; int written = snprintf(address, sizeof(address), "%p", dumped_data); - CHECK(written > 0 && written < sizeof(address)); + ABSL_CHECK(written > 0 && written < sizeof(address)); options->set_pointer(address); } void AddPostStreamPacketSink(const std::string& stream_name, CalculatorGraphConfig* config, Packet* post_stream_packet) { - CHECK(config); - CHECK(post_stream_packet); + ABSL_CHECK(config); + ABSL_CHECK(post_stream_packet); std::string input_side_packet_name; tool::AddCallbackCalculator(stream_name, config, &input_side_packet_name, @@ -121,14 +121,14 @@ void AddPostStreamPacketSink(const std::string& stream_name, // Up to 64-bit pointer in hex (16 characters) and an optional "0x" prepended. char address[19]; int written = snprintf(address, sizeof(address), "%p", post_stream_packet); - CHECK(written > 0 && written < sizeof(address)); + ABSL_CHECK(written > 0 && written < sizeof(address)); options->set_pointer(address); } void AddSidePacketSink(const std::string& side_packet_name, CalculatorGraphConfig* config, Packet* dumped_packet) { - CHECK(config); - CHECK(dumped_packet); + ABSL_CHECK(config); + ABSL_CHECK(dumped_packet); CalculatorGraphConfig::Node* conversion_node = config->add_node(); const std::string node_name = GetUnusedNodeName( @@ -150,8 +150,8 @@ void AddCallbackCalculator(const std::string& stream_name, CalculatorGraphConfig* config, std::string* callback_side_packet_name, bool use_std_function) { - CHECK(config); - CHECK(callback_side_packet_name); + ABSL_CHECK(config); + ABSL_CHECK(callback_side_packet_name); CalculatorGraphConfig::Node* sink_node = config->add_node(); sink_node->set_name(GetUnusedNodeName( *config, @@ -187,8 +187,8 @@ void AddMultiStreamCallback( std::function&)> callback, CalculatorGraphConfig* config, std::map* side_packets, bool observe_timestamp_bounds) { - CHECK(config); - CHECK(side_packets); + ABSL_CHECK(config); + ABSL_CHECK(side_packets); CalculatorGraphConfig::Node* sink_node = config->add_node(); const std::string name = GetUnusedNodeName( *config, absl::StrCat("multi_callback_", absl::StrJoin(streams, "_"))); @@ -222,8 +222,8 @@ void AddCallbackWithHeaderCalculator(const std::string& stream_name, CalculatorGraphConfig* config, std::string* callback_side_packet_name, bool use_std_function) { - CHECK(config); - CHECK(callback_side_packet_name); + ABSL_CHECK(config); + ABSL_CHECK(callback_side_packet_name); CalculatorGraphConfig::Node* sink_node = config->add_node(); sink_node->set_name(GetUnusedNodeName( *config, @@ -331,7 +331,7 @@ absl::Status CallbackWithHeaderCalculator::GetContract(CalculatorContract* cc) { cc->Inputs().Tag("HEADER").SetAny(); if (cc->InputSidePackets().UsesTags()) { - CHECK(cc->InputSidePackets().HasTag("CALLBACK")); + ABSL_CHECK(cc->InputSidePackets().HasTag("CALLBACK")); cc->InputSidePackets() .Tag("CALLBACK") .Set>(); diff --git a/mediapipe/framework/tool/sink.h b/mediapipe/framework/tool/sink.h index c5d45332d..4d00b6e6d 100644 --- a/mediapipe/framework/tool/sink.h +++ b/mediapipe/framework/tool/sink.h @@ -68,9 +68,9 @@ namespace tool { // // Call tool::AddVectorSink() more times if you wish. Note that each stream // // needs to get its own packet vector. // CalculatorGraph graph; -// CHECK_OK(graph.Initialize(config)); +// ABSL_CHECK_OK(graph.Initialize(config)); // // Set other input side packets. -// CHECK_OK(graph.Run()); +// ABSL_CHECK_OK(graph.Run()); // for (const Packet& packet : packet_dump) { // // Do something. // } @@ -160,7 +160,7 @@ void AddCallbackWithHeaderCalculator(const std::string& stream_name, // tool::AddCallbackCalculator("the_output_stream", &config, // &input_side_packet_name, true); // CalculatorGraph graph(config); -// CHECK_OK(graph.Run( +// ABSL_CHECK_OK(graph.Run( // {{input_side_packet_name, // MakePacket>( // std::bind(&MyClass::MyFunction, this, std::placeholders::_1))}} diff --git a/mediapipe/framework/tool/status_util.cc b/mediapipe/framework/tool/status_util.cc index 0c277a003..19f3fc6b7 100644 --- a/mediapipe/framework/tool/status_util.cc +++ b/mediapipe/framework/tool/status_util.cc @@ -16,6 +16,7 @@ #include +#include "absl/log/absl_check.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" #include "absl/strings/string_view.h" diff --git a/mediapipe/framework/tool/switch_container.cc b/mediapipe/framework/tool/switch_container.cc index daa129928..29307c4f9 100644 --- a/mediapipe/framework/tool/switch_container.cc +++ b/mediapipe/framework/tool/switch_container.cc @@ -20,6 +20,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/strings/str_cat.h" #include "mediapipe/framework/calculator.pb.h" #include "mediapipe/framework/calculator_framework.h" @@ -148,7 +149,7 @@ void ClearContainerOptions(CalculatorGraphConfig::Node* dest) { // Returns an unused name similar to a specified name. std::string UniqueName(std::string name, std::set* names) { - CHECK(names != nullptr); + ABSL_CHECK(names != nullptr); std::string result = name; int suffix = 2; while (names->count(result) > 0) { @@ -161,7 +162,7 @@ std::string UniqueName(std::string name, std::set* names) { // Parses tag, index, and name from a list of stream identifiers. void ParseTags(const proto_ns::RepeatedPtrField& streams, std::map* result) { - CHECK(result != nullptr); + ABSL_CHECK(result != nullptr); std::set used_names; int used_index = -1; for (const std::string& stream : streams) { @@ -177,14 +178,14 @@ void ParseTags(const proto_ns::RepeatedPtrField& streams, // Removes the entry for a tag and index from a map. void EraseTag(const std::string& stream, std::map* streams) { - CHECK(streams != nullptr); + ABSL_CHECK(streams != nullptr); streams->erase(ParseTagIndexFromStream(absl::StrCat(stream, ":u"))); } // Removes the entry for a tag and index from a list. void EraseTag(const std::string& stream, proto_ns::RepeatedPtrField* streams) { - CHECK(streams != nullptr); + ABSL_CHECK(streams != nullptr); TagIndex stream_tag = ParseTagIndexFromStream(absl::StrCat(stream, ":u")); for (int i = streams->size() - 1; i >= 0; --i) { TagIndex tag = ParseTagIndexFromStream(streams->at(i)); @@ -197,7 +198,7 @@ void EraseTag(const std::string& stream, // Returns the stream names for the container node. void GetContainerNodeStreams(const CalculatorGraphConfig::Node& node, CalculatorGraphConfig::Node* result) { - CHECK(result != nullptr); + ABSL_CHECK(result != nullptr); *result->mutable_input_stream() = node.input_stream(); *result->mutable_output_stream() = node.output_stream(); *result->mutable_input_side_packet() = node.input_side_packet(); diff --git a/mediapipe/framework/tool/template_expander.cc b/mediapipe/framework/tool/template_expander.cc index 9bbe2165d..8f9ef6866 100644 --- a/mediapipe/framework/tool/template_expander.cc +++ b/mediapipe/framework/tool/template_expander.cc @@ -19,8 +19,8 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" -#include "absl/log/check.h" #include "absl/strings/ascii.h" #include "absl/strings/match.h" #include "absl/strings/numbers.h" @@ -179,7 +179,8 @@ FieldType GetFieldType(const TemplateExpression& rule) { int FieldCount(const FieldValue& base, ProtoPath field_path, FieldType field_type) { int result = 0; - CHECK_OK(ProtoUtilLite::GetFieldCount(base, field_path, field_type, &result)); + ABSL_CHECK_OK( + ProtoUtilLite::GetFieldCount(base, field_path, field_type, &result)); return result; } @@ -642,7 +643,7 @@ class TemplateExpanderImpl { for (int i = 0; i < args.size(); ++i) { if (args[i].has_dict()) { FieldValue dict_bytes; - CHECK(args[i].dict().SerializePartialToString(&dict_bytes)); + ABSL_CHECK(args[i].dict().SerializePartialToString(&dict_bytes)); result->push_back(dict_bytes); } else if (args[i].has_num() || args[i].has_str()) { std::string text_value = args[i].has_num() diff --git a/mediapipe/framework/tool/template_parser.cc b/mediapipe/framework/tool/template_parser.cc index 5bc42ba2c..d97ec0c2c 100644 --- a/mediapipe/framework/tool/template_parser.cc +++ b/mediapipe/framework/tool/template_parser.cc @@ -21,6 +21,7 @@ #include #include "absl/container/flat_hash_set.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/memory/memory.h" #include "absl/strings/ascii.h" @@ -565,7 +566,8 @@ class TemplateParser::Parser::ParserImpl { // Skips unknown or reserved fields. if (field == NULL) { - CHECK(allow_unknown_field_ || allow_unknown_extension_ || reserved_field); + ABSL_CHECK(allow_unknown_field_ || allow_unknown_extension_ || + reserved_field); // Try to guess the type of this field. // If this field is not a message, there should be a ":" between the @@ -1397,7 +1399,7 @@ bool DeterministicallySerialize(const Message& proto, std::string* result) { void SerializeField(const Message* message, const FieldDescriptor* field, std::vector* result) { ProtoUtilLite::FieldValue message_bytes; - CHECK(DeterministicallySerialize(*message, &message_bytes)); + ABSL_CHECK(DeterministicallySerialize(*message, &message_bytes)); ProtoUtilLite::FieldAccess access( field->number(), static_cast(field->type())); MEDIAPIPE_CHECK_OK(access.SetMessage(message_bytes)); @@ -1702,13 +1704,13 @@ class TemplateParser::Parser::MediaPipeParserImpl const std::vector& args) { auto field_type = static_cast(field->type()); ProtoUtilLite::FieldValue message_bytes; - CHECK(message->SerializePartialToString(&message_bytes)); + ABSL_CHECK(message->SerializePartialToString(&message_bytes)); int count; MEDIAPIPE_CHECK_OK(ProtoUtilLite::GetFieldCount( message_bytes, {{field->number(), 0}}, field_type, &count)); MEDIAPIPE_CHECK_OK(ProtoUtilLite::ReplaceFieldRange( &message_bytes, {{field->number(), count}}, 0, field_type, args)); - CHECK(message->ParsePartialFromString(message_bytes)); + ABSL_CHECK(message->ParsePartialFromString(message_bytes)); } // Parse and record a template definition for the current field path. diff --git a/mediapipe/framework/tool/test_util.cc b/mediapipe/framework/tool/test_util.cc index d82a491da..e5fac11ae 100644 --- a/mediapipe/framework/tool/test_util.cc +++ b/mediapipe/framework/tool/test_util.cc @@ -22,8 +22,8 @@ #include "absl/cleanup/cleanup.h" #include "absl/container/flat_hash_set.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" -#include "absl/log/check.h" #include "absl/memory/memory.h" #include "absl/status/status.h" #include "absl/strings/match.h" @@ -60,8 +60,8 @@ absl::Status CompareDiff(const ImageFrame& image1, const ImageFrame& image2, const float max_avg_diff, std::unique_ptr& diff_image) { // Verify image byte depth matches expected byte depth. - CHECK_EQ(sizeof(T), image1.ByteDepth()); - CHECK_EQ(sizeof(T), image2.ByteDepth()); + ABSL_CHECK_EQ(sizeof(T), image1.ByteDepth()); + ABSL_CHECK_EQ(sizeof(T), image2.ByteDepth()); const int width = image1.Width(); const int height = image1.Height(); @@ -72,8 +72,8 @@ absl::Status CompareDiff(const ImageFrame& image1, const ImageFrame& image2, const int num_channels = std::min(channels1, channels2); // Verify the width steps are multiples of byte depth. - CHECK_EQ(image1.WidthStep() % image1.ByteDepth(), 0); - CHECK_EQ(image2.WidthStep() % image2.ByteDepth(), 0); + ABSL_CHECK_EQ(image1.WidthStep() % image1.ByteDepth(), 0); + ABSL_CHECK_EQ(image2.WidthStep() % image2.ByteDepth(), 0); const int width_padding1 = image1.WidthStep() / image1.ByteDepth() - width * channels1; const int width_padding2 = @@ -144,7 +144,7 @@ absl::Status CompareDiff(const ImageFrame& image1, const ImageFrame& image2, std::string GetBinaryDirectory() { char full_path[PATH_MAX + 1]; int length = readlink("/proc/self/exe", full_path, PATH_MAX + 1); - CHECK_GT(length, 0); + ABSL_CHECK_GT(length, 0); return std::string( ::mediapipe::file::Dirname(absl::string_view(full_path, length))); } diff --git a/mediapipe/framework/tool/validate_type.cc b/mediapipe/framework/tool/validate_type.cc index 4c97a310a..38c04fa87 100644 --- a/mediapipe/framework/tool/validate_type.cc +++ b/mediapipe/framework/tool/validate_type.cc @@ -18,6 +18,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/strings/str_cat.h" #include "mediapipe/framework/calculator_contract.h" #include "mediapipe/framework/calculator_framework.h" @@ -78,7 +79,7 @@ absl::Status RunGenerateAndValidateTypes( const PacketGeneratorOptions& extendable_options, const PacketSet& input_side_packets, PacketSet* output_side_packets, const std::string& package) { - CHECK(output_side_packets); + ABSL_CHECK(output_side_packets); // Get static access to functions. ASSIGN_OR_RETURN( auto static_access, diff --git a/mediapipe/framework/type_map.h b/mediapipe/framework/type_map.h index 9af3e895b..f03f48ce7 100644 --- a/mediapipe/framework/type_map.h +++ b/mediapipe/framework/type_map.h @@ -64,8 +64,8 @@ #include #include "absl/base/macros.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" -#include "absl/log/check.h" #include "absl/synchronization/mutex.h" #include "mediapipe/framework/demangle.h" #include "mediapipe/framework/port/status.h" @@ -129,7 +129,7 @@ class StaticMap { } static void GetKeys(std::vector* keys) { - CHECK(keys); + ABSL_CHECK(keys); keys->clear(); const MapType& internal_map = GetMap()->internal_map_; for (typename MapType::const_iterator i = internal_map.begin(); @@ -160,12 +160,12 @@ class StaticMap { // Type has been already registered. const MediaPipeTypeData& existing_data = it->second.second; - CHECK_EQ(existing_data.type_id, value.type_id) + ABSL_CHECK_EQ(existing_data.type_id, value.type_id) << "Found inconsistent type ids (" << existing_data.type_id << " vs " << value.type_id << ") during mediapipe type registration. Previous definition at " << it->second.first << " and current definition at " << file_and_line; - CHECK_EQ(existing_data.type_string, value.type_string) + ABSL_CHECK_EQ(existing_data.type_string, value.type_string) << "Found inconsistent type strings (" << existing_data.type_string << " vs " << value.type_string << ") during mediapipe type registration. Previous registration at " @@ -173,7 +173,7 @@ class StaticMap { << file_and_line; if (value.serialize_fn && value.deserialize_fn) { // Doesn't allow to redefine the existing type serialization functions. - CHECK(!existing_data.serialize_fn && !existing_data.deserialize_fn) + ABSL_CHECK(!existing_data.serialize_fn && !existing_data.deserialize_fn) << "Attempting to redefine serialization functions of type " << value.type_string << ", that have been defined at " << it->second.first << ", at " << file_and_line; diff --git a/mediapipe/framework/validated_graph_config.cc b/mediapipe/framework/validated_graph_config.cc index 2a718cfaa..4f9182474 100644 --- a/mediapipe/framework/validated_graph_config.cc +++ b/mediapipe/framework/validated_graph_config.cc @@ -18,6 +18,7 @@ #include #include "absl/container/flat_hash_set.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/memory/memory.h" #include "absl/strings/str_cat.h" @@ -748,7 +749,7 @@ int ValidatedGraphConfig::SorterIndexForNode(NodeTypeInfo::NodeRef node) const { case NodeTypeInfo::NodeType::CALCULATOR: return generators_.size() + node.index; default: - CHECK(false); + ABSL_CHECK(false); } } diff --git a/mediapipe/gpu/BUILD b/mediapipe/gpu/BUILD index ebca543f8..74c7e2d05 100644 --- a/mediapipe/gpu/BUILD +++ b/mediapipe/gpu/BUILD @@ -204,8 +204,8 @@ cc_library( "//mediapipe/framework/port:threadpool", "@com_google_absl//absl/base:dynamic_annotations", "@com_google_absl//absl/debugging:leak_check", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", - "@com_google_absl//absl/log:check", "@com_google_absl//absl/memory", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", @@ -237,6 +237,7 @@ cc_library( ":gpu_buffer_format", ":gpu_buffer_storage", ":gpu_buffer_storage_image_frame", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/memory", # TODO: remove this dependency. Some other teams' tests @@ -298,7 +299,7 @@ cc_library( "//mediapipe/framework/formats:image_frame", "//mediapipe/framework/port:logging", "@com_google_absl//absl/functional:bind_front", - "@com_google_absl//absl/log:check", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", "@com_google_absl//absl/synchronization", ] + select({ @@ -335,6 +336,7 @@ cc_library( "//mediapipe/framework/formats:image_format_cc_proto", "//mediapipe/framework/port:logging", "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/log:absl_check", ] + select({ "//conditions:default": [ ":gl_base", @@ -371,6 +373,7 @@ cc_library( ":image_frame_view", "//mediapipe/objc:CFHolder", "//mediapipe/objc:util", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", ], ) @@ -402,6 +405,7 @@ cc_library( ":pixel_buffer_pool_util", "//mediapipe/framework/port:logging", "//mediapipe/objc:CFHolder", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/synchronization", ], ) @@ -425,6 +429,7 @@ cc_library( "//mediapipe/framework/port:logging", "//mediapipe/objc:CFHolder", "//mediapipe/objc:util", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/synchronization", ], ) @@ -441,6 +446,7 @@ cc_library( ":image_frame_view", "//mediapipe/framework/formats:frame_buffer", "//mediapipe/framework/formats:image_frame", + "@com_google_absl//absl/log:absl_check", ], ) @@ -480,8 +486,8 @@ cc_library( "//mediapipe/framework/formats:yuv_image", "//mediapipe/util/frame_buffer:frame_buffer_util", "//third_party/libyuv", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", - "@com_google_absl//absl/log:check", ], ) @@ -639,6 +645,7 @@ cc_library( "//mediapipe/framework/deps:no_destructor", "//mediapipe/framework/port:ret_check", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/log:absl_check", ] + select({ "//conditions:default": [], "//mediapipe:apple": [ @@ -827,6 +834,7 @@ cc_library( "//mediapipe/framework/port:ret_check", "//mediapipe/framework/port:status", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/memory", "@com_google_absl//absl/synchronization", @@ -853,6 +861,7 @@ objc_library( "//mediapipe/objc:mediapipe_framework_ios", "//third_party/apple_frameworks:CoreVideo", "//third_party/apple_frameworks:Metal", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@google_toolbox_for_mac//:GTM_Defines", ], @@ -1215,5 +1224,6 @@ mediapipe_cc_test( "//mediapipe/framework/formats:yuv_image", "//mediapipe/framework/port:gtest_main", "//third_party/libyuv", + "@com_google_absl//absl/log:absl_check", ], ) diff --git a/mediapipe/gpu/MPPMetalHelper.mm b/mediapipe/gpu/MPPMetalHelper.mm index e87b81a4e..3405d560f 100644 --- a/mediapipe/gpu/MPPMetalHelper.mm +++ b/mediapipe/gpu/MPPMetalHelper.mm @@ -14,6 +14,7 @@ #import "mediapipe/gpu/MPPMetalHelper.h" +#import "third_party/absl/log/absl_check.h" #import "third_party/absl/log/absl_log.h" #import "mediapipe/gpu/gpu_buffer.h" #import "mediapipe/gpu/gpu_service.h" @@ -79,7 +80,7 @@ class MetalHelperLegacySupport { - (instancetype)initWithSidePackets:(const mediapipe::PacketSet&)inputSidePackets { auto cc = mediapipe::MetalHelperLegacySupport::GetCalculatorContext(); if (cc) { - CHECK_EQ(&inputSidePackets, &cc->InputSidePackets()); + ABSL_CHECK_EQ(&inputSidePackets, &cc->InputSidePackets()); return [self initWithCalculatorContext:cc]; } @@ -96,7 +97,7 @@ class MetalHelperLegacySupport { + (absl::Status)setupInputSidePackets:(mediapipe::PacketTypeSet*)inputSidePackets { auto cc = mediapipe::MetalHelperLegacySupport::GetCalculatorContract(); if (cc) { - CHECK_EQ(inputSidePackets, &cc->InputSidePackets()); + ABSL_CHECK_EQ(inputSidePackets, &cc->InputSidePackets()); return [self updateContract:cc]; } @@ -179,7 +180,7 @@ class MetalHelperLegacySupport { NULL, _gpuResources->metal_shared().resources().mtlTextureCache, mediapipe::GetCVPixelBufferRef(gpuBuffer), NULL, metalPixelFormat, width, height, plane, &texture); - CHECK_EQ(err, kCVReturnSuccess); + ABSL_CHECK_EQ(err, kCVReturnSuccess); return texture; } diff --git a/mediapipe/gpu/cv_pixel_buffer_pool_wrapper.cc b/mediapipe/gpu/cv_pixel_buffer_pool_wrapper.cc index 6e077ae6e..07ac7373a 100644 --- a/mediapipe/gpu/cv_pixel_buffer_pool_wrapper.cc +++ b/mediapipe/gpu/cv_pixel_buffer_pool_wrapper.cc @@ -17,6 +17,7 @@ #include #include "CoreFoundation/CFBase.h" +#include "absl/log/absl_check.h" #include "mediapipe/framework/port/logging.h" #include "mediapipe/objc/CFHolder.h" #include "mediapipe/objc/util.h" @@ -27,7 +28,7 @@ CvPixelBufferPoolWrapper::CvPixelBufferPoolWrapper( int width, int height, GpuBufferFormat format, CFTimeInterval maxAge, CvTextureCacheManager* texture_caches) { OSType cv_format = CVPixelFormatForGpuBufferFormat(format); - CHECK_NE(cv_format, -1) << "unsupported pixel format"; + ABSL_CHECK_NE(cv_format, -1) << "unsupported pixel format"; pool_ = MakeCFHolderAdopting( /* keep count is 0 because the age param keeps buffers around anyway */ CreateCVPixelBufferPool(width, height, cv_format, 0, maxAge)); @@ -58,7 +59,7 @@ CFHolder CvPixelBufferPoolWrapper::GetBuffer() { ++threshold; } } - CHECK(!err) << "Error creating pixel buffer: " << err; + ABSL_CHECK(!err) << "Error creating pixel buffer: " << err; count_ = threshold; return MakeCFHolderAdopting(buffer); } @@ -73,11 +74,11 @@ void CvPixelBufferPoolWrapper::Flush() { CVPixelBufferPoolFlush(*pool_, 0); } CFHolder CvPixelBufferPoolWrapper::CreateBufferWithoutPool( const internal::GpuBufferSpec& spec) { OSType cv_format = CVPixelFormatForGpuBufferFormat(spec.format); - CHECK_NE(cv_format, -1) << "unsupported pixel format"; + ABSL_CHECK_NE(cv_format, -1) << "unsupported pixel format"; CVPixelBufferRef buffer; CVReturn err = CreateCVPixelBufferWithoutPool(spec.width, spec.height, cv_format, &buffer); - CHECK(!err) << "Error creating pixel buffer: " << err; + ABSL_CHECK(!err) << "Error creating pixel buffer: " << err; return MakeCFHolderAdopting(buffer); } diff --git a/mediapipe/gpu/cv_texture_cache_manager.cc b/mediapipe/gpu/cv_texture_cache_manager.cc index b977a8993..0c4d2306c 100644 --- a/mediapipe/gpu/cv_texture_cache_manager.cc +++ b/mediapipe/gpu/cv_texture_cache_manager.cc @@ -14,6 +14,7 @@ #include "mediapipe/gpu/cv_texture_cache_manager.h" +#include "absl/log/absl_check.h" #include "mediapipe/framework/port/logging.h" namespace mediapipe { @@ -32,8 +33,8 @@ void CvTextureCacheManager::FlushTextureCaches() { void CvTextureCacheManager::RegisterTextureCache(CVTextureCacheType cache) { absl::MutexLock lock(&mutex_); - CHECK(std::find(texture_caches_.begin(), texture_caches_.end(), cache) == - texture_caches_.end()) + ABSL_CHECK(std::find(texture_caches_.begin(), texture_caches_.end(), cache) == + texture_caches_.end()) << "Attempting to register a texture cache twice"; texture_caches_.emplace_back(cache); } @@ -42,13 +43,13 @@ void CvTextureCacheManager::UnregisterTextureCache(CVTextureCacheType cache) { absl::MutexLock lock(&mutex_); auto it = std::find(texture_caches_.begin(), texture_caches_.end(), cache); - CHECK(it != texture_caches_.end()) + ABSL_CHECK(it != texture_caches_.end()) << "Attempting to unregister an unknown texture cache"; texture_caches_.erase(it); } CvTextureCacheManager::~CvTextureCacheManager() { - CHECK_EQ(texture_caches_.size(), 0) + ABSL_CHECK_EQ(texture_caches_.size(), 0) << "Failed to unregister texture caches before deleting manager"; } diff --git a/mediapipe/gpu/gl_calculator_helper.cc b/mediapipe/gpu/gl_calculator_helper.cc index eff994dcb..763ac387a 100644 --- a/mediapipe/gpu/gl_calculator_helper.cc +++ b/mediapipe/gpu/gl_calculator_helper.cc @@ -14,6 +14,7 @@ #include "mediapipe/gpu/gl_calculator_helper.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "mediapipe/framework/formats/image.h" #include "mediapipe/framework/formats/image_frame.h" @@ -37,7 +38,7 @@ void GlCalculatorHelper::InitializeInternal(CalculatorContext* cc, } absl::Status GlCalculatorHelper::Open(CalculatorContext* cc) { - CHECK(cc); + ABSL_CHECK(cc); auto gpu_service = cc->Service(kGpuService); RET_CHECK(gpu_service.IsAvailable()) << "GPU service not available. Did you forget to call " @@ -72,7 +73,7 @@ absl::Status GlCalculatorHelper::SetupInputSidePackets( PacketTypeSet* input_side_packets) { auto cc = LegacyCalculatorSupport::Scoped::current(); if (cc) { - CHECK_EQ(input_side_packets, &cc->InputSidePackets()); + ABSL_CHECK_EQ(input_side_packets, &cc->InputSidePackets()); return UpdateContract(cc); } @@ -184,9 +185,9 @@ GpuBuffer GlCalculatorHelper::GpuBufferCopyingImageFrame( const ImageFrame& image_frame) { #if MEDIAPIPE_GPU_BUFFER_USE_CV_PIXEL_BUFFER auto maybe_buffer = CreateCVPixelBufferCopyingImageFrame(image_frame); - // Converts absl::StatusOr to absl::Status since CHECK_OK() currently only - // deals with absl::Status in MediaPipe OSS. - CHECK_OK(maybe_buffer.status()); + // Converts absl::StatusOr to absl::Status since ABSL_CHECK_OK() currently + // only deals with absl::Status in MediaPipe OSS. + ABSL_CHECK_OK(maybe_buffer.status()); return GpuBuffer(std::move(maybe_buffer).value()); #else return GpuBuffer(GlTextureBuffer::Create(image_frame)); @@ -195,8 +196,8 @@ GpuBuffer GlCalculatorHelper::GpuBufferCopyingImageFrame( void GlCalculatorHelper::GetGpuBufferDimensions(const GpuBuffer& pixel_buffer, int* width, int* height) { - CHECK(width); - CHECK(height); + ABSL_CHECK(width); + ABSL_CHECK(height); *width = pixel_buffer.width(); *height = pixel_buffer.height(); } diff --git a/mediapipe/gpu/gl_context.cc b/mediapipe/gpu/gl_context.cc index 1ab3fabb9..5eff88b92 100644 --- a/mediapipe/gpu/gl_context.cc +++ b/mediapipe/gpu/gl_context.cc @@ -22,6 +22,7 @@ #include #include "absl/base/dynamic_annotations.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/memory/memory.h" #include "absl/status/status.h" @@ -69,17 +70,17 @@ static void SetThreadName(const char* name) { } GlContext::DedicatedThread::DedicatedThread() { - CHECK_EQ(pthread_create(&gl_thread_id_, nullptr, ThreadBody, this), 0); + ABSL_CHECK_EQ(pthread_create(&gl_thread_id_, nullptr, ThreadBody, this), 0); } GlContext::DedicatedThread::~DedicatedThread() { if (IsCurrentThread()) { - CHECK(self_destruct_); - CHECK_EQ(pthread_detach(gl_thread_id_), 0); + ABSL_CHECK(self_destruct_); + ABSL_CHECK_EQ(pthread_detach(gl_thread_id_), 0); } else { // Give an invalid job to signal termination. PutJob({}); - CHECK_EQ(pthread_join(gl_thread_id_, nullptr), 0); + ABSL_CHECK_EQ(pthread_join(gl_thread_id_, nullptr), 0); } } @@ -168,7 +169,7 @@ void GlContext::DedicatedThread::RunWithoutWaiting(GlVoidFunction gl_func) { // non-calculator tasks in the presence of GL source calculators, calculator // tasks must always be scheduled as new tasks, or another solution needs to // be set up to avoid starvation. See b/78522434. - CHECK(gl_func); + ABSL_CHECK(gl_func); PutJob(std::move(gl_func)); } @@ -495,10 +496,10 @@ absl::Status GlContext::SwitchContext(ContextBinding* saved_context, } // Check that the context object is consistent with the native context. if (old_context_obj && saved_context) { - DCHECK(old_context_obj->context_ == saved_context->context); + ABSL_DCHECK(old_context_obj->context_ == saved_context->context); } if (new_context_obj) { - DCHECK(new_context_obj->context_ == new_context.context); + ABSL_DCHECK(new_context_obj->context_ == new_context.context); } if (new_context_obj && (old_context_obj == new_context_obj)) { @@ -538,7 +539,7 @@ GlContext::ContextBinding GlContext::ThisContextBinding() { } absl::Status GlContext::EnterContext(ContextBinding* saved_context) { - DCHECK(HasContext()); + ABSL_DCHECK(HasContext()); return SwitchContext(saved_context, ThisContextBinding()); } @@ -849,7 +850,7 @@ bool GlContext::IsAnyContextCurrent() { std::shared_ptr GlContext::CreateSyncTokenForCurrentExternalContext( const std::shared_ptr& delegate_graph_context) { - CHECK(delegate_graph_context); + ABSL_CHECK(delegate_graph_context); if (!IsAnyContextCurrent()) return nullptr; if (delegate_graph_context->ShouldUseFenceSync()) { return std::shared_ptr( @@ -900,7 +901,7 @@ void GlContext::WaitForGlFinishCountPast(int64_t count_to_pass) { // from the GlContext, and we must wait for gl_finish_count_ to pass it. // Therefore, we need to do at most one more glFinish call. This DCHECK // is used for documentation and sanity-checking purposes. - DCHECK(gl_finish_count_ >= count_to_pass); + ABSL_DCHECK(gl_finish_count_ >= count_to_pass); if (gl_finish_count_ == count_to_pass) { glFinish(); GlFinishCalled(); @@ -921,7 +922,7 @@ void GlContext::WaitForGlFinishCountPast(int64_t count_to_pass) { // it can signal the right condition variable if it is asked to do a // glFinish. absl::MutexLock other_lock(&other->mutex_); - DCHECK(!other->context_waiting_on_); + ABSL_DCHECK(!other->context_waiting_on_); other->context_waiting_on_ = this; } // We do not schedule this action using Run because we don't necessarily @@ -965,12 +966,12 @@ void GlContext::WaitForGlFinishCountPast(int64_t count_to_pass) { } void GlContext::WaitSyncToken(const std::shared_ptr& token) { - CHECK(token); + ABSL_CHECK(token); token->Wait(); } bool GlContext::SyncTokenIsReady(const std::shared_ptr& token) { - CHECK(token); + ABSL_CHECK(token); return token->IsReady(); } @@ -1032,7 +1033,7 @@ void GlContext::LogUncheckedGlErrors(bool had_gl_errors) { const GlTextureInfo& GlTextureInfoForGpuBufferFormat(GpuBufferFormat format, int plane) { std::shared_ptr ctx = GlContext::GetCurrent(); - CHECK(ctx != nullptr); + ABSL_CHECK(ctx != nullptr); return GlTextureInfoForGpuBufferFormat(format, plane, ctx->GetGlVersion()); } diff --git a/mediapipe/gpu/gl_context.h b/mediapipe/gpu/gl_context.h index fba0267a8..bb3e6a597 100644 --- a/mediapipe/gpu/gl_context.h +++ b/mediapipe/gpu/gl_context.h @@ -22,6 +22,7 @@ #include #include "absl/container/flat_hash_map.h" +#include "absl/log/absl_check.h" #include "absl/synchronization/mutex.h" #include "mediapipe/framework/executor.h" #include "mediapipe/framework/mediapipe_profiling.h" @@ -295,7 +296,7 @@ class GlContext : public std::enable_shared_from_this { // TOOD: const result? template T& GetCachedAttachment(const Attachment& attachment) { - DCHECK(IsCurrent()); + ABSL_DCHECK(IsCurrent()); internal::AttachmentPtr& entry = attachments_[&attachment]; if (entry == nullptr) { entry = attachment.factory()(*this); diff --git a/mediapipe/gpu/gl_context_egl.cc b/mediapipe/gpu/gl_context_egl.cc index 5d2592794..d573b6978 100644 --- a/mediapipe/gpu/gl_context_egl.cc +++ b/mediapipe/gpu/gl_context_egl.cc @@ -14,8 +14,8 @@ #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" -#include "absl/log/check.h" #include "absl/memory/memory.h" #include "absl/status/status.h" #include "absl/status/statusor.h" @@ -115,7 +115,7 @@ GlContext::StatusOrGlContext GlContext::Create(EGLContext share_context, absl::Status GlContext::CreateContextInternal(EGLContext share_context, int gl_version) { - CHECK(gl_version == 2 || gl_version == 3); + ABSL_CHECK(gl_version == 2 || gl_version == 3); const EGLint config_attr[] = { // clang-format off diff --git a/mediapipe/gpu/gl_context_webgl.cc b/mediapipe/gpu/gl_context_webgl.cc index c81f35b93..0f14581b6 100644 --- a/mediapipe/gpu/gl_context_webgl.cc +++ b/mediapipe/gpu/gl_context_webgl.cc @@ -14,6 +14,7 @@ #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/memory/memory.h" #include "mediapipe/framework/port/logging.h" @@ -49,7 +50,7 @@ GlContext::StatusOrGlContext GlContext::Create( absl::Status GlContext::CreateContextInternal( EMSCRIPTEN_WEBGL_CONTEXT_HANDLE external_context, int webgl_version) { - CHECK(webgl_version == 1 || webgl_version == 2); + ABSL_CHECK(webgl_version == 1 || webgl_version == 2); EmscriptenWebGLContextAttributes attrs; emscripten_webgl_init_context_attributes(&attrs); diff --git a/mediapipe/gpu/gl_texture_buffer.cc b/mediapipe/gpu/gl_texture_buffer.cc index ffa8db6e0..0ea511c5b 100644 --- a/mediapipe/gpu/gl_texture_buffer.cc +++ b/mediapipe/gpu/gl_texture_buffer.cc @@ -14,6 +14,7 @@ #include "mediapipe/gpu/gl_texture_buffer.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "mediapipe/framework/formats/image_frame.h" #include "mediapipe/gpu/gl_context.h" @@ -128,7 +129,7 @@ bool GlTextureBuffer::CreateInternal(const void* data, int alignment) { if (info.gl_internal_format == GL_RGBA16F && context->GetGlVersion() != GlVersion::kGLES2 && SymbolAvailable(&glTexStorage2D)) { - CHECK(data == nullptr) << "unimplemented"; + ABSL_CHECK(data == nullptr) << "unimplemented"; glTexStorage2D(target_, 1, info.gl_internal_format, width_, height_); } else { glTexImage2D(target_, 0 /* level */, info.gl_internal_format, width_, @@ -150,10 +151,10 @@ bool GlTextureBuffer::CreateInternal(const void* data, int alignment) { // Use the deletion callback to delete the texture on the context // that created it. - CHECK(!deletion_callback_); + ABSL_CHECK(!deletion_callback_); deletion_callback_ = [this, context](std::shared_ptr sync_token) { - CHECK_NE(name_, 0); + ABSL_CHECK_NE(name_, 0); GLuint name_to_delete = name_; context->RunWithoutWaiting([name_to_delete]() { // Note that we do not wait for consumers to be done before deleting the @@ -201,9 +202,9 @@ void GlTextureBuffer::Reuse() { } void GlTextureBuffer::Updated(std::shared_ptr prod_token) { - CHECK(!producer_sync_) + ABSL_CHECK(!producer_sync_) << "Updated existing texture which had not been marked for reuse!"; - CHECK(prod_token); + ABSL_CHECK(prod_token); producer_sync_ = std::move(prod_token); const auto& synced_context = producer_sync_->GetContext(); if (synced_context) { @@ -264,11 +265,11 @@ void GlTextureBuffer::WaitForConsumersOnGpu() { GlTextureView GlTextureBuffer::GetReadView(internal::types, int plane) const { auto gl_context = GlContext::GetCurrent(); - CHECK(gl_context); - CHECK_EQ(plane, 0); + ABSL_CHECK(gl_context); + ABSL_CHECK_EQ(plane, 0); // Note that this method is only supposed to be called by GpuBuffer, which // ensures this condition is satisfied. - DCHECK(!weak_from_this().expired()) + ABSL_DCHECK(!weak_from_this().expired()) << "GlTextureBuffer must be held in shared_ptr to get a GlTextureView"; // Insert wait call to sync with the producer. WaitOnGpu(); @@ -285,11 +286,11 @@ GlTextureView GlTextureBuffer::GetReadView(internal::types, GlTextureView GlTextureBuffer::GetWriteView(internal::types, int plane) { auto gl_context = GlContext::GetCurrent(); - CHECK(gl_context); - CHECK_EQ(plane, 0); + ABSL_CHECK(gl_context); + ABSL_CHECK_EQ(plane, 0); // Note that this method is only supposed to be called by GpuBuffer, which // ensures this condition is satisfied. - DCHECK(!weak_from_this().expired()) + ABSL_DCHECK(!weak_from_this().expired()) << "GlTextureBuffer must be held in shared_ptr to get a GlTextureView"; // Insert wait call to sync with the producer. WaitOnGpu(); @@ -346,7 +347,7 @@ static void ReadTexture(GlContext& ctx, const GlTextureView& view, // won't overflow the buffer with glReadPixels, we'd also need to check or // reset several glPixelStore parameters (e.g. what if someone had the // ill-advised idea of setting GL_PACK_SKIP_PIXELS?). - CHECK(view.gl_context()); + ABSL_CHECK(view.gl_context()); GlTextureInfo info = GlTextureInfoForGpuBufferFormat( format, view.plane(), view.gl_context()->GetGlVersion()); diff --git a/mediapipe/gpu/gpu_buffer.cc b/mediapipe/gpu/gpu_buffer.cc index 628e86099..0eb7a1c5d 100644 --- a/mediapipe/gpu/gpu_buffer.cc +++ b/mediapipe/gpu/gpu_buffer.cc @@ -4,6 +4,7 @@ #include #include "absl/functional/bind_front.h" +#include "absl/log/absl_check.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" #include "mediapipe/framework/port/logging.h" @@ -127,10 +128,11 @@ internal::GpuBufferStorage& GpuBuffer::GetStorageForViewOrDie( TypeId view_provider_type, bool for_writing) const { auto* chosen_storage = GpuBuffer::GetStorageForView(view_provider_type, for_writing); - CHECK(chosen_storage) << "no view provider found for requested view " - << view_provider_type.name() << "; storages available: " - << (holder_ ? holder_->DebugString() : "invalid"); - DCHECK(chosen_storage->can_down_cast_to(view_provider_type)); + ABSL_CHECK(chosen_storage) + << "no view provider found for requested view " + << view_provider_type.name() << "; storages available: " + << (holder_ ? holder_->DebugString() : "invalid"); + ABSL_DCHECK(chosen_storage->can_down_cast_to(view_provider_type)); return *chosen_storage; } diff --git a/mediapipe/gpu/gpu_buffer.h b/mediapipe/gpu/gpu_buffer.h index 93eb1460e..20cc05ead 100644 --- a/mediapipe/gpu/gpu_buffer.h +++ b/mediapipe/gpu/gpu_buffer.h @@ -20,7 +20,7 @@ #include #include -#include "absl/log/check.h" +#include "absl/log/absl_check.h" #include "absl/synchronization/mutex.h" #include "mediapipe/framework/formats/image_frame.h" #include "mediapipe/gpu/gpu_buffer_format.h" @@ -74,7 +74,7 @@ class GpuBuffer { // GpuBuffers in a portable way from the framework, e.g. using // GpuBufferMultiPool. explicit GpuBuffer(std::shared_ptr storage) { - CHECK(storage) << "Cannot construct GpuBuffer with null storage"; + ABSL_CHECK(storage) << "Cannot construct GpuBuffer with null storage"; holder_ = std::make_shared(std::move(storage)); } diff --git a/mediapipe/gpu/gpu_buffer_format.cc b/mediapipe/gpu/gpu_buffer_format.cc index e88aa602e..646fb383f 100644 --- a/mediapipe/gpu/gpu_buffer_format.cc +++ b/mediapipe/gpu/gpu_buffer_format.cc @@ -15,6 +15,7 @@ #include "mediapipe/gpu/gpu_buffer_format.h" #include "absl/container/flat_hash_map.h" +#include "absl/log/absl_check.h" #include "mediapipe/framework/deps/no_destructor.h" #include "mediapipe/framework/port/logging.h" @@ -189,16 +190,16 @@ const GlTextureInfo& GlTextureInfoForGpuBufferFormat(GpuBufferFormat format, } auto iter = format_info->find(format); - CHECK(iter != format_info->end()) + ABSL_CHECK(iter != format_info->end()) << "unsupported format: " << static_cast>(format); const auto& planes = iter->second; #ifndef __APPLE__ - CHECK_EQ(planes.size(), 1) + ABSL_CHECK_EQ(planes.size(), 1) << "multiplanar formats are not supported on this platform"; #endif - CHECK_GE(plane, 0) << "invalid plane number"; - CHECK_LT(plane, planes.size()) << "invalid plane number"; + ABSL_CHECK_GE(plane, 0) << "invalid plane number"; + ABSL_CHECK_LT(plane, planes.size()) << "invalid plane number"; return planes[plane]; } #endif // MEDIAPIPE_DISABLE_GPU diff --git a/mediapipe/gpu/gpu_buffer_storage_cv_pixel_buffer.cc b/mediapipe/gpu/gpu_buffer_storage_cv_pixel_buffer.cc index 7759cc789..ba048351b 100644 --- a/mediapipe/gpu/gpu_buffer_storage_cv_pixel_buffer.cc +++ b/mediapipe/gpu/gpu_buffer_storage_cv_pixel_buffer.cc @@ -2,6 +2,7 @@ #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "mediapipe/gpu/gl_context.h" #include "mediapipe/gpu/gpu_buffer_storage_image_frame.h" @@ -18,11 +19,11 @@ typedef CVOpenGLESTextureRef CVTextureType; GpuBufferStorageCvPixelBuffer::GpuBufferStorageCvPixelBuffer( int width, int height, GpuBufferFormat format) { OSType cv_format = CVPixelFormatForGpuBufferFormat(format); - CHECK_NE(cv_format, -1) << "unsupported pixel format"; + ABSL_CHECK_NE(cv_format, -1) << "unsupported pixel format"; CVPixelBufferRef buffer; CVReturn err = CreateCVPixelBufferWithoutPool(width, height, cv_format, &buffer); - CHECK(!err) << "Error creating pixel buffer: " << err; + ABSL_CHECK(!err) << "Error creating pixel buffer: " << err; adopt(buffer); } @@ -30,13 +31,13 @@ GlTextureView GpuBufferStorageCvPixelBuffer::GetTexture( int plane, GlTextureView::DoneWritingFn done_writing) const { CVReturn err; auto gl_context = GlContext::GetCurrent(); - CHECK(gl_context); + ABSL_CHECK(gl_context); #if TARGET_OS_OSX CVTextureType cv_texture_temp; err = CVOpenGLTextureCacheCreateTextureFromImage( kCFAllocatorDefault, gl_context->cv_texture_cache(), **this, NULL, &cv_texture_temp); - CHECK(cv_texture_temp && !err) + ABSL_CHECK(cv_texture_temp && !err) << "CVOpenGLTextureCacheCreateTextureFromImage failed: " << err; CFHolder cv_texture; cv_texture.adopt(cv_texture_temp); @@ -54,7 +55,7 @@ GlTextureView GpuBufferStorageCvPixelBuffer::GetTexture( GL_TEXTURE_2D, info.gl_internal_format, width() / info.downscale, height() / info.downscale, info.gl_format, info.gl_type, plane, &cv_texture_temp); - CHECK(cv_texture_temp && !err) + ABSL_CHECK(cv_texture_temp && !err) << "CVOpenGLESTextureCacheCreateTextureFromImage failed: " << err; CFHolder cv_texture; cv_texture.adopt(cv_texture_temp); @@ -74,12 +75,12 @@ GlTextureView GpuBufferStorageCvPixelBuffer::GetReadView( #if TARGET_IPHONE_SIMULATOR static void ViewDoneWritingSimulatorWorkaround(CVPixelBufferRef pixel_buffer, const GlTextureView& view) { - CHECK(pixel_buffer); + ABSL_CHECK(pixel_buffer); auto ctx = GlContext::GetCurrent().get(); if (!ctx) ctx = view.gl_context(); ctx->Run([pixel_buffer, &view, ctx] { CVReturn err = CVPixelBufferLockBaseAddress(pixel_buffer, 0); - CHECK(err == kCVReturnSuccess) + ABSL_CHECK(err == kCVReturnSuccess) << "CVPixelBufferLockBaseAddress failed: " << err; OSType pixel_format = CVPixelBufferGetPixelFormatType(pixel_buffer); size_t bytes_per_row = CVPixelBufferGetBytesPerRow(pixel_buffer); @@ -117,7 +118,7 @@ static void ViewDoneWritingSimulatorWorkaround(CVPixelBufferRef pixel_buffer, ABSL_LOG(ERROR) << "unsupported pixel format: " << pixel_format; } err = CVPixelBufferUnlockBaseAddress(pixel_buffer, 0); - CHECK(err == kCVReturnSuccess) + ABSL_CHECK(err == kCVReturnSuccess) << "CVPixelBufferUnlockBaseAddress failed: " << err; }); } @@ -150,7 +151,7 @@ static std::shared_ptr ConvertFromImageFrame( std::shared_ptr frame) { auto status_or_buffer = CreateCVPixelBufferForImageFrame(frame->image_frame()); - CHECK(status_or_buffer.ok()); + ABSL_CHECK(status_or_buffer.ok()); return std::make_shared( std::move(status_or_buffer).value()); } diff --git a/mediapipe/gpu/gpu_buffer_storage_image_frame.cc b/mediapipe/gpu/gpu_buffer_storage_image_frame.cc index 316c6cc4e..7f46e2975 100644 --- a/mediapipe/gpu/gpu_buffer_storage_image_frame.cc +++ b/mediapipe/gpu/gpu_buffer_storage_image_frame.cc @@ -18,6 +18,7 @@ limitations under the License. #include #include +#include "absl/log/absl_check.h" #include "mediapipe/framework/formats/frame_buffer.h" #include "mediapipe/framework/formats/image_frame.h" @@ -43,7 +44,7 @@ std::shared_ptr ImageFrameToFrameBuffer( std::shared_ptr image_frame) { FrameBuffer::Format format = FrameBufferFormatForImageFrameFormat(image_frame->Format()); - CHECK(format != FrameBuffer::Format::kUNKNOWN) + ABSL_CHECK(format != FrameBuffer::Format::kUNKNOWN) << "Invalid format. Only SRGB, SRGBA and GRAY8 are supported."; const FrameBuffer::Dimension dimension{/*width=*/image_frame->Width(), /*height=*/image_frame->Height()}; diff --git a/mediapipe/gpu/gpu_buffer_storage_yuv_image.cc b/mediapipe/gpu/gpu_buffer_storage_yuv_image.cc index 1137154b2..87fb8957d 100644 --- a/mediapipe/gpu/gpu_buffer_storage_yuv_image.cc +++ b/mediapipe/gpu/gpu_buffer_storage_yuv_image.cc @@ -19,8 +19,8 @@ limitations under the License. #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" -#include "absl/log/check.h" #include "libyuv/video_common.h" #include "mediapipe/framework/formats/frame_buffer.h" #include "mediapipe/framework/formats/image_frame.h" @@ -87,7 +87,7 @@ std::shared_ptr YuvImageToFrameBuffer( FrameBuffer::Dimension dimension{/*width=*/yuv_image->width(), /*height=*/yuv_image->height()}; std::vector planes; - CHECK(yuv_image->mutable_data(0) != nullptr && yuv_image->stride(0) > 0) + ABSL_CHECK(yuv_image->mutable_data(0) != nullptr && yuv_image->stride(0) > 0) << "Invalid YuvImage. Expected plane at index 0 to be non-null and have " "stride > 0."; planes.emplace_back( @@ -97,7 +97,8 @@ std::shared_ptr YuvImageToFrameBuffer( switch (format) { case FrameBuffer::Format::kNV12: case FrameBuffer::Format::kNV21: { - CHECK(yuv_image->mutable_data(1) != nullptr && yuv_image->stride(1) > 0) + ABSL_CHECK(yuv_image->mutable_data(1) != nullptr && + yuv_image->stride(1) > 0) << "Invalid YuvImage. Expected plane at index 1 to be non-null and " "have stride > 0."; planes.emplace_back( @@ -108,8 +109,9 @@ std::shared_ptr YuvImageToFrameBuffer( } case FrameBuffer::Format::kYV12: case FrameBuffer::Format::kYV21: { - CHECK(yuv_image->mutable_data(1) != nullptr && yuv_image->stride(1) > 0 && - yuv_image->mutable_data(2) != nullptr && yuv_image->stride(2) > 0) + ABSL_CHECK( + yuv_image->mutable_data(1) != nullptr && yuv_image->stride(1) > 0 && + yuv_image->mutable_data(2) != nullptr && yuv_image->stride(2) > 0) << "Invalid YuvImage. Expected planes at indices 1 and 2 to be " "non-null and have stride > 0."; planes.emplace_back( @@ -148,7 +150,7 @@ std::shared_ptr YuvImageToImageFrame( auto rgb_buffer = FrameBuffer(planes, yuv_buffer->dimension(), FrameBuffer::Format::kRGB); // Convert. - CHECK_OK(frame_buffer::Convert(*yuv_buffer, &rgb_buffer)); + ABSL_CHECK_OK(frame_buffer::Convert(*yuv_buffer, &rgb_buffer)); return image_frame; } @@ -156,8 +158,8 @@ std::shared_ptr YuvImageToImageFrame( GpuBufferStorageYuvImage::GpuBufferStorageYuvImage( std::shared_ptr yuv_image) { - CHECK(GpuBufferFormatForFourCC(yuv_image->fourcc()) != - GpuBufferFormat::kUnknown) + ABSL_CHECK(GpuBufferFormatForFourCC(yuv_image->fourcc()) != + GpuBufferFormat::kUnknown) << "Invalid format. Only FOURCC_NV12, FOURCC_NV21, FOURCC_YV12 and " "FOURCC_I420 are supported."; yuv_image_ = yuv_image; diff --git a/mediapipe/gpu/gpu_shared_data_internal.cc b/mediapipe/gpu/gpu_shared_data_internal.cc index 1098c82ec..b9b9c26f0 100644 --- a/mediapipe/gpu/gpu_shared_data_internal.cc +++ b/mediapipe/gpu/gpu_shared_data_internal.cc @@ -15,6 +15,7 @@ #include "mediapipe/gpu/gpu_shared_data_internal.h" #include "absl/base/attributes.h" +#include "absl/log/absl_check.h" #include "mediapipe/framework/deps/no_destructor.h" #include "mediapipe/framework/port/ret_check.h" #include "mediapipe/gpu/gl_context.h" @@ -120,7 +121,7 @@ GpuResources::~GpuResources() { ABSL_CONST_INIT extern const GraphService kGpuService; absl::Status GpuResources::PrepareGpuNode(CalculatorNode* node) { - CHECK(node->Contract().ServiceRequests().contains(kGpuService.key)); + ABSL_CHECK(node->Contract().ServiceRequests().contains(kGpuService.key)); std::string node_id = node->GetCalculatorState().NodeName(); std::string node_type = node->GetCalculatorState().CalculatorType(); std::string context_key; diff --git a/mediapipe/graphs/object_detection_3d/calculators/BUILD b/mediapipe/graphs/object_detection_3d/calculators/BUILD index 39022af29..c491baf28 100644 --- a/mediapipe/graphs/object_detection_3d/calculators/BUILD +++ b/mediapipe/graphs/object_detection_3d/calculators/BUILD @@ -74,6 +74,7 @@ cc_library( "//mediapipe/gpu:shader_util", "//mediapipe/modules/objectron/calculators:camera_parameters_cc_proto", "//mediapipe/util/android:asset_manager_util", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", ], alwayslink = 1, diff --git a/mediapipe/graphs/object_detection_3d/calculators/gl_animation_overlay_calculator.cc b/mediapipe/graphs/object_detection_3d/calculators/gl_animation_overlay_calculator.cc index a0a55301e..5dee74a25 100644 --- a/mediapipe/graphs/object_detection_3d/calculators/gl_animation_overlay_calculator.cc +++ b/mediapipe/graphs/object_detection_3d/calculators/gl_animation_overlay_calculator.cc @@ -19,6 +19,7 @@ #include #endif +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "mediapipe/framework/calculator_framework.h" #include "mediapipe/framework/port/ret_check.h" @@ -510,8 +511,8 @@ bool GlAnimationOverlayCalculator::LoadAnimation(const std::string &filename) { void GlAnimationOverlayCalculator::ComputeAspectRatioAndFovFromCameraParameters( const CameraParametersProto &camera_parameters, float *aspect_ratio, float *vertical_fov_degrees) { - CHECK(aspect_ratio != nullptr); - CHECK(vertical_fov_degrees != nullptr); + ABSL_CHECK(aspect_ratio != nullptr); + ABSL_CHECK(vertical_fov_degrees != nullptr); *aspect_ratio = camera_parameters.portrait_width() / camera_parameters.portrait_height(); *vertical_fov_degrees = @@ -612,7 +613,7 @@ void GlAnimationOverlayCalculator::LoadModelMatrices( current_model_matrices->clear(); for (int i = 0; i < model_matrices.model_matrix_size(); ++i) { const auto &model_matrix = model_matrices.model_matrix(i); - CHECK(model_matrix.matrix_entries_size() == kNumMatrixEntries) + ABSL_CHECK(model_matrix.matrix_entries_size() == kNumMatrixEntries) << "Invalid Model Matrix"; current_model_matrices->emplace_back(); ModelMatrix &new_matrix = current_model_matrices->back(); diff --git a/mediapipe/java/com/google/mediapipe/framework/jni/BUILD b/mediapipe/java/com/google/mediapipe/framework/jni/BUILD index c675c64af..0a985f87c 100644 --- a/mediapipe/java/com/google/mediapipe/framework/jni/BUILD +++ b/mediapipe/java/com/google/mediapipe/framework/jni/BUILD @@ -101,6 +101,7 @@ cc_library( "//mediapipe/framework/stream_handler:fixed_size_input_stream_handler", "//mediapipe/framework/tool:executor_util", "//mediapipe/framework/tool:name_util", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", "@com_google_absl//absl/strings:str_format", diff --git a/mediapipe/java/com/google/mediapipe/framework/jni/surface_output_jni.cc b/mediapipe/java/com/google/mediapipe/framework/jni/surface_output_jni.cc index 5d9a087ee..2ac43e57e 100644 --- a/mediapipe/java/com/google/mediapipe/framework/jni/surface_output_jni.cc +++ b/mediapipe/java/com/google/mediapipe/framework/jni/surface_output_jni.cc @@ -17,6 +17,7 @@ #include #endif // __ANDROID__ +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "mediapipe/framework/port/ret_check.h" #include "mediapipe/framework/port/status.h" @@ -52,7 +53,7 @@ JNIEXPORT void JNICALL MEDIAPIPE_SURFACE_OUTPUT_METHOD(nativeSetSurface)( JNIEnv* env, jobject thiz, jlong context, jlong packet, jobject surface) { #ifdef __ANDROID__ mediapipe::GlContext* gl_context = GetGlContext(context); - CHECK(gl_context) << "GPU shared data not created"; + ABSL_CHECK(gl_context) << "GPU shared data not created"; mediapipe::EglSurfaceHolder* surface_holder = GetSurfaceHolder(packet); // ANativeWindow_fromSurface must not be called on the GL thread, it is a @@ -107,7 +108,7 @@ JNIEXPORT void JNICALL MEDIAPIPE_SURFACE_OUTPUT_METHOD(nativeSetSurface)( JNIEXPORT void JNICALL MEDIAPIPE_SURFACE_OUTPUT_METHOD(nativeSetEglSurface)( JNIEnv* env, jobject thiz, jlong context, jlong packet, jlong surface) { mediapipe::GlContext* gl_context = GetGlContext(context); - CHECK(gl_context) << "GPU shared data not created"; + ABSL_CHECK(gl_context) << "GPU shared data not created"; auto egl_surface = reinterpret_cast(surface); mediapipe::EglSurfaceHolder* surface_holder = GetSurfaceHolder(packet); EGLSurface old_surface = EGL_NO_SURFACE; diff --git a/mediapipe/modules/objectron/calculators/BUILD b/mediapipe/modules/objectron/calculators/BUILD index e2b0a5ccf..05b254753 100644 --- a/mediapipe/modules/objectron/calculators/BUILD +++ b/mediapipe/modules/objectron/calculators/BUILD @@ -135,6 +135,7 @@ cc_library( "//mediapipe/framework/port:opencv_core", "//mediapipe/framework/port:opencv_imgproc", "//mediapipe/util/tracking:box_tracker_cc_proto", + "@com_google_absl//absl/log:absl_check", ], ) @@ -149,6 +150,7 @@ cc_library( "//mediapipe/util/tracking:box_tracker_cc_proto", "@com_google_absl//absl/container:btree", "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", ], ) @@ -163,6 +165,7 @@ cc_library( ], deps = [ "//mediapipe/framework/port:logging", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/status", "@com_google_absl//absl/strings:str_format", "@eigen_archive//:eigen3", @@ -185,6 +188,7 @@ cc_library( "//mediapipe/framework/port:opencv_core", "//mediapipe/framework/port:opencv_imgproc", "//mediapipe/framework/port:status", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/status", "@eigen_archive//:eigen3", @@ -203,6 +207,7 @@ cc_library( "//mediapipe/framework/formats:tensor", "//mediapipe/framework/port:logging", "//mediapipe/framework/port:opencv_core", + "@com_google_absl//absl/log:absl_check", "@org_tensorflow//tensorflow/lite:framework", ], ) @@ -223,6 +228,7 @@ cc_library( ":annotation_cc_proto", ":object_cc_proto", "//mediapipe/framework/port:logging", + "@com_google_absl//absl/log:absl_check", "@eigen_archive//:eigen3", ], ) @@ -277,6 +283,7 @@ cc_library( "//mediapipe/framework/deps:file_path", "//mediapipe/framework/port:opencv_core", "//mediapipe/framework/port:ret_check", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/memory", "@com_google_absl//absl/strings:str_format", @@ -302,6 +309,7 @@ cc_library( "//mediapipe/framework/formats:tensor", "//mediapipe/framework/port:opencv_core", "//mediapipe/framework/port:ret_check", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/memory", "@com_google_absl//absl/strings:str_format", "@com_google_absl//absl/types:span", @@ -419,5 +427,6 @@ cc_test( "//mediapipe/framework/port:logging", "//mediapipe/util/tracking:box_tracker_cc_proto", "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/log:absl_check", ], ) diff --git a/mediapipe/modules/objectron/calculators/box.cc b/mediapipe/modules/objectron/calculators/box.cc index bd2ce57f9..9b3e43484 100644 --- a/mediapipe/modules/objectron/calculators/box.cc +++ b/mediapipe/modules/objectron/calculators/box.cc @@ -15,6 +15,7 @@ #include "mediapipe/modules/objectron/calculators/box.h" #include "Eigen/Core" +#include "absl/log/absl_check.h" #include "mediapipe/framework/port/logging.h" namespace mediapipe { @@ -107,12 +108,12 @@ void Box::Adjust(const std::vector& variables) { } float* Box::GetVertex(size_t vertex_id) { - CHECK_LT(vertex_id, kNumKeypoints); + ABSL_CHECK_LT(vertex_id, kNumKeypoints); return bounding_box_[vertex_id].data(); } const float* Box::GetVertex(size_t vertex_id) const { - CHECK_LT(vertex_id, kNumKeypoints); + ABSL_CHECK_LT(vertex_id, kNumKeypoints); return bounding_box_[vertex_id].data(); } @@ -135,7 +136,7 @@ bool Box::InsideTest(const Eigen::Vector3f& point, int check_axis) const { } void Box::Deserialize(const Object& obj) { - CHECK_EQ(obj.keypoints_size(), kNumKeypoints); + ABSL_CHECK_EQ(obj.keypoints_size(), kNumKeypoints); Model::Deserialize(obj); } @@ -222,7 +223,7 @@ std::pair Box::GetGroundPlane() const { template void Box::Fit(const std::vector& vertices) { - CHECK_EQ(vertices.size(), kNumKeypoints); + ABSL_CHECK_EQ(vertices.size(), kNumKeypoints); scale_.setZero(); // The scale would remain invariant under rotation and translation. // We can safely estimate the scale from the oriented box. diff --git a/mediapipe/modules/objectron/calculators/box_util.cc b/mediapipe/modules/objectron/calculators/box_util.cc index 0663b5bdb..c19fa5be2 100644 --- a/mediapipe/modules/objectron/calculators/box_util.cc +++ b/mediapipe/modules/objectron/calculators/box_util.cc @@ -16,6 +16,7 @@ #include +#include "absl/log/absl_check.h" #include "mediapipe/framework/port/logging.h" #include "mediapipe/framework/port/opencv_core_inc.h" #include "mediapipe/framework/port/opencv_imgproc_inc.h" @@ -24,7 +25,7 @@ namespace mediapipe { void ComputeBoundingRect(const std::vector& points, mediapipe::TimedBoxProto* box) { - CHECK(box != nullptr); + ABSL_CHECK(box != nullptr); float top = 1.0f; float bottom = 0.0f; float left = 1.0f; diff --git a/mediapipe/modules/objectron/calculators/decoder.cc b/mediapipe/modules/objectron/calculators/decoder.cc index 82aeee599..b823490d7 100644 --- a/mediapipe/modules/objectron/calculators/decoder.cc +++ b/mediapipe/modules/objectron/calculators/decoder.cc @@ -19,6 +19,7 @@ #include "Eigen/Core" #include "Eigen/Dense" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/status/status.h" #include "mediapipe/framework/port/canonical_errors.h" @@ -46,10 +47,10 @@ inline void SetPoint3d(const Eigen::Vector3f& point_vec, Point3D* point_3d) { FrameAnnotation Decoder::DecodeBoundingBoxKeypoints( const cv::Mat& heatmap, const cv::Mat& offsetmap) const { - CHECK_EQ(1, heatmap.channels()); - CHECK_EQ(kNumOffsetmaps, offsetmap.channels()); - CHECK_EQ(heatmap.cols, offsetmap.cols); - CHECK_EQ(heatmap.rows, offsetmap.rows); + ABSL_CHECK_EQ(1, heatmap.channels()); + ABSL_CHECK_EQ(kNumOffsetmaps, offsetmap.channels()); + ABSL_CHECK_EQ(heatmap.cols, offsetmap.cols); + ABSL_CHECK_EQ(heatmap.rows, offsetmap.rows); const float offset_scale = std::min(offsetmap.cols, offsetmap.rows); const std::vector center_points = ExtractCenterKeypoints(heatmap); @@ -201,10 +202,10 @@ std::vector Decoder::ExtractCenterKeypoints( absl::Status Decoder::Lift2DTo3D( const Eigen::Matrix& projection_matrix, bool portrait, FrameAnnotation* estimated_box) const { - CHECK(estimated_box != nullptr); + ABSL_CHECK(estimated_box != nullptr); for (auto& annotation : *estimated_box->mutable_annotations()) { - CHECK_EQ(kNumKeypoints, annotation.keypoints_size()); + ABSL_CHECK_EQ(kNumKeypoints, annotation.keypoints_size()); // Fill input 2D Points; std::vector input_points_2d; diff --git a/mediapipe/modules/objectron/calculators/epnp.cc b/mediapipe/modules/objectron/calculators/epnp.cc index 8bd7151fa..03b78c728 100644 --- a/mediapipe/modules/objectron/calculators/epnp.cc +++ b/mediapipe/modules/objectron/calculators/epnp.cc @@ -14,6 +14,8 @@ #include "mediapipe/modules/objectron/calculators/epnp.h" +#include "absl/log/absl_check.h" + namespace mediapipe { namespace { @@ -126,7 +128,7 @@ absl::Status SolveEpnp(const float focal_x, const float focal_y, if (eigen_solver.info() != Eigen::Success) { return absl::AbortedError("Eigen decomposition failed."); } - CHECK_EQ(12, eigen_solver.eigenvalues().size()); + ABSL_CHECK_EQ(12, eigen_solver.eigenvalues().size()); // Eigenvalues are sorted in increasing order for SelfAdjointEigenSolver // only! If you use other Eigen Solvers, it's not guaranteed to be in diff --git a/mediapipe/modules/objectron/calculators/frame_annotation_tracker.cc b/mediapipe/modules/objectron/calculators/frame_annotation_tracker.cc index 39fe1f936..d060af355 100644 --- a/mediapipe/modules/objectron/calculators/frame_annotation_tracker.cc +++ b/mediapipe/modules/objectron/calculators/frame_annotation_tracker.cc @@ -15,6 +15,7 @@ #include "mediapipe/modules/objectron/calculators/frame_annotation_tracker.h" #include "absl/container/flat_hash_set.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "mediapipe/modules/objectron/calculators/annotation_data.pb.h" #include "mediapipe/modules/objectron/calculators/box_util.h" @@ -35,7 +36,7 @@ void FrameAnnotationTracker::AddDetectionResult( FrameAnnotation FrameAnnotationTracker::ConsolidateTrackingResult( const TimedBoxProtoList& tracked_boxes, absl::flat_hash_set* cancel_object_ids) { - CHECK(cancel_object_ids != nullptr); + ABSL_CHECK(cancel_object_ids != nullptr); FrameAnnotation frame_annotation; std::vector keys_to_be_deleted; for (const auto& detected_obj : detected_objects_) { diff --git a/mediapipe/modules/objectron/calculators/frame_annotation_tracker_test.cc b/mediapipe/modules/objectron/calculators/frame_annotation_tracker_test.cc index d155f8e73..df6ffd40b 100644 --- a/mediapipe/modules/objectron/calculators/frame_annotation_tracker_test.cc +++ b/mediapipe/modules/objectron/calculators/frame_annotation_tracker_test.cc @@ -15,6 +15,7 @@ #include "mediapipe/modules/objectron/calculators/frame_annotation_tracker.h" #include "absl/container/flat_hash_set.h" +#include "absl/log/absl_check.h" #include "mediapipe/framework/port/gmock.h" #include "mediapipe/framework/port/gtest.h" #include "mediapipe/framework/port/logging.h" @@ -53,7 +54,7 @@ ObjectAnnotation ConstructFixedObject( ObjectAnnotation obj; for (const auto& point : points) { auto* keypoint = obj.add_keypoints(); - CHECK_EQ(2, point.size()); + ABSL_CHECK_EQ(2, point.size()); keypoint->mutable_point_2d()->set_x(point[0]); keypoint->mutable_point_2d()->set_y(point[1]); } diff --git a/mediapipe/modules/objectron/calculators/model.cc b/mediapipe/modules/objectron/calculators/model.cc index 40aca39d9..d6fe9ed6c 100644 --- a/mediapipe/modules/objectron/calculators/model.cc +++ b/mediapipe/modules/objectron/calculators/model.cc @@ -14,6 +14,7 @@ #include "mediapipe/modules/objectron/calculators/model.h" +#include "absl/log/absl_check.h" #include "mediapipe/framework/port/logging.h" namespace mediapipe { @@ -66,9 +67,9 @@ const Eigen::Ref Model::GetRotation() const { const std::string& Model::GetCategory() const { return category_; } void Model::Deserialize(const Object& obj) { - CHECK_EQ(obj.rotation_size(), 9); - CHECK_EQ(obj.translation_size(), 3); - CHECK_EQ(obj.scale_size(), 3); + ABSL_CHECK_EQ(obj.rotation_size(), 9); + ABSL_CHECK_EQ(obj.translation_size(), 3); + ABSL_CHECK_EQ(obj.scale_size(), 3); category_ = obj.category(); using RotationMatrix = Eigen::Matrix; diff --git a/mediapipe/modules/objectron/calculators/tensor_util.cc b/mediapipe/modules/objectron/calculators/tensor_util.cc index 0004edd80..c6fa74b2c 100644 --- a/mediapipe/modules/objectron/calculators/tensor_util.cc +++ b/mediapipe/modules/objectron/calculators/tensor_util.cc @@ -14,14 +14,16 @@ #include "mediapipe/modules/objectron/calculators/tensor_util.h" +#include "absl/log/absl_check.h" #include "mediapipe/framework/port/logging.h" namespace mediapipe { cv::Mat ConvertTfliteTensorToCvMat(const TfLiteTensor& tensor) { // Check tensor is BxCxWxH (size = 4) and the batch size is one(data[0] = 1) - CHECK(tensor.dims->size == 4 && tensor.dims->data[0] == 1); - CHECK_EQ(kTfLiteFloat32, tensor.type) << "tflite_tensor type is not float"; + ABSL_CHECK(tensor.dims->size == 4 && tensor.dims->data[0] == 1); + ABSL_CHECK_EQ(kTfLiteFloat32, tensor.type) + << "tflite_tensor type is not float"; const size_t num_output_channels = tensor.dims->data[3]; const int dims = 2; @@ -32,9 +34,9 @@ cv::Mat ConvertTfliteTensorToCvMat(const TfLiteTensor& tensor) { cv::Mat ConvertTensorToCvMat(const mediapipe::Tensor& tensor) { // Check tensor is BxCxWxH (size = 4) and the batch size is one(data[0] = 1) - CHECK(tensor.shape().dims.size() == 4 && tensor.shape().dims[0] == 1); - CHECK_EQ(mediapipe::Tensor::ElementType::kFloat32 == tensor.element_type(), - true) + ABSL_CHECK(tensor.shape().dims.size() == 4 && tensor.shape().dims[0] == 1); + ABSL_CHECK_EQ( + mediapipe::Tensor::ElementType::kFloat32 == tensor.element_type(), true) << "tensor type is not float"; const size_t num_output_channels = tensor.shape().dims[3]; diff --git a/mediapipe/modules/objectron/calculators/tensors_to_objects_calculator.cc b/mediapipe/modules/objectron/calculators/tensors_to_objects_calculator.cc index c1092c725..c5ccf1d12 100644 --- a/mediapipe/modules/objectron/calculators/tensors_to_objects_calculator.cc +++ b/mediapipe/modules/objectron/calculators/tensors_to_objects_calculator.cc @@ -17,6 +17,7 @@ #include #include "Eigen/Dense" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/memory/memory.h" #include "absl/strings/str_format.h" @@ -171,7 +172,7 @@ absl::Status TensorsToObjectsCalculator::LoadOptions(CalculatorContext* cc) { num_keypoints_ = options_.num_keypoints(); // Currently only support 2D when num_values_per_keypoint equals to 2. - CHECK_EQ(options_.num_values_per_keypoint(), 2); + ABSL_CHECK_EQ(options_.num_values_per_keypoint(), 2); return absl::OkStatus(); } diff --git a/mediapipe/modules/objectron/calculators/tflite_tensors_to_objects_calculator.cc b/mediapipe/modules/objectron/calculators/tflite_tensors_to_objects_calculator.cc index ebecfc093..1aefd4672 100644 --- a/mediapipe/modules/objectron/calculators/tflite_tensors_to_objects_calculator.cc +++ b/mediapipe/modules/objectron/calculators/tflite_tensors_to_objects_calculator.cc @@ -17,6 +17,7 @@ #include #include "Eigen/Dense" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/memory/memory.h" #include "absl/strings/str_format.h" @@ -179,7 +180,7 @@ absl::Status TfLiteTensorsToObjectsCalculator::LoadOptions( num_keypoints_ = options_.num_keypoints(); // Currently only support 2D when num_values_per_keypoint equals to 2. - CHECK_EQ(options_.num_values_per_keypoint(), 2); + ABSL_CHECK_EQ(options_.num_values_per_keypoint(), 2); return absl::OkStatus(); } diff --git a/mediapipe/objc/BUILD b/mediapipe/objc/BUILD index 81982cdd4..df6c8db08 100644 --- a/mediapipe/objc/BUILD +++ b/mediapipe/objc/BUILD @@ -39,6 +39,7 @@ cc_library( "//mediapipe/framework/port:source_location", "//mediapipe/framework/port:status", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/memory", ], diff --git a/mediapipe/objc/util.cc b/mediapipe/objc/util.cc index 8cefab974..684dc181c 100644 --- a/mediapipe/objc/util.cc +++ b/mediapipe/objc/util.cc @@ -15,6 +15,7 @@ #include "mediapipe/objc/util.h" #include "absl/base/macros.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/memory/memory.h" #include "mediapipe/framework/port/logging.h" @@ -572,7 +573,7 @@ std::unique_ptr CreateImageFrameForCVPixelBuffer( CVPixelBufferRef image_buffer, bool can_overwrite, bool bgr_as_rgb) { CVReturn status = CVPixelBufferLockBaseAddress(image_buffer, kCVPixelBufferLock_ReadOnly); - CHECK_EQ(status, kCVReturnSuccess) + ABSL_CHECK_EQ(status, kCVReturnSuccess) << "CVPixelBufferLockBaseAddress failed: " << status; void* base_address = CVPixelBufferGetBaseAddress(image_buffer); @@ -602,7 +603,7 @@ std::unique_ptr CreateImageFrameForCVPixelBuffer( const uint8_t permute_map[4] = {2, 1, 0, 3}; vImage_Error vError = vImagePermuteChannels_ARGB8888( &v_image, &v_dest, permute_map, kvImageNoFlags); - CHECK(vError == kvImageNoError) + ABSL_CHECK(vError == kvImageNoError) << "vImagePermuteChannels failed: " << vError; } } break; @@ -632,7 +633,7 @@ std::unique_ptr CreateImageFrameForCVPixelBuffer( // We have already created a new frame that does not reference the buffer. status = CVPixelBufferUnlockBaseAddress(image_buffer, kCVPixelBufferLock_ReadOnly); - CHECK_EQ(status, kCVReturnSuccess) + ABSL_CHECK_EQ(status, kCVReturnSuccess) << "CVPixelBufferUnlockBaseAddress failed: " << status; CVPixelBufferRelease(image_buffer); } else { diff --git a/mediapipe/tasks/cc/components/calculators/BUILD b/mediapipe/tasks/cc/components/calculators/BUILD index fb4b66b35..9046a280d 100644 --- a/mediapipe/tasks/cc/components/calculators/BUILD +++ b/mediapipe/tasks/cc/components/calculators/BUILD @@ -133,6 +133,7 @@ cc_test( "//mediapipe/framework/port:gtest_main", "//mediapipe/framework/port:parse_text_proto", "//mediapipe/tasks/metadata:metadata_schema_cc", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", ], ) diff --git a/mediapipe/tasks/cc/text/custom_ops/ragged/ragged_tensor_to_tensor_tflite.cc b/mediapipe/tasks/cc/text/custom_ops/ragged/ragged_tensor_to_tensor_tflite.cc index a0eadd715..1894dfa8d 100644 --- a/mediapipe/tasks/cc/text/custom_ops/ragged/ragged_tensor_to_tensor_tflite.cc +++ b/mediapipe/tasks/cc/text/custom_ops/ragged/ragged_tensor_to_tensor_tflite.cc @@ -357,7 +357,7 @@ void CalculateOutputIndexValueRowID(const TfLiteTensor& value_rowids, }; int current_output_column = 0; int current_value_rowid = value_rowids_val(0); - // DCHECK_LT(current_value_rowid, parent_output_index.size()); + // ABSL_DCHECK_LT(current_value_rowid, parent_output_index.size()); int current_output_index = parent_output_index[current_value_rowid]; result->push_back(current_output_index); for (int i = 1; i < index_size; ++i) { @@ -374,12 +374,12 @@ void CalculateOutputIndexValueRowID(const TfLiteTensor& value_rowids, } else { current_output_column = 0; current_value_rowid = next_value_rowid; - // DCHECK_LT(next_value_rowid, parent_output_index.size()); + // ABSL_DCHECK_LT(next_value_rowid, parent_output_index.size()); current_output_index = parent_output_index[next_value_rowid]; } result->push_back(current_output_index); } - // DCHECK_EQ(result->size(), value_rowids.size()); + // ABSL_DCHECK_EQ(result->size(), value_rowids.size()); } void CalculateOutputIndexRowSplit(const TfLiteTensor& row_split, @@ -420,7 +420,7 @@ void CalculateOutputIndexRowSplit(const TfLiteTensor& row_split, } } // if (row_split_size > 0) { - // DCHECK_EQ(result->size(), row_split(row_split_size - 1)); + // ABSL_DCHECK_EQ(result->size(), row_split(row_split_size - 1)); //} } diff --git a/mediapipe/tasks/cc/text/language_detector/custom_ops/BUILD b/mediapipe/tasks/cc/text/language_detector/custom_ops/BUILD index 26eee18c4..bb33bd200 100644 --- a/mediapipe/tasks/cc/text/language_detector/custom_ops/BUILD +++ b/mediapipe/tasks/cc/text/language_detector/custom_ops/BUILD @@ -37,6 +37,7 @@ cc_test( deps = [ ":kmeans_embedding_lookup", "//mediapipe/framework/port:gtest_main", + "@com_google_absl//absl/log:absl_check", "@org_tensorflow//tensorflow/lite:framework", "@org_tensorflow//tensorflow/lite/c:common", "@org_tensorflow//tensorflow/lite/kernels:test_util", @@ -66,6 +67,7 @@ cc_test( ":ngram_hash", "//mediapipe/framework/port:gtest_main", "//mediapipe/tasks/cc/text/language_detector/custom_ops/utils/hash:murmur", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/types:optional", "@flatbuffers", "@org_tensorflow//tensorflow/lite:framework", diff --git a/mediapipe/tasks/cc/text/language_detector/custom_ops/kmeans_embedding_lookup_test.cc b/mediapipe/tasks/cc/text/language_detector/custom_ops/kmeans_embedding_lookup_test.cc index f1ee661d4..54b5161fe 100644 --- a/mediapipe/tasks/cc/text/language_detector/custom_ops/kmeans_embedding_lookup_test.cc +++ b/mediapipe/tasks/cc/text/language_detector/custom_ops/kmeans_embedding_lookup_test.cc @@ -6,6 +6,7 @@ #include #include +#include "absl/log/absl_check.h" #include "mediapipe/framework/port/gmock.h" #include "mediapipe/framework/port/gtest.h" #include "tensorflow/lite/c/common.h" @@ -45,8 +46,8 @@ class KmeansEmbeddingLookupModel : public tflite::SingleOpModel { void Invoke(const std::vector& input, const std::vector& encoding_table, const std::vector& codebook) { - CHECK_EQ(SetUpInputTensor(input, encoding_table, codebook), kTfLiteOk); - CHECK_EQ(SingleOpModel::Invoke(), kTfLiteOk); + ABSL_CHECK_EQ(SetUpInputTensor(input, encoding_table, codebook), kTfLiteOk); + ABSL_CHECK_EQ(SingleOpModel::Invoke(), kTfLiteOk); } TfLiteStatus InvokeUnchecked(const std::vector& input, diff --git a/mediapipe/tasks/cc/text/language_detector/custom_ops/ngram_hash_test.cc b/mediapipe/tasks/cc/text/language_detector/custom_ops/ngram_hash_test.cc index d8b6ce3d4..1e348bdd1 100644 --- a/mediapipe/tasks/cc/text/language_detector/custom_ops/ngram_hash_test.cc +++ b/mediapipe/tasks/cc/text/language_detector/custom_ops/ngram_hash_test.cc @@ -20,6 +20,7 @@ limitations under the License. #include #include +#include "absl/log/absl_check.h" #include "absl/types/optional.h" #include "flatbuffers/flexbuffers.h" #include "mediapipe/framework/port/gmock.h" @@ -78,13 +79,13 @@ class NGramHashModel : public tflite::SingleOpModel { void SetupInputTensor(const std::string& input) { PopulateStringTensor(input_, {input}); - CHECK(interpreter_->AllocateTensors() == kTfLiteOk) + ABSL_CHECK(interpreter_->AllocateTensors() == kTfLiteOk) << "Cannot allocate tensors"; } void Invoke(const std::string& input) { SetupInputTensor(input); - CHECK_EQ(SingleOpModel::Invoke(), kTfLiteOk); + ABSL_CHECK_EQ(SingleOpModel::Invoke(), kTfLiteOk); } TfLiteStatus InvokeUnchecked(const std::string& input) { diff --git a/mediapipe/tasks/cc/text/text_embedder/BUILD b/mediapipe/tasks/cc/text/text_embedder/BUILD index 76025b3cf..c925abcbd 100644 --- a/mediapipe/tasks/cc/text/text_embedder/BUILD +++ b/mediapipe/tasks/cc/text/text_embedder/BUILD @@ -66,6 +66,7 @@ cc_library( "//mediapipe/tasks/cc/core/proto:model_resources_calculator_cc_proto", "//mediapipe/tasks/cc/text/text_embedder/proto:text_embedder_graph_options_cc_proto", "//mediapipe/tasks/cc/text/utils:text_model_utils", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", diff --git a/mediapipe/tasks/cc/text/text_embedder/text_embedder_graph.cc b/mediapipe/tasks/cc/text/text_embedder/text_embedder_graph.cc index 9c812e9fd..d5bdda4ff 100644 --- a/mediapipe/tasks/cc/text/text_embedder/text_embedder_graph.cc +++ b/mediapipe/tasks/cc/text/text_embedder/text_embedder_graph.cc @@ -13,6 +13,7 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ +#include "absl/log/absl_check.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/string_view.h" @@ -86,7 +87,7 @@ class TextEmbedderGraph : public core::ModelTaskGraph { public: absl::StatusOr GetConfig( SubgraphContext* sc) override { - CHECK(sc != nullptr); + ABSL_CHECK(sc != nullptr); ASSIGN_OR_RETURN(const ModelResources* model_resources, CreateModelResources(sc)); Graph graph; diff --git a/mediapipe/tasks/cc/text/tokenizers/BUILD b/mediapipe/tasks/cc/text/tokenizers/BUILD index 01908cd2c..b299f1c73 100644 --- a/mediapipe/tasks/cc/text/tokenizers/BUILD +++ b/mediapipe/tasks/cc/text/tokenizers/BUILD @@ -71,6 +71,7 @@ cc_library( deps = [ ":tokenizer", "//mediapipe/framework/port:logging", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", "@com_google_sentencepiece//src:sentencepiece_processor", ], @@ -86,6 +87,7 @@ cc_test( ":sentencepiece_tokenizer", "//mediapipe/framework/port:gtest_main", "//mediapipe/tasks/cc/core:utils", + "@com_google_absl//absl/log:absl_check", "@com_google_sentencepiece//src:sentencepiece_processor", ], ) @@ -105,6 +107,7 @@ cc_library( "//mediapipe/tasks/cc:common", "//mediapipe/tasks/cc/metadata:metadata_extractor", "//mediapipe/tasks/metadata:metadata_schema_cc", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", @@ -119,6 +122,7 @@ cc_test( "//mediapipe/tasks/testdata/text:albert_model", "//mediapipe/tasks/testdata/text:mobile_bert_model", "//mediapipe/tasks/testdata/text:text_classifier_models", + "@com_google_absl//absl/log:absl_check", ], linkopts = ["-ldl"], deps = [ diff --git a/mediapipe/tasks/cc/text/tokenizers/sentencepiece_tokenizer.h b/mediapipe/tasks/cc/text/tokenizers/sentencepiece_tokenizer.h index e1aab0ec5..97ef1848c 100644 --- a/mediapipe/tasks/cc/text/tokenizers/sentencepiece_tokenizer.h +++ b/mediapipe/tasks/cc/text/tokenizers/sentencepiece_tokenizer.h @@ -21,6 +21,7 @@ limitations under the License. #include #include +#include "absl/log/absl_check.h" #include "absl/strings/string_view.h" #include "mediapipe/framework/port/logging.h" #include "mediapipe/tasks/cc/text/tokenizers/tokenizer.h" @@ -36,20 +37,27 @@ class SentencePieceTokenizer : public Tokenizer { public: // Initialize the SentencePiece tokenizer from model file path. explicit SentencePieceTokenizer(const std::string& path_to_model) { - CHECK_OK(sp_.Load(path_to_model)); + // Can't use ABSL_CHECK_OK here because in internal builds + // the return type is absl::Status while the open source builds + // use sentencepiece/src/deps/status.h's util::Status which + // doesn't work with the absl CHECK macros. + const auto status = sp_.Load(path_to_model); + ABSL_CHECK(status.ok()) << status.ToString(); } explicit SentencePieceTokenizer(const char* spmodel_buffer_data, size_t spmodel_buffer_size) { absl::string_view buffer_binary(spmodel_buffer_data, spmodel_buffer_size); - CHECK_OK(sp_.LoadFromSerializedProto(buffer_binary)); + const auto status = sp_.LoadFromSerializedProto(buffer_binary); + ABSL_CHECK(status.ok()) << status.ToString(); } // Perform tokenization, return tokenized results. TokenizerResult Tokenize(const std::string& input) override { TokenizerResult result; std::vector& subwords = result.subwords; - CHECK_OK(sp_.Encode(input, &subwords)); + const auto status = sp_.Encode(input, &subwords); + ABSL_CHECK(status.ok()) << status.ToString(); return result; } diff --git a/mediapipe/tasks/cc/vision/face_detector/face_detector_graph_test.cc b/mediapipe/tasks/cc/vision/face_detector/face_detector_graph_test.cc index 72eb4cb56..651ad722d 100644 --- a/mediapipe/tasks/cc/vision/face_detector/face_detector_graph_test.cc +++ b/mediapipe/tasks/cc/vision/face_detector/face_detector_graph_test.cc @@ -21,6 +21,7 @@ limitations under the License. #include #include "absl/flags/flag.h" +#include "absl/log/absl_check.h" #include "absl/status/statusor.h" #include "absl/strings/str_format.h" #include "absl/strings/string_view.h" @@ -119,8 +120,9 @@ absl::StatusOr> CreateTaskRunner( Detection GetExpectedFaceDetectionResult(absl::string_view file_name) { Detection detection; - CHECK_OK(GetTextProto(file::JoinPath("./", kTestDataDirectory, file_name), - &detection, Defaults())) + ABSL_CHECK_OK( + GetTextProto(file::JoinPath("./", kTestDataDirectory, file_name), + &detection, Defaults())) << "Expected face detection result does not exist."; return detection; } diff --git a/mediapipe/tasks/cc/vision/face_detector/face_detector_test.cc b/mediapipe/tasks/cc/vision/face_detector/face_detector_test.cc index 97c64ac16..fcb32a7d3 100644 --- a/mediapipe/tasks/cc/vision/face_detector/face_detector_test.cc +++ b/mediapipe/tasks/cc/vision/face_detector/face_detector_test.cc @@ -18,6 +18,7 @@ limitations under the License. #include #include "absl/flags/flag.h" +#include "absl/log/absl_check.h" #include "mediapipe/framework/deps/file_path.h" #include "mediapipe/framework/formats/image.h" #include "mediapipe/framework/port/file_helpers.h" @@ -57,8 +58,9 @@ constexpr float kKeypointErrorThreshold = 1e-2; FaceDetectorResult GetExpectedFaceDetectorResult(absl::string_view file_name) { mediapipe::Detection detection; - CHECK_OK(GetTextProto(file::JoinPath("./", kTestDataDirectory, file_name), - &detection, Defaults())) + ABSL_CHECK_OK( + GetTextProto(file::JoinPath("./", kTestDataDirectory, file_name), + &detection, Defaults())) << "Expected face detection result does not exist."; return components::containers::ConvertToDetectionResult({detection}); } diff --git a/mediapipe/tasks/cc/vision/face_stylizer/calculators/BUILD b/mediapipe/tasks/cc/vision/face_stylizer/calculators/BUILD index 74b174015..46f8944ac 100644 --- a/mediapipe/tasks/cc/vision/face_stylizer/calculators/BUILD +++ b/mediapipe/tasks/cc/vision/face_stylizer/calculators/BUILD @@ -65,6 +65,7 @@ cc_library( "//mediapipe/framework/port:status", "//mediapipe/framework/port:vector", "//mediapipe/gpu:gpu_origin_cc_proto", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/status", "@com_google_absl//absl/strings", ] + select({ diff --git a/mediapipe/tasks/cc/vision/face_stylizer/calculators/tensors_to_image_calculator.cc b/mediapipe/tasks/cc/vision/face_stylizer/calculators/tensors_to_image_calculator.cc index 9e3fdc0ca..651b7efc3 100644 --- a/mediapipe/tasks/cc/vision/face_stylizer/calculators/tensors_to_image_calculator.cc +++ b/mediapipe/tasks/cc/vision/face_stylizer/calculators/tensors_to_image_calculator.cc @@ -16,6 +16,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "mediapipe/calculators/tensor/image_to_tensor_utils.h" @@ -162,8 +163,8 @@ absl::Status TensorsToImageCalculator::Open(CalculatorContext* cc) { #endif // MEDIAPIPE_METAL_ENABLED #endif // !MEDIAPIPE_DISABLE_GPU } else { - CHECK(options_.has_input_tensor_float_range() ^ - options_.has_input_tensor_uint_range()) + ABSL_CHECK(options_.has_input_tensor_float_range() ^ + options_.has_input_tensor_uint_range()) << "Must specify either `input_tensor_float_range` or " "`input_tensor_uint_range` in the calculator options"; } diff --git a/mediapipe/tasks/cc/vision/hand_detector/hand_detector_graph_test.cc b/mediapipe/tasks/cc/vision/hand_detector/hand_detector_graph_test.cc index c69869f75..eadc26ad9 100644 --- a/mediapipe/tasks/cc/vision/hand_detector/hand_detector_graph_test.cc +++ b/mediapipe/tasks/cc/vision/hand_detector/hand_detector_graph_test.cc @@ -21,6 +21,7 @@ limitations under the License. #include #include "absl/flags/flag.h" +#include "absl/log/absl_check.h" #include "absl/status/statusor.h" #include "absl/strings/str_format.h" #include "absl/strings/string_view.h" @@ -138,8 +139,8 @@ absl::StatusOr> CreateTaskRunner( HandDetectorResult GetExpectedHandDetectorResult(absl::string_view file_name) { HandDetectorResult result; - CHECK_OK(GetTextProto(file::JoinPath("./", kTestDataDirectory, file_name), - &result, Defaults())) + ABSL_CHECK_OK(GetTextProto( + file::JoinPath("./", kTestDataDirectory, file_name), &result, Defaults())) << "Expected hand detector result does not exist."; return result; } diff --git a/mediapipe/tasks/cc/vision/hand_landmarker/calculators/BUILD b/mediapipe/tasks/cc/vision/hand_landmarker/calculators/BUILD index a30cc5558..15806b516 100644 --- a/mediapipe/tasks/cc/vision/hand_landmarker/calculators/BUILD +++ b/mediapipe/tasks/cc/vision/hand_landmarker/calculators/BUILD @@ -42,6 +42,7 @@ cc_library( "//mediapipe/framework/port:rectangle", "//mediapipe/framework/port:status", "//mediapipe/util:rectangle_util", + "@com_google_absl//absl/log:absl_check", ], alwayslink = 1, ) diff --git a/mediapipe/tasks/cc/vision/hand_landmarker/calculators/hand_association_calculator.cc b/mediapipe/tasks/cc/vision/hand_landmarker/calculators/hand_association_calculator.cc index 060e7a2dc..5cbd72c3b 100644 --- a/mediapipe/tasks/cc/vision/hand_landmarker/calculators/hand_association_calculator.cc +++ b/mediapipe/tasks/cc/vision/hand_landmarker/calculators/hand_association_calculator.cc @@ -17,6 +17,7 @@ limitations under the License. #include #include +#include "absl/log/absl_check.h" #include "mediapipe/framework/api2/node.h" #include "mediapipe/framework/calculator_framework.h" #include "mediapipe/framework/collection_item_id.h" @@ -89,8 +90,8 @@ class HandAssociationCalculator : public CalculatorBase { cc->SetOffset(TimestampDiff(0)); options_ = cc->Options(); - CHECK_GT(options_.min_similarity_threshold(), 0.0); - CHECK_LE(options_.min_similarity_threshold(), 1.0); + ABSL_CHECK_GT(options_.min_similarity_threshold(), 0.0); + ABSL_CHECK_LE(options_.min_similarity_threshold(), 1.0); return absl::OkStatus(); } diff --git a/mediapipe/tasks/cc/vision/image_generator/diffuser/BUILD b/mediapipe/tasks/cc/vision/image_generator/diffuser/BUILD index 1dc24200b..fe10affa1 100644 --- a/mediapipe/tasks/cc/vision/image_generator/diffuser/BUILD +++ b/mediapipe/tasks/cc/vision/image_generator/diffuser/BUILD @@ -61,8 +61,8 @@ cc_library( "//mediapipe/framework:calculator_framework", "//mediapipe/framework/api2:node", "//mediapipe/framework/formats:tensor", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", - "@com_google_absl//absl/log:check", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", ], diff --git a/mediapipe/tasks/cc/vision/image_generator/diffuser/diffusion_plugins_output_calculator.cc b/mediapipe/tasks/cc/vision/image_generator/diffuser/diffusion_plugins_output_calculator.cc index a52c9afb9..a2282b907 100644 --- a/mediapipe/tasks/cc/vision/image_generator/diffuser/diffusion_plugins_output_calculator.cc +++ b/mediapipe/tasks/cc/vision/image_generator/diffuser/diffusion_plugins_output_calculator.cc @@ -17,7 +17,7 @@ limitations under the License. #include #include -#include "absl/log/check.h" +#include "absl/log/absl_check.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "mediapipe/framework/api2/node.h" @@ -49,7 +49,7 @@ class DiffusionPluginsOutputCalculator : public Node { return absl::InternalError("Input tensor vector is not consumable."); } if (kIterationIn(cc).IsConnected()) { - CHECK_EQ(kIterationIn(cc).Get(), 0); + ABSL_CHECK_EQ(kIterationIn(cc).Get(), 0); kTensorsOut(cc).Send(std::move(*status_or_tensor.value())); kTensorsOut(cc).SetNextTimestampBound(cc->InputTimestamp() + kStepsIn(cc).Get()); diff --git a/mediapipe/tasks/cc/vision/pose_detector/pose_detector_graph_test.cc b/mediapipe/tasks/cc/vision/pose_detector/pose_detector_graph_test.cc index 711131107..4d15583af 100644 --- a/mediapipe/tasks/cc/vision/pose_detector/pose_detector_graph_test.cc +++ b/mediapipe/tasks/cc/vision/pose_detector/pose_detector_graph_test.cc @@ -14,6 +14,7 @@ limitations under the License. ==============================================================================*/ #include "absl/flags/flag.h" +#include "absl/log/absl_check.h" #include "absl/status/statusor.h" #include "absl/strings/str_format.h" #include "absl/strings/string_view.h" @@ -114,16 +115,18 @@ absl::StatusOr> CreateTaskRunner( Detection GetExpectedPoseDetectionResult(absl::string_view file_name) { Detection detection; - CHECK_OK(GetTextProto(file::JoinPath("./", kTestDataDirectory, file_name), - &detection, Defaults())) + ABSL_CHECK_OK( + GetTextProto(file::JoinPath("./", kTestDataDirectory, file_name), + &detection, Defaults())) << "Expected pose detection result does not exist."; return detection; } NormalizedRect GetExpectedExpandedPoseRect(absl::string_view file_name) { NormalizedRect expanded_rect; - CHECK_OK(GetTextProto(file::JoinPath("./", kTestDataDirectory, file_name), - &expanded_rect, Defaults())) + ABSL_CHECK_OK( + GetTextProto(file::JoinPath("./", kTestDataDirectory, file_name), + &expanded_rect, Defaults())) << "Expected expanded pose rect does not exist."; return expanded_rect; } diff --git a/mediapipe/tasks/cc/vision/utils/BUILD b/mediapipe/tasks/cc/vision/utils/BUILD index 22bcdec4c..bb84cf3f1 100644 --- a/mediapipe/tasks/cc/vision/utils/BUILD +++ b/mediapipe/tasks/cc/vision/utils/BUILD @@ -61,6 +61,7 @@ cc_test_with_tflite( "//mediapipe/tasks/cc/metadata:metadata_extractor", "//mediapipe/tasks/metadata:metadata_schema_cc", "@com_google_absl//absl/flags:flag", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", diff --git a/mediapipe/tasks/cc/vision/utils/image_tensor_specs_test.cc b/mediapipe/tasks/cc/vision/utils/image_tensor_specs_test.cc index 7293d58b6..a10d1281c 100644 --- a/mediapipe/tasks/cc/vision/utils/image_tensor_specs_test.cc +++ b/mediapipe/tasks/cc/vision/utils/image_tensor_specs_test.cc @@ -21,6 +21,7 @@ limitations under the License. #include #include "absl/flags/flag.h" +#include "absl/log/absl_check.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/cord.h" @@ -179,7 +180,7 @@ TEST_F(ImageTensorSpecsTest, BuildInputImageTensorSpecsFromModelResources) { core::ModelResources::Create(kTestModelResourcesTag, std::move(model_file))); const tflite::Model* model = model_resources->GetTfLiteModel(); - CHECK(model != nullptr); + ABSL_CHECK(model != nullptr); absl::StatusOr input_specs_or = BuildInputImageTensorSpecs(*model_resources); MP_ASSERT_OK(input_specs_or); diff --git a/mediapipe/util/BUILD b/mediapipe/util/BUILD index e123d5641..0316224f7 100644 --- a/mediapipe/util/BUILD +++ b/mediapipe/util/BUILD @@ -69,6 +69,7 @@ cc_library( "//third_party:libffmpeg", "@com_google_absl//absl/base:endian", "@com_google_absl//absl/flags:flag", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", "@com_google_absl//absl/time", @@ -126,6 +127,7 @@ cc_library( "//mediapipe/framework/port:opencv_imgproc", "//mediapipe/framework/port:status", "//mediapipe/framework/tool:status_util", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", "@libyuv", @@ -172,6 +174,7 @@ cc_library( "//mediapipe/framework/port:opencv_core", "//mediapipe/framework/port:opencv_imgproc", "//mediapipe/framework/port:vector", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", ], ) @@ -253,6 +256,7 @@ cc_library( "//mediapipe/framework/port:logging", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/functional:function_ref", + "@com_google_absl//absl/log:absl_check", ], ) @@ -303,6 +307,7 @@ cc_library( "//mediapipe/framework/formats:time_series_header_cc_proto", "//mediapipe/framework/port:integral_types", "//mediapipe/framework/port:status", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", ], @@ -324,6 +329,7 @@ cc_library( "//mediapipe/framework/port:logging", "//mediapipe/framework/port:parse_text_proto", "//mediapipe/framework/port:status", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", "@eigen_archive//:eigen3", diff --git a/mediapipe/util/android/BUILD b/mediapipe/util/android/BUILD index d104e123a..d66558d12 100644 --- a/mediapipe/util/android/BUILD +++ b/mediapipe/util/android/BUILD @@ -39,8 +39,8 @@ cc_library( "//mediapipe/framework/port:status", "//mediapipe/framework/port:statusor", "//mediapipe/util/android/file/base", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", - "@com_google_absl//absl/log:check", "@com_google_absl//absl/strings", ] + select({ "//conditions:default": [], diff --git a/mediapipe/util/android/asset_manager_util.cc b/mediapipe/util/android/asset_manager_util.cc index 754f7fdfb..6e544ee80 100644 --- a/mediapipe/util/android/asset_manager_util.cc +++ b/mediapipe/util/android/asset_manager_util.cc @@ -16,8 +16,8 @@ #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" -#include "absl/log/check.h" #include "absl/strings/str_cat.h" #include "mediapipe/framework/port/ret_check.h" #include "mediapipe/java/com/google/mediapipe/framework/jni/jni_util.h" @@ -134,7 +134,7 @@ bool AssetManager::FileExists(const std::string& filename, bool* is_dir) { } bool AssetManager::ReadFile(const std::string& filename, std::string* output) { - CHECK(output); + ABSL_CHECK(output); if (!asset_manager_) { ABSL_LOG(ERROR) << "Asset manager was not initialized from JNI"; return false; diff --git a/mediapipe/util/annotation_renderer.cc b/mediapipe/util/annotation_renderer.cc index d6540c67e..b83b4f71e 100644 --- a/mediapipe/util/annotation_renderer.cc +++ b/mediapipe/util/annotation_renderer.cc @@ -19,6 +19,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "mediapipe/framework/port/logging.h" #include "mediapipe/framework/port/vector.h" @@ -48,10 +49,10 @@ int ClampThickness(int thickness) { bool NormalizedtoPixelCoordinates(double normalized_x, double normalized_y, int image_width, int image_height, int* x_px, int* y_px) { - CHECK(x_px != nullptr); - CHECK(y_px != nullptr); - CHECK_GT(image_width, 0); - CHECK_GT(image_height, 0); + ABSL_CHECK(x_px != nullptr); + ABSL_CHECK(y_px != nullptr); + ABSL_CHECK_GT(image_width, 0); + ABSL_CHECK_GT(image_height, 0); if (normalized_x < 0 || normalized_x > 1.0 || normalized_y < 0 || normalized_y > 1.0) { @@ -148,12 +149,12 @@ void AnnotationRenderer::DrawRectangle(const RenderAnnotation& annotation) { int bottom = -1; const auto& rectangle = annotation.rectangle(); if (rectangle.normalized()) { - CHECK(NormalizedtoPixelCoordinates(rectangle.left(), rectangle.top(), - image_width_, image_height_, &left, - &top)); - CHECK(NormalizedtoPixelCoordinates(rectangle.right(), rectangle.bottom(), - image_width_, image_height_, &right, - &bottom)); + ABSL_CHECK(NormalizedtoPixelCoordinates(rectangle.left(), rectangle.top(), + image_width_, image_height_, &left, + &top)); + ABSL_CHECK(NormalizedtoPixelCoordinates(rectangle.right(), + rectangle.bottom(), image_width_, + image_height_, &right, &bottom)); } else { left = static_cast(rectangle.left() * scale_factor_); top = static_cast(rectangle.top() * scale_factor_); @@ -200,12 +201,12 @@ void AnnotationRenderer::DrawFilledRectangle( int bottom = -1; const auto& rectangle = annotation.filled_rectangle().rectangle(); if (rectangle.normalized()) { - CHECK(NormalizedtoPixelCoordinates(rectangle.left(), rectangle.top(), - image_width_, image_height_, &left, - &top)); - CHECK(NormalizedtoPixelCoordinates(rectangle.right(), rectangle.bottom(), - image_width_, image_height_, &right, - &bottom)); + ABSL_CHECK(NormalizedtoPixelCoordinates(rectangle.left(), rectangle.top(), + image_width_, image_height_, &left, + &top)); + ABSL_CHECK(NormalizedtoPixelCoordinates(rectangle.right(), + rectangle.bottom(), image_width_, + image_height_, &right, &bottom)); } else { left = static_cast(rectangle.left() * scale_factor_); top = static_cast(rectangle.top() * scale_factor_); @@ -240,12 +241,12 @@ void AnnotationRenderer::DrawRoundedRectangle( int bottom = -1; const auto& rectangle = annotation.rounded_rectangle().rectangle(); if (rectangle.normalized()) { - CHECK(NormalizedtoPixelCoordinates(rectangle.left(), rectangle.top(), - image_width_, image_height_, &left, - &top)); - CHECK(NormalizedtoPixelCoordinates(rectangle.right(), rectangle.bottom(), - image_width_, image_height_, &right, - &bottom)); + ABSL_CHECK(NormalizedtoPixelCoordinates(rectangle.left(), rectangle.top(), + image_width_, image_height_, &left, + &top)); + ABSL_CHECK(NormalizedtoPixelCoordinates(rectangle.right(), + rectangle.bottom(), image_width_, + image_height_, &right, &bottom)); } else { left = static_cast(rectangle.left() * scale_factor_); top = static_cast(rectangle.top() * scale_factor_); @@ -273,12 +274,12 @@ void AnnotationRenderer::DrawFilledRoundedRectangle( const auto& rectangle = annotation.filled_rounded_rectangle().rounded_rectangle().rectangle(); if (rectangle.normalized()) { - CHECK(NormalizedtoPixelCoordinates(rectangle.left(), rectangle.top(), - image_width_, image_height_, &left, - &top)); - CHECK(NormalizedtoPixelCoordinates(rectangle.right(), rectangle.bottom(), - image_width_, image_height_, &right, - &bottom)); + ABSL_CHECK(NormalizedtoPixelCoordinates(rectangle.left(), rectangle.top(), + image_width_, image_height_, &left, + &top)); + ABSL_CHECK(NormalizedtoPixelCoordinates(rectangle.right(), + rectangle.bottom(), image_width_, + image_height_, &right, &bottom)); } else { left = static_cast(rectangle.left() * scale_factor_); top = static_cast(rectangle.top() * scale_factor_); @@ -345,10 +346,10 @@ void AnnotationRenderer::DrawOval(const RenderAnnotation& annotation) { int bottom = -1; const auto& enclosing_rectangle = annotation.oval().rectangle(); if (enclosing_rectangle.normalized()) { - CHECK(NormalizedtoPixelCoordinates(enclosing_rectangle.left(), - enclosing_rectangle.top(), image_width_, - image_height_, &left, &top)); - CHECK(NormalizedtoPixelCoordinates( + ABSL_CHECK(NormalizedtoPixelCoordinates( + enclosing_rectangle.left(), enclosing_rectangle.top(), image_width_, + image_height_, &left, &top)); + ABSL_CHECK(NormalizedtoPixelCoordinates( enclosing_rectangle.right(), enclosing_rectangle.bottom(), image_width_, image_height_, &right, &bottom)); } else { @@ -374,10 +375,10 @@ void AnnotationRenderer::DrawFilledOval(const RenderAnnotation& annotation) { int bottom = -1; const auto& enclosing_rectangle = annotation.filled_oval().oval().rectangle(); if (enclosing_rectangle.normalized()) { - CHECK(NormalizedtoPixelCoordinates(enclosing_rectangle.left(), - enclosing_rectangle.top(), image_width_, - image_height_, &left, &top)); - CHECK(NormalizedtoPixelCoordinates( + ABSL_CHECK(NormalizedtoPixelCoordinates( + enclosing_rectangle.left(), enclosing_rectangle.top(), image_width_, + image_height_, &left, &top)); + ABSL_CHECK(NormalizedtoPixelCoordinates( enclosing_rectangle.right(), enclosing_rectangle.bottom(), image_width_, image_height_, &right, &bottom)); } else { @@ -403,12 +404,12 @@ void AnnotationRenderer::DrawArrow(const RenderAnnotation& annotation) { const auto& arrow = annotation.arrow(); if (arrow.normalized()) { - CHECK(NormalizedtoPixelCoordinates(arrow.x_start(), arrow.y_start(), - image_width_, image_height_, &x_start, - &y_start)); - CHECK(NormalizedtoPixelCoordinates(arrow.x_end(), arrow.y_end(), - image_width_, image_height_, &x_end, - &y_end)); + ABSL_CHECK(NormalizedtoPixelCoordinates(arrow.x_start(), arrow.y_start(), + image_width_, image_height_, + &x_start, &y_start)); + ABSL_CHECK(NormalizedtoPixelCoordinates(arrow.x_end(), arrow.y_end(), + image_width_, image_height_, &x_end, + &y_end)); } else { x_start = static_cast(arrow.x_start() * scale_factor_); y_start = static_cast(arrow.y_start() * scale_factor_); @@ -454,8 +455,8 @@ void AnnotationRenderer::DrawPoint(const RenderAnnotation::Point& point, int x = -1; int y = -1; if (point.normalized()) { - CHECK(NormalizedtoPixelCoordinates(point.x(), point.y(), image_width_, - image_height_, &x, &y)); + ABSL_CHECK(NormalizedtoPixelCoordinates(point.x(), point.y(), image_width_, + image_height_, &x, &y)); } else { x = static_cast(point.x() * scale_factor_); y = static_cast(point.y() * scale_factor_); @@ -482,11 +483,12 @@ void AnnotationRenderer::DrawLine(const RenderAnnotation& annotation) { const auto& line = annotation.line(); if (line.normalized()) { - CHECK(NormalizedtoPixelCoordinates(line.x_start(), line.y_start(), - image_width_, image_height_, &x_start, - &y_start)); - CHECK(NormalizedtoPixelCoordinates(line.x_end(), line.y_end(), image_width_, - image_height_, &x_end, &y_end)); + ABSL_CHECK(NormalizedtoPixelCoordinates(line.x_start(), line.y_start(), + image_width_, image_height_, + &x_start, &y_start)); + ABSL_CHECK(NormalizedtoPixelCoordinates(line.x_end(), line.y_end(), + image_width_, image_height_, &x_end, + &y_end)); } else { x_start = static_cast(line.x_start() * scale_factor_); y_start = static_cast(line.y_start() * scale_factor_); @@ -510,11 +512,12 @@ void AnnotationRenderer::DrawGradientLine(const RenderAnnotation& annotation) { const auto& line = annotation.gradient_line(); if (line.normalized()) { - CHECK(NormalizedtoPixelCoordinates(line.x_start(), line.y_start(), - image_width_, image_height_, &x_start, - &y_start)); - CHECK(NormalizedtoPixelCoordinates(line.x_end(), line.y_end(), image_width_, - image_height_, &x_end, &y_end)); + ABSL_CHECK(NormalizedtoPixelCoordinates(line.x_start(), line.y_start(), + image_width_, image_height_, + &x_start, &y_start)); + ABSL_CHECK(NormalizedtoPixelCoordinates(line.x_end(), line.y_end(), + image_width_, image_height_, &x_end, + &y_end)); } else { x_start = static_cast(line.x_start() * scale_factor_); y_start = static_cast(line.y_start() * scale_factor_); @@ -538,9 +541,9 @@ void AnnotationRenderer::DrawText(const RenderAnnotation& annotation) { const auto& text = annotation.text(); if (text.normalized()) { - CHECK(NormalizedtoPixelCoordinates(text.left(), text.baseline(), - image_width_, image_height_, &left, - &baseline)); + ABSL_CHECK(NormalizedtoPixelCoordinates(text.left(), text.baseline(), + image_width_, image_height_, &left, + &baseline)); font_size = static_cast(round(text.font_height() * image_height_)); } else { left = static_cast(text.left() * scale_factor_); diff --git a/mediapipe/util/audio_decoder.cc b/mediapipe/util/audio_decoder.cc index 51cd12a0e..33d56887b 100644 --- a/mediapipe/util/audio_decoder.cc +++ b/mediapipe/util/audio_decoder.cc @@ -22,6 +22,7 @@ #include "Eigen/Core" #include "absl/base/internal/endian.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/strings/numbers.h" #include "absl/strings/str_cat.h" @@ -228,8 +229,8 @@ BasePacketProcessor::~BasePacketProcessor() { Close(); } bool BasePacketProcessor::HasData() { return !buffer_.empty(); } absl::Status BasePacketProcessor::GetData(Packet* packet) { - CHECK(packet); - CHECK(!buffer_.empty()); + ABSL_CHECK(packet); + ABSL_CHECK(!buffer_.empty()); *packet = buffer_.front(); buffer_.pop_front(); @@ -336,7 +337,7 @@ inline float PcmEncodedSampleInt32ToFloat(const char* data) { AudioPacketProcessor::AudioPacketProcessor(const AudioStreamOptions& options) : sample_time_base_{0, 0}, options_(options) { - DCHECK(absl::little_endian::IsLittleEndian()); + ABSL_DCHECK(absl::little_endian::IsLittleEndian()); } absl::Status AudioPacketProcessor::Open(int id, AVStream* stream) { @@ -350,7 +351,7 @@ absl::Status AudioPacketProcessor::Open(int id, AVStream* stream) { if (avcodec_open2(avcodec_ctx_, avcodec_, &avcodec_opts_) < 0) { return UnknownError("avcodec_open() failed."); } - CHECK(avcodec_ctx_->codec); + ABSL_CHECK(avcodec_ctx_->codec); source_time_base_ = stream->time_base; source_frame_rate_ = stream->r_frame_rate; @@ -412,7 +413,7 @@ int64_t AudioPacketProcessor::SampleNumberToMicroseconds( } absl::Status AudioPacketProcessor::ProcessPacket(AVPacket* packet) { - CHECK(packet); + ABSL_CHECK(packet); if (flushed_) { return UnknownError( "ProcessPacket was called, but AudioPacketProcessor is already " @@ -578,7 +579,7 @@ absl::Status AudioPacketProcessor::AddAudioDataToBuffer( } absl::Status AudioPacketProcessor::FillHeader(TimeSeriesHeader* header) const { - CHECK(header); + ABSL_CHECK(header); header->set_sample_rate(sample_rate_); header->set_num_channels(num_channels_); return absl::OkStatus(); @@ -658,14 +659,14 @@ absl::Status AudioDecoder::Initialize( MP_RETURN_IF_ERROR(processor->Open(stream_id, stream)); audio_processor_.emplace(stream_id, std::move(processor)); - CHECK(InsertIfNotPresent( + ABSL_CHECK(InsertIfNotPresent( &stream_index_to_stream_id_, options.audio_stream(*options_index_ptr).stream_index(), stream_id)); - CHECK(InsertIfNotPresent(&stream_id_to_audio_options_index_, - stream_id, *options_index_ptr)); - CHECK(InsertIfNotPresent(&audio_options_index_to_stream_id, - *options_index_ptr, stream_id)); + ABSL_CHECK(InsertIfNotPresent(&stream_id_to_audio_options_index_, + stream_id, *options_index_ptr)); + ABSL_CHECK(InsertIfNotPresent(&audio_options_index_to_stream_id, + *options_index_ptr, stream_id)); } ++current_audio_index; break; @@ -775,8 +776,8 @@ absl::Status AudioDecoder::ProcessPacket() { av_packet->data = nullptr; int ret = av_read_frame(avformat_ctx_, av_packet.get()); if (ret >= 0) { - CHECK(av_packet->data) << "AVPacket does not include any data but " - "av_read_frame was successful."; + ABSL_CHECK(av_packet->data) << "AVPacket does not include any data but " + "av_read_frame was successful."; const int stream_id = av_packet->stream_index; auto audio_iterator = audio_processor_.find(stream_id); if (audio_iterator != audio_processor_.end()) { diff --git a/mediapipe/util/filtering/BUILD b/mediapipe/util/filtering/BUILD index 17feab2d5..4acb83f60 100644 --- a/mediapipe/util/filtering/BUILD +++ b/mediapipe/util/filtering/BUILD @@ -57,8 +57,8 @@ cc_library( hdrs = ["relative_velocity_filter.h"], deps = [ ":low_pass_filter", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", - "@com_google_absl//absl/log:check", "@com_google_absl//absl/memory", "@com_google_absl//absl/time", ], @@ -71,6 +71,7 @@ cc_test( ":relative_velocity_filter", "//mediapipe/framework/port:gtest_main", "//mediapipe/framework/port:logging", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/memory", "@com_google_absl//absl/time", ], diff --git a/mediapipe/util/filtering/relative_velocity_filter.cc b/mediapipe/util/filtering/relative_velocity_filter.cc index f074d7db2..a10b1c5a1 100644 --- a/mediapipe/util/filtering/relative_velocity_filter.cc +++ b/mediapipe/util/filtering/relative_velocity_filter.cc @@ -17,8 +17,8 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" -#include "absl/log/check.h" #include "absl/memory/memory.h" namespace mediapipe { @@ -37,8 +37,8 @@ float RelativeVelocityFilter::Apply(absl::Duration timestamp, float value_scale, if (last_timestamp_ == -1) { alpha = 1.0; } else { - DCHECK(distance_mode_ == DistanceEstimationMode::kLegacyTransition || - distance_mode_ == DistanceEstimationMode::kForceCurrentScale); + ABSL_DCHECK(distance_mode_ == DistanceEstimationMode::kLegacyTransition || + distance_mode_ == DistanceEstimationMode::kForceCurrentScale); const float distance = distance_mode_ == DistanceEstimationMode::kLegacyTransition ? value * value_scale - diff --git a/mediapipe/util/filtering/relative_velocity_filter_test.cc b/mediapipe/util/filtering/relative_velocity_filter_test.cc index 717237bbe..4589f8336 100644 --- a/mediapipe/util/filtering/relative_velocity_filter_test.cc +++ b/mediapipe/util/filtering/relative_velocity_filter_test.cc @@ -18,6 +18,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/memory/memory.h" #include "absl/time/time.h" #include "mediapipe/framework/port/gtest.h" @@ -268,7 +269,7 @@ void TestTranslationInvariance(DistanceEstimationMode distance_mode) { ++times_largely_diverged; } } else { - CHECK(distance_mode == DistanceEstimationMode::kForceCurrentScale); + ABSL_CHECK(distance_mode == DistanceEstimationMode::kForceCurrentScale); EXPECT_NEAR(difference, 0.0f, kForceCurrentScaleAbsoluteError); } } diff --git a/mediapipe/util/frame_buffer/BUILD b/mediapipe/util/frame_buffer/BUILD index f0eda2943..c42c96431 100644 --- a/mediapipe/util/frame_buffer/BUILD +++ b/mediapipe/util/frame_buffer/BUILD @@ -41,6 +41,7 @@ cc_test( "//mediapipe/framework/formats:tensor", "//mediapipe/framework/port:gtest_main", "//mediapipe/framework/port:status", + "@com_google_absl//absl/log:absl_check", ], ) diff --git a/mediapipe/util/frame_buffer/frame_buffer_util_test.cc b/mediapipe/util/frame_buffer/frame_buffer_util_test.cc index 8e86f02d0..aed03962b 100644 --- a/mediapipe/util/frame_buffer/frame_buffer_util_test.cc +++ b/mediapipe/util/frame_buffer/frame_buffer_util_test.cc @@ -18,6 +18,7 @@ #include #include +#include "absl/log/absl_check.h" #include "mediapipe/framework/formats/frame_buffer.h" #include "mediapipe/framework/formats/tensor.h" #include "mediapipe/framework/port/gmock.h" @@ -784,7 +785,7 @@ TEST(FrameBufferUtil, RgbRotate) { absl::StatusOr> CreateYuvBuffer( uint8_t* buffer, FrameBuffer::Dimension dimension, int plane_count, FrameBuffer::Format format) { - DCHECK(plane_count > 0 && plane_count < 4); + ABSL_DCHECK(plane_count > 0 && plane_count < 4); ASSIGN_OR_RETURN(auto uv_dimension, GetUvPlaneDimension(dimension, format)); if (plane_count == 1) { @@ -793,8 +794,8 @@ absl::StatusOr> CreateYuvBuffer( /*pixel_stride_bytes=*/1}}}; return std::make_shared(planes, dimension, format); } else if (plane_count == 2) { - CHECK(format == FrameBuffer::Format::kNV12 || - format == FrameBuffer::Format::kNV21); + ABSL_CHECK(format == FrameBuffer::Format::kNV12 || + format == FrameBuffer::Format::kNV21); const std::vector planes = { {buffer, /*stride=*/{/*row_stride_bytes=*/dimension.width, diff --git a/mediapipe/util/image_frame_util.cc b/mediapipe/util/image_frame_util.cc index ecc0de717..418a6b09a 100644 --- a/mediapipe/util/image_frame_util.cc +++ b/mediapipe/util/image_frame_util.cc @@ -20,6 +20,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" @@ -46,8 +47,8 @@ void RescaleImageFrame(const ImageFrame& source_frame, const int width, const int height, const int alignment_boundary, const int open_cv_interpolation_algorithm, ImageFrame* destination_frame) { - CHECK(destination_frame); - CHECK_EQ(ImageFormat::SRGB, source_frame.Format()); + ABSL_CHECK(destination_frame); + ABSL_CHECK_EQ(ImageFormat::SRGB, source_frame.Format()); cv::Mat source_mat = ::mediapipe::formats::MatView(&source_frame); destination_frame->Reset(source_frame.Format(), width, height, @@ -61,7 +62,7 @@ void RescaleImageFrame(const ImageFrame& source_frame, const int width, void RescaleSrgbImage(const cv::Mat& source, const int width, const int height, const int open_cv_interpolation_algorithm, cv::Mat* destination) { - CHECK(destination); + ABSL_CHECK(destination); // Convert input_mat into 16 bit per channel linear RGB space. cv::Mat input_mat16; @@ -106,7 +107,7 @@ void ImageFrameToYUVImage(const ImageFrame& image_frame, YUVImage* yuv_image) { u, uv_stride, // v, uv_stride, // width, height); - CHECK_EQ(0, rv); + ABSL_CHECK_EQ(0, rv); } void ImageFrameToYUVNV12Image(const ImageFrame& image_frame, @@ -136,12 +137,12 @@ void ImageFrameToYUVNV12Image(const ImageFrame& image_frame, yuv_i420_image.stride(2), yuv_nv12_image->mutable_data(0), yuv_nv12_image->stride(0), yuv_nv12_image->mutable_data(1), yuv_nv12_image->stride(1), width, height); - CHECK_EQ(0, rv); + ABSL_CHECK_EQ(0, rv); } void YUVImageToImageFrame(const YUVImage& yuv_image, ImageFrame* image_frame, bool use_bt709) { - CHECK(image_frame); + ABSL_CHECK(image_frame); int width = yuv_image.width(); int height = yuv_image.height(); image_frame->Reset(ImageFormat::SRGB, width, height, 16); @@ -161,12 +162,12 @@ void YUVImageToImageFrame(const YUVImage& yuv_image, ImageFrame* image_frame, image_frame->MutablePixelData(), image_frame->WidthStep(), width, height); } - CHECK_EQ(0, rv); + ABSL_CHECK_EQ(0, rv); } void YUVImageToImageFrameFromFormat(const YUVImage& yuv_image, ImageFrame* image_frame) { - CHECK(image_frame); + ABSL_CHECK(image_frame); int width = yuv_image.width(); int height = yuv_image.height(); image_frame->Reset(ImageFormat::SRGB, width, height, 16); diff --git a/mediapipe/util/resource_cache.h b/mediapipe/util/resource_cache.h index 2b3ccbc7d..517182f18 100644 --- a/mediapipe/util/resource_cache.h +++ b/mediapipe/util/resource_cache.h @@ -19,6 +19,7 @@ #include "absl/container/flat_hash_map.h" #include "absl/functional/function_ref.h" +#include "absl/log/absl_check.h" #include "mediapipe/framework/port/logging.h" namespace mediapipe { @@ -40,10 +41,10 @@ class ResourceCache { std::tie(map_it, std::ignore) = map_.try_emplace(key, std::make_unique(key)); entry = map_it->second.get(); - CHECK_EQ(entry->request_count, 0); + ABSL_CHECK_EQ(entry->request_count, 0); entry->request_count = 1; entry_list_.Append(entry); - if (entry->prev != nullptr) CHECK_GE(entry->prev->request_count, 1); + if (entry->prev != nullptr) ABSL_CHECK_GE(entry->prev->request_count, 1); } else { entry = map_it->second.get(); ++entry->request_count; diff --git a/mediapipe/util/sequence/BUILD b/mediapipe/util/sequence/BUILD index c7ee52f82..238583043 100644 --- a/mediapipe/util/sequence/BUILD +++ b/mediapipe/util/sequence/BUILD @@ -31,6 +31,7 @@ cc_library( "//mediapipe/framework/port:core_proto", "//mediapipe/framework/port:integral_types", "//mediapipe/framework/port:logging", + "@com_google_absl//absl/log:absl_check", "@org_tensorflow//tensorflow/core:protos_all_cc", ], ) @@ -50,6 +51,7 @@ cc_library( "//mediapipe/framework/port:opencv_imgcodecs", "//mediapipe/framework/port:ret_check", "//mediapipe/framework/port:status", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/memory", "@com_google_absl//absl/strings", "@org_tensorflow//tensorflow/core:protos_all_cc", diff --git a/mediapipe/util/sequence/media_sequence.cc b/mediapipe/util/sequence/media_sequence.cc index 21d030fff..9cff193cd 100644 --- a/mediapipe/util/sequence/media_sequence.cc +++ b/mediapipe/util/sequence/media_sequence.cc @@ -17,6 +17,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/strings/str_split.h" #include "mediapipe/framework/port/opencv_imgcodecs_inc.h" #include "mediapipe/framework/port/ret_check.h" @@ -530,11 +531,11 @@ std::unique_ptr GetAudioFromFeatureAt( const std::string& prefix, const tensorflow::SequenceExample& sequence, int index) { const auto& flat_data = GetFeatureFloatsAt(prefix, sequence, index); - CHECK(HasFeatureNumChannels(prefix, sequence)) + ABSL_CHECK(HasFeatureNumChannels(prefix, sequence)) << "GetAudioAt requires num_channels context to be specified as key: " << merge_prefix(prefix, kFeatureNumChannelsKey); int num_channels = GetFeatureNumChannels(prefix, sequence); - CHECK_EQ(flat_data.size() % num_channels, 0) + ABSL_CHECK_EQ(flat_data.size() % num_channels, 0) << "The data size is not a multiple of the number of channels: " << flat_data.size() << " % " << num_channels << " = " << flat_data.size() % num_channels << " for sequence index " << index; diff --git a/mediapipe/util/sequence/media_sequence_util.h b/mediapipe/util/sequence/media_sequence_util.h index 1737f91a0..5b765f13b 100644 --- a/mediapipe/util/sequence/media_sequence_util.h +++ b/mediapipe/util/sequence/media_sequence_util.h @@ -92,6 +92,7 @@ #include #include +#include "absl/log/absl_check.h" #include "mediapipe/framework/port/integral_types.h" #include "mediapipe/framework/port/logging.h" #include "mediapipe/framework/port/proto_ns.h" @@ -124,7 +125,7 @@ inline const tensorflow::Feature& GetContext( // proto map's at function also checks whether key is present, but it doesn't // print the missing key when it check-fails. const auto it = sequence.context().feature().find(key); - CHECK(it != sequence.context().feature().end()) + ABSL_CHECK(it != sequence.context().feature().end()) << "Could not find context key " << key << ". Sequence: \n" << sequence.DebugString(); return it->second; @@ -220,7 +221,7 @@ inline const proto_ns::RepeatedField& GetFloatsAt( const tensorflow::SequenceExample& sequence, const std::string& key, const int index) { const tensorflow::FeatureList& fl = GetFeatureList(sequence, key); - CHECK_LT(index, fl.feature_size()) + ABSL_CHECK_LT(index, fl.feature_size()) << "Sequence: \n " << sequence.DebugString(); return fl.feature().Get(index).float_list().value(); } @@ -231,7 +232,7 @@ inline const proto_ns::RepeatedField& GetInt64sAt( const tensorflow::SequenceExample& sequence, const std::string& key, const int index) { const tensorflow::FeatureList& fl = GetFeatureList(sequence, key); - CHECK_LT(index, fl.feature_size()) + ABSL_CHECK_LT(index, fl.feature_size()) << "Sequence: \n " << sequence.DebugString(); return fl.feature().Get(index).int64_list().value(); } @@ -242,7 +243,7 @@ inline const proto_ns::RepeatedPtrField& GetBytesAt( const tensorflow::SequenceExample& sequence, const std::string& key, const int index) { const tensorflow::FeatureList& fl = GetFeatureList(sequence, key); - CHECK_LT(index, fl.feature_size()) + ABSL_CHECK_LT(index, fl.feature_size()) << "Sequence: \n " << sequence.DebugString(); return fl.feature().Get(index).bytes_list().value(); } diff --git a/mediapipe/util/tflite/BUILD b/mediapipe/util/tflite/BUILD index 97ee1cddb..b34d0e080 100644 --- a/mediapipe/util/tflite/BUILD +++ b/mediapipe/util/tflite/BUILD @@ -49,6 +49,7 @@ cc_library_with_tflite( "//mediapipe/util/tflite/operations:transform_landmarks", "//mediapipe/util/tflite/operations:transform_tensor_bilinear", "//mediapipe/util/tflite/operations:transpose_conv_bias", + "@com_google_absl//absl/log:absl_check", "@org_tensorflow//tensorflow/lite:builtin_op_data", ], # For using the symbol `MediaPipe_RegisterTfLiteOpResolver` in Python diff --git a/mediapipe/util/tflite/cpu_op_resolver.cc b/mediapipe/util/tflite/cpu_op_resolver.cc index 588a237b2..3b5ab308f 100644 --- a/mediapipe/util/tflite/cpu_op_resolver.cc +++ b/mediapipe/util/tflite/cpu_op_resolver.cc @@ -14,6 +14,7 @@ #include "mediapipe/util/tflite/cpu_op_resolver.h" +#include "absl/log/absl_check.h" #include "mediapipe/framework/port/logging.h" #include "mediapipe/util/tflite/operations/landmarks_to_transform_matrix.h" #include "mediapipe/util/tflite/operations/max_pool_argmax.h" @@ -27,7 +28,7 @@ namespace mediapipe { void MediaPipe_RegisterTfLiteOpResolver(tflite::MutableOpResolver *resolver) { - CHECK(resolver != nullptr); + ABSL_CHECK(resolver != nullptr); resolver->AddCustom("MaxPoolingWithArgmax2D", tflite_operations::RegisterMaxPoolingWithArgmax2D()); resolver->AddCustom("MaxUnpooling2D", diff --git a/mediapipe/util/time_series_test_util.h b/mediapipe/util/time_series_test_util.h index f44a0bdb3..50fe32601 100644 --- a/mediapipe/util/time_series_test_util.h +++ b/mediapipe/util/time_series_test_util.h @@ -20,6 +20,7 @@ #include #include "Eigen/Core" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" @@ -140,7 +141,7 @@ class TimeSeriesCalculatorTest : public ::testing::Test { // _, _, etc. std::vector MakeNames(const std::vector& base_names, const std::vector& ids) { - CHECK_EQ(base_names.size(), ids.size()); + ABSL_CHECK_EQ(base_names.size(), ids.size()); std::vector names; for (int i = 0; i < base_names.size(); ++i) { const std::string name_template = R"($0_$1)"; diff --git a/mediapipe/util/time_series_util.cc b/mediapipe/util/time_series_util.cc index e74350333..f978280a9 100644 --- a/mediapipe/util/time_series_util.cc +++ b/mediapipe/util/time_series_util.cc @@ -19,6 +19,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/strings/str_cat.h" #include "mediapipe/framework/calculator_framework.h" @@ -79,7 +80,7 @@ absl::Status IsTimeSeriesHeaderValid(const TimeSeriesHeader& header) { absl::Status FillTimeSeriesHeaderIfValid(const Packet& header_packet, TimeSeriesHeader* header) { - CHECK(header); + ABSL_CHECK(header); if (header_packet.IsEmpty()) { return tool::StatusFail("No header found."); } @@ -92,7 +93,7 @@ absl::Status FillTimeSeriesHeaderIfValid(const Packet& header_packet, absl::Status FillMultiStreamTimeSeriesHeaderIfValid( const Packet& header_packet, MultiStreamTimeSeriesHeader* header) { - CHECK(header); + ABSL_CHECK(header); if (header_packet.IsEmpty()) { return tool::StatusFail("No header found."); } @@ -127,7 +128,7 @@ int64_t SecondsToSamples(double time_in_seconds, double sample_rate) { } double SamplesToSeconds(int64_t num_samples, double sample_rate) { - DCHECK_NE(sample_rate, 0.0); + ABSL_DCHECK_NE(sample_rate, 0.0); return (num_samples / sample_rate); } diff --git a/mediapipe/util/tracking/BUILD b/mediapipe/util/tracking/BUILD index d845f6a45..969723988 100644 --- a/mediapipe/util/tracking/BUILD +++ b/mediapipe/util/tracking/BUILD @@ -143,6 +143,7 @@ cc_library( "//mediapipe/framework/port:singleton", "//mediapipe/framework/port:vector", "@com_google_absl//absl/container:node_hash_map", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings:str_format", "@eigen_archive//:eigen3", @@ -157,6 +158,7 @@ cc_library( ":motion_models", ":motion_models_cc_proto", "//mediapipe/framework/port:opencv_core", + "@com_google_absl//absl/log:absl_check", ], ) @@ -173,6 +175,7 @@ cc_library( "//mediapipe/framework/port:vector", "@com_google_absl//absl/container:node_hash_map", "@com_google_absl//absl/container:node_hash_set", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", ], @@ -187,6 +190,7 @@ cc_library( ":motion_models", ":region_flow", ":region_flow_cc_proto", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings:str_format", ], @@ -206,8 +210,8 @@ cc_library( hdrs = ["measure_time.h"], deps = [ "//mediapipe/framework/port:integral_types", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", - "@com_google_absl//absl/log:check", "@com_google_absl//absl/strings", "@com_google_absl//absl/synchronization", "@com_google_absl//absl/time", @@ -223,8 +227,8 @@ cc_library( deps = [ ":parallel_invoker_forbid_mixed_active", "//mediapipe/framework/port:threadpool", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", - "@com_google_absl//absl/log:check", "@com_google_absl//absl/synchronization", ], ) @@ -248,6 +252,7 @@ cc_library( "//mediapipe/framework/port:opencv_core", "//mediapipe/framework/port:opencv_imgproc", "//mediapipe/framework/port:vector", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", ], ) @@ -259,8 +264,8 @@ cc_library( deps = [ "//mediapipe/framework/tool:type_util", "@com_google_absl//absl/container:node_hash_map", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", - "@com_google_absl//absl/log:check", "@com_google_absl//absl/strings", "@com_google_absl//absl/types:any", ], @@ -286,6 +291,7 @@ cc_library( "//mediapipe/framework/port:vector", "@com_google_absl//absl/container:node_hash_map", "@com_google_absl//absl/container:node_hash_set", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", "@eigen_archive//:eigen3", @@ -303,6 +309,7 @@ cc_library( ":region_flow", ":region_flow_cc_proto", "//mediapipe/framework/port:vector", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", ], ) @@ -315,6 +322,7 @@ cc_library( ":push_pull_filtering_cc_proto", "//mediapipe/framework/port:integral_types", "//mediapipe/framework/port:opencv_core", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", ], ) @@ -328,6 +336,7 @@ cc_library( "//mediapipe/framework/port:integral_types", "//mediapipe/framework/port:opencv_core", "//mediapipe/framework/port:vector", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings:str_format", ], @@ -349,6 +358,7 @@ cc_library( "//mediapipe/framework/port:opencv_core", "//mediapipe/framework/port:opencv_imgproc", "//mediapipe/framework/port:vector", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", ], ) @@ -384,6 +394,7 @@ cc_library( "//mediapipe/framework/port:vector", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:node_hash_set", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/memory", "@eigen_archive//:eigen3", @@ -405,6 +416,7 @@ cc_library( "//mediapipe/framework/port:opencv_core", "//mediapipe/framework/port:opencv_imgproc", "//mediapipe/framework/port:vector", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", ], ) @@ -434,6 +446,7 @@ cc_library( "//mediapipe/framework/port:opencv_core", "//mediapipe/framework/port:opencv_imgproc", "//mediapipe/framework/port:vector", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings:str_format", ], @@ -457,6 +470,7 @@ cc_library( "//mediapipe/framework/port:logging", "//mediapipe/framework/port:vector", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", ], @@ -484,6 +498,7 @@ cc_library( "//mediapipe/framework/port:vector", "@com_google_absl//absl/algorithm:container", "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/memory", "@eigen_archive//:eigen3", @@ -504,6 +519,7 @@ cc_library( "//mediapipe/framework/port:integral_types", "//mediapipe/framework/port:logging", "//mediapipe/framework/port:threadpool", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", "@com_google_absl//absl/strings:str_format", @@ -529,6 +545,7 @@ cc_library( "//mediapipe/framework/port:opencv_imgproc", "//mediapipe/framework/port:opencv_video", "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/memory", "@com_google_absl//absl/synchronization", @@ -547,6 +564,7 @@ cc_library( ":tracking_cc_proto", "//mediapipe/framework/port:opencv_core", "//mediapipe/framework/port:opencv_imgproc", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings:str_format", ], @@ -607,6 +625,7 @@ cc_test( "//mediapipe/framework/port:status", "//mediapipe/framework/port:vector", "@com_google_absl//absl/flags:flag", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/time", ], diff --git a/mediapipe/util/tracking/box_detector.cc b/mediapipe/util/tracking/box_detector.cc index 81947f9cf..e477d7cd4 100644 --- a/mediapipe/util/tracking/box_detector.cc +++ b/mediapipe/util/tracking/box_detector.cc @@ -16,6 +16,7 @@ #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/memory/memory.h" #include "mediapipe/framework/port/opencv_calib3d_inc.h" @@ -44,10 +45,10 @@ void ScaleBox(float scale_x, float scale_y, TimedBoxProto *box) { } cv::Mat ConvertDescriptorsToMat(const std::vector &descriptors) { - CHECK(!descriptors.empty()) << "empty descriptors."; + ABSL_CHECK(!descriptors.empty()) << "empty descriptors."; const int descriptors_dims = descriptors[0].size(); - CHECK_GT(descriptors_dims, 0); + ABSL_CHECK_GT(descriptors_dims, 0); cv::Mat mat(descriptors.size(), descriptors_dims, CV_8U); @@ -60,13 +61,13 @@ cv::Mat ConvertDescriptorsToMat(const std::vector &descriptors) { cv::Mat GetDescriptorsWithIndices(const cv::Mat &frame_descriptors, const std::vector &indices) { - CHECK_GT(frame_descriptors.rows, 0); + ABSL_CHECK_GT(frame_descriptors.rows, 0); const int num_inlier_descriptors = indices.size(); - CHECK_GT(num_inlier_descriptors, 0); + ABSL_CHECK_GT(num_inlier_descriptors, 0); const int descriptors_dims = frame_descriptors.cols; - CHECK_GT(descriptors_dims, 0); + ABSL_CHECK_GT(descriptors_dims, 0); cv::Mat mat(num_inlier_descriptors, descriptors_dims, CV_32F); @@ -303,7 +304,7 @@ void BoxDetectorInterface::DetectAndAddBox( orb_extractor_->detect(resize_image, keypoints); orb_extractor_->compute(resize_image, keypoints, descriptors); - CHECK_EQ(keypoints.size(), descriptors.rows); + ABSL_CHECK_EQ(keypoints.size(), descriptors.rows); float inv_scale = 1.0f / std::max(resize_image.cols, resize_image.rows); std::vector v_keypoints(keypoints.size()); @@ -683,15 +684,15 @@ void BoxDetectorInterface::AddBoxDetectorIndex(const BoxDetectorIndex &index) { continue; } - CHECK_EQ(frame_entry.keypoints_size(), - frame_entry.descriptors_size() * 2); + ABSL_CHECK_EQ(frame_entry.keypoints_size(), + frame_entry.descriptors_size() * 2); const int num_features = frame_entry.descriptors_size(); - CHECK_GT(num_features, 0); + ABSL_CHECK_GT(num_features, 0); std::vector features(num_features); const int descriptors_dims = frame_entry.descriptors(0).data().size(); - CHECK_GT(descriptors_dims, 0); + ABSL_CHECK_GT(descriptors_dims, 0); cv::Mat descriptors_mat(num_features, descriptors_dims / sizeof(float), CV_32F); @@ -715,7 +716,7 @@ std::vector BoxDetectorOpencvBfImpl::MatchFeatureDescriptors( const std::vector &features, const cv::Mat &descriptors, int box_idx) { - CHECK_EQ(features.size(), descriptors.rows); + ABSL_CHECK_EQ(features.size(), descriptors.rows); std::vector correspondence_result( frame_box_[box_idx].size()); diff --git a/mediapipe/util/tracking/box_tracker.cc b/mediapipe/util/tracking/box_tracker.cc index d74445141..47986516a 100644 --- a/mediapipe/util/tracking/box_tracker.cc +++ b/mediapipe/util/tracking/box_tracker.cc @@ -19,6 +19,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/strings/str_cat.h" #include "absl/synchronization/mutex.h" @@ -37,8 +38,8 @@ static constexpr int kInitCheckpoint = -1; void MotionBoxStateQuadToVertices(const MotionBoxState::Quad& quad, std::vector* vertices) { - CHECK_EQ(TimedBox::kNumQuadVertices * 2, quad.vertices_size()); - CHECK(vertices != nullptr); + ABSL_CHECK_EQ(TimedBox::kNumQuadVertices * 2, quad.vertices_size()); + ABSL_CHECK(vertices != nullptr); vertices->clear(); for (int i = 0; i < TimedBox::kNumQuadVertices; ++i) { vertices->push_back( @@ -48,8 +49,8 @@ void MotionBoxStateQuadToVertices(const MotionBoxState::Quad& quad, void VerticesToMotionBoxStateQuad(const std::vector& vertices, MotionBoxState::Quad* quad) { - CHECK_EQ(TimedBox::kNumQuadVertices, vertices.size()); - CHECK(quad != nullptr); + ABSL_CHECK_EQ(TimedBox::kNumQuadVertices, vertices.size()); + ABSL_CHECK(quad != nullptr); for (const Vector2_f& vertex : vertices) { quad->add_vertices(vertex.x()); quad->add_vertices(vertex.y()); @@ -57,7 +58,7 @@ void VerticesToMotionBoxStateQuad(const std::vector& vertices, } void MotionBoxStateFromTimedBox(const TimedBox& box, MotionBoxState* state) { - CHECK(state); + ABSL_CHECK(state); state->set_pos_x(box.left); state->set_pos_y(box.top); state->set_width(box.right - box.left); @@ -91,7 +92,7 @@ void MotionBoxStateFromTimedBox(const TimedBox& box, MotionBoxState* state) { } void TimedBoxFromMotionBoxState(const MotionBoxState& state, TimedBox* box) { - CHECK(box); + ABSL_CHECK(box); const float scale_dx = state.width() * (state.scale() - 1.0f) * 0.5f; const float scale_dy = state.height() * (state.scale() - 1.0f) * 0.5f; box->left = state.pos_x() - scale_dx; @@ -114,7 +115,7 @@ namespace { TimedBox BlendTimedBoxes(const TimedBox& lhs, const TimedBox& rhs, int64_t time_msec) { - CHECK_LT(lhs.time_msec, rhs.time_msec); + ABSL_CHECK_LT(lhs.time_msec, rhs.time_msec); const double alpha = (time_msec - lhs.time_msec) * 1.0 / (rhs.time_msec - lhs.time_msec); return TimedBox::Blend(lhs, rhs, alpha); @@ -246,10 +247,10 @@ BoxTracker::BoxTracker( void BoxTracker::AddTrackingDataChunk(const TrackingDataChunk* chunk, bool copy_data) { - CHECK_GT(chunk->item_size(), 0) << "Empty chunk."; + ABSL_CHECK_GT(chunk->item_size(), 0) << "Empty chunk."; int64_t chunk_time_msec = chunk->item(0).timestamp_usec() / 1000; int chunk_idx = ChunkIdxFromTime(chunk_time_msec); - CHECK_GE(chunk_idx, tracking_data_.size()) << "Chunk is out of order."; + ABSL_CHECK_GE(chunk_idx, tracking_data_.size()) << "Chunk is out of order."; if (chunk_idx > tracking_data_.size()) { ABSL_LOG(INFO) << "Resize tracking_data_ to " << chunk_idx; tracking_data_.resize(chunk_idx); @@ -486,12 +487,12 @@ void BoxTracker::CancelTracking(int id, int checkpoint) { bool BoxTracker::GetTimedPosition(int id, int64_t time_msec, TimedBox* result, std::vector* states) { - CHECK(result); + ABSL_CHECK(result); MotionBoxState* lhs_box_state = nullptr; MotionBoxState* rhs_box_state = nullptr; if (states) { - CHECK(options_.record_path_states()) + ABSL_CHECK(options_.record_path_states()) << "Requesting corresponding tracking states requires option " << "record_path_states to be set"; states->resize(1); @@ -689,7 +690,7 @@ bool BoxTracker::WaitForChunkFile(int id, int checkpoint, int BoxTracker::ClosestFrameIndex(int64_t msec, const TrackingDataChunk& chunk) const { - CHECK_GT(chunk.item_size(), 0); + ABSL_CHECK_GT(chunk.item_size(), 0); typedef TrackingDataChunk::Item Item; Item item_to_find; item_to_find.set_timestamp_usec(msec * 1000); @@ -751,8 +752,8 @@ void BoxTracker::TrackingImpl(const TrackingImplArgs& a) { MotionBox motion_box(track_step_options); const int chunk_data_size = a.chunk_data->item_size(); - CHECK_GE(a.start_frame, 0); - CHECK_LT(a.start_frame, chunk_data_size); + ABSL_CHECK_GE(a.start_frame, 0); + ABSL_CHECK_LT(a.start_frame, chunk_data_size); VLOG(1) << " a.start_frame = " << a.start_frame << " @" << a.chunk_data->item(a.start_frame).timestamp_usec() << " with " @@ -909,7 +910,7 @@ void BoxTracker::TrackingImpl(const TrackingImplArgs& a) { bool TimedBoxAtTime(const PathSegment& segment, int64_t time_msec, TimedBox* box, MotionBoxState* state) { - CHECK(box); + ABSL_CHECK(box); if (segment.empty()) { return false; @@ -1033,7 +1034,7 @@ bool BoxTracker::WaitForAllOngoingTracks(int timeout_us) { bool BoxTracker::GetTrackingData(int id, int64_t request_time_msec, TrackingData* tracking_data, int* tracking_data_msec) { - CHECK(tracking_data); + ABSL_CHECK(tracking_data); int chunk_idx = ChunkIdxFromTime(request_time_msec); diff --git a/mediapipe/util/tracking/camera_motion.cc b/mediapipe/util/tracking/camera_motion.cc index 8e8e238d3..21924a9d0 100644 --- a/mediapipe/util/tracking/camera_motion.cc +++ b/mediapipe/util/tracking/camera_motion.cc @@ -16,6 +16,7 @@ #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/strings/str_format.h" #include "mediapipe/util/tracking/region_flow.h" @@ -77,8 +78,8 @@ void CameraMotionToMixtureHomography(const CameraMotion& camera_motion, CameraMotion ComposeCameraMotion(const CameraMotion& lhs, const CameraMotion& rhs) { - CHECK_EQ(lhs.frame_width(), rhs.frame_width()); - CHECK_EQ(lhs.frame_height(), rhs.frame_height()); + ABSL_CHECK_EQ(lhs.frame_width(), rhs.frame_width()); + ABSL_CHECK_EQ(lhs.frame_height(), rhs.frame_height()); CameraMotion result = rhs; if (lhs.has_translation() || rhs.has_translation()) { @@ -186,8 +187,8 @@ CameraMotion InvertCameraMotion(const CameraMotion& motion) { void SubtractCameraMotionFromFeatures( const std::vector& camera_motions, std::vector* feature_lists) { - CHECK(feature_lists != nullptr); - CHECK_GE(camera_motions.size(), feature_lists->size()); + ABSL_CHECK(feature_lists != nullptr); + ABSL_CHECK_GE(camera_motions.size(), feature_lists->size()); if (feature_lists->empty()) { return; } diff --git a/mediapipe/util/tracking/camera_motion.h b/mediapipe/util/tracking/camera_motion.h index b37fd482f..cfe6b250f 100644 --- a/mediapipe/util/tracking/camera_motion.h +++ b/mediapipe/util/tracking/camera_motion.h @@ -17,6 +17,7 @@ #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "mediapipe/util/tracking/camera_motion.pb.h" #include "mediapipe/util/tracking/motion_models.h" @@ -237,11 +238,11 @@ void DownsampleMotionModels( std::vector* downsampled_models, std::vector* downsampled_types) { if (model_type) { - CHECK_EQ(models.size(), model_type->size()); - CHECK(downsampled_models) << "Expecting output models."; + ABSL_CHECK_EQ(models.size(), model_type->size()); + ABSL_CHECK(downsampled_models) << "Expecting output models."; } - CHECK(downsampled_models); + ABSL_CHECK(downsampled_models); downsampled_models->clear(); if (downsampled_types) { downsampled_types->clear(); @@ -277,7 +278,7 @@ void DownsampleMotionModels( template void SubsampleEntities(const Container& input, int downsample_factor, Container* output) { - CHECK(output); + ABSL_CHECK(output); output->clear(); if (input.empty()) { diff --git a/mediapipe/util/tracking/flow_packager.cc b/mediapipe/util/tracking/flow_packager.cc index 8f990cd05..1f3588609 100644 --- a/mediapipe/util/tracking/flow_packager.cc +++ b/mediapipe/util/tracking/flow_packager.cc @@ -20,6 +20,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" @@ -37,8 +38,8 @@ namespace mediapipe { FlowPackager::FlowPackager(const FlowPackagerOptions& options) : options_(options) { if (options_.binary_tracking_data_support()) { - CHECK_LE(options.domain_width(), 256); - CHECK_LE(options.domain_height(), 256); + ABSL_CHECK_LE(options.domain_width(), 256); + ABSL_CHECK_LE(options.domain_height(), 256); } } @@ -106,7 +107,7 @@ inline std::string EncodeVectorToString(const std::vector& vec) { template inline bool DecodeFromStringView(absl::string_view str, T* result) { - CHECK(result != nullptr); + ABSL_CHECK(result != nullptr); if (sizeof(*result) != str.size()) { return false; } @@ -117,7 +118,7 @@ inline bool DecodeFromStringView(absl::string_view str, T* result) { template inline bool DecodeVectorFromStringView(absl::string_view str, std::vector* result) { - CHECK(result != nullptr); + ABSL_CHECK(result != nullptr); if (str.size() % sizeof(T) != 0) return false; result->clear(); result->reserve(str.size() / sizeof(T)); @@ -135,9 +136,9 @@ inline bool DecodeVectorFromStringView(absl::string_view str, void FlowPackager::PackFlow(const RegionFlowFeatureList& feature_list, const CameraMotion* camera_motion, TrackingData* tracking_data) const { - CHECK(tracking_data); - CHECK_GT(feature_list.frame_width(), 0); - CHECK_GT(feature_list.frame_height(), 0); + ABSL_CHECK(tracking_data); + ABSL_CHECK_GT(feature_list.frame_width(), 0); + ABSL_CHECK_GT(feature_list.frame_height(), 0); // Scale flow to output domain. const float dim_x_scale = @@ -232,12 +233,12 @@ void FlowPackager::PackFlow(const RegionFlowFeatureList& feature_list, const int curr_col = loc.x(); if (curr_col != last_col) { - CHECK_LT(last_col, curr_col); - CHECK_EQ(-1, col_start[curr_col]); + ABSL_CHECK_LT(last_col, curr_col); + ABSL_CHECK_EQ(-1, col_start[curr_col]); col_start[curr_col] = data->row_indices_size() - 1; last_col = curr_col; } else { - CHECK_LE(last_row, loc.y()); + ABSL_CHECK_LE(last_row, loc.y()); } last_row = loc.y(); } @@ -248,7 +249,7 @@ void FlowPackager::PackFlow(const RegionFlowFeatureList& feature_list, // Fill unset values with previously set value. Propagate end value. for (int i = options_.domain_width() - 1; i > 0; --i) { if (col_start[i] < 0) { - DCHECK_GE(col_start[i + 1], 0); + ABSL_DCHECK_GE(col_start[i + 1], 0); col_start[i] = col_start[i + 1]; } } @@ -262,11 +263,11 @@ void FlowPackager::PackFlow(const RegionFlowFeatureList& feature_list, const int r_start = data->col_starts(c); const int r_end = data->col_starts(c + 1); for (int r = r_start; r < r_end - 1; ++r) { - CHECK_LE(data->row_indices(r), data->row_indices(r + 1)); + ABSL_CHECK_LE(data->row_indices(r), data->row_indices(r + 1)); } } - CHECK_EQ(data->vector_data_size(), 2 * data->row_indices_size()); + ABSL_CHECK_EQ(data->vector_data_size(), 2 * data->row_indices_size()); *data->mutable_actively_discarded_tracked_ids() = feature_list.actively_discarded_tracked_ids(); @@ -274,8 +275,8 @@ void FlowPackager::PackFlow(const RegionFlowFeatureList& feature_list, void FlowPackager::EncodeTrackingData(const TrackingData& tracking_data, BinaryTrackingData* binary_data) const { - CHECK(options_.binary_tracking_data_support()); - CHECK(binary_data != nullptr); + ABSL_CHECK(options_.binary_tracking_data_support()); + ABSL_CHECK(binary_data != nullptr); int32_t frame_flags = 0; const bool high_profile = options_.use_high_profile(); @@ -314,7 +315,7 @@ void FlowPackager::EncodeTrackingData(const TrackingData& tracking_data, const int32_t domain_width = tracking_data.domain_width(); const int32_t domain_height = tracking_data.domain_height(); - CHECK_LT(domain_height, 256) << "Only heights below 256 are supported."; + ABSL_CHECK_LT(domain_height, 256) << "Only heights below 256 are supported."; const float frame_aspect = tracking_data.frame_aspect(); // Limit vector value from above (to 20% frame diameter) and below (small @@ -394,7 +395,7 @@ void FlowPackager::EncodeTrackingData(const TrackingData& tracking_data, flow_compressed_8.push_back(flow_y); } - DCHECK_LT(motion_data.row_indices(r), 256); + ABSL_DCHECK_LT(motion_data.row_indices(r), 256); row_idx.push_back(motion_data.row_indices(r)); } } @@ -471,7 +472,7 @@ void FlowPackager::EncodeTrackingData(const TrackingData& tracking_data, // Delta compress. int delta_row = motion_data.row_indices(r) - (r == r_start ? 0 : motion_data.row_indices(r - 1)); - CHECK_GE(delta_row, 0); + ABSL_CHECK_GE(delta_row, 0); bool combined = false; if (r > r_start) { @@ -521,9 +522,9 @@ void FlowPackager::EncodeTrackingData(const TrackingData& tracking_data, } if (options_.high_fidelity_16bit_encode()) { - CHECK_EQ(2 * encoded, flow_compressed_16.size()); + ABSL_CHECK_EQ(2 * encoded, flow_compressed_16.size()); } else { - CHECK_EQ(2 * encoded, flow_compressed_8.size()); + ABSL_CHECK_EQ(2 * encoded, flow_compressed_8.size()); } // Adjust column start by compressions. @@ -531,11 +532,11 @@ void FlowPackager::EncodeTrackingData(const TrackingData& tracking_data, for (int k = 0; k < domain_width; ++k) { curr_adjust -= compressions_per_column[k]; col_starts[k + 1] += curr_adjust; - CHECK_LE(col_starts[k], col_starts[k + 1]); + ABSL_CHECK_LE(col_starts[k], col_starts[k + 1]); } - CHECK_EQ(row_idx.size(), col_starts.back()); - CHECK_EQ(num_vectors, row_idx.size() + compressible); + ABSL_CHECK_EQ(row_idx.size(), col_starts.back()); + ABSL_CHECK_EQ(num_vectors, row_idx.size() + compressible); } // Delta compress col_starts. @@ -543,7 +544,7 @@ void FlowPackager::EncodeTrackingData(const TrackingData& tracking_data, col_start_delta[0] = col_starts[0]; for (int k = 1; k < domain_width + 1; ++k) { const int delta = col_starts[k] - col_starts[k - 1]; - CHECK_LT(delta, 256) << "Only up to 255 items per column supported."; + ABSL_CHECK_LT(delta, 256) << "Only up to 255 items per column supported."; col_start_delta[k] = delta; } @@ -603,7 +604,7 @@ std::string PopSubstring(int len, absl::string_view* piece) { void FlowPackager::DecodeTrackingData(const BinaryTrackingData& container_data, TrackingData* tracking_data) const { - CHECK(tracking_data != nullptr); + ABSL_CHECK(tracking_data != nullptr); absl::string_view data(container_data.data()); int32_t frame_flags = 0; @@ -619,8 +620,8 @@ void FlowPackager::DecodeTrackingData(const BinaryTrackingData& container_data, DecodeFromStringView(PopSubstring(4, &data), &domain_height); DecodeFromStringView(PopSubstring(4, &data), &frame_aspect); - CHECK_LE(domain_width, 256); - CHECK_LE(domain_height, 256); + ABSL_CHECK_LE(domain_width, 256); + ABSL_CHECK_LE(domain_height, 256); DecodeVectorFromStringView( PopSubstring(4 * HomographyAdapter::NumParameters(), &data), @@ -663,7 +664,7 @@ void FlowPackager::DecodeTrackingData(const BinaryTrackingData& container_data, // Should not have more row indices than vectors. (One for each in baseline // profile, less in high profile). - CHECK_LE(row_idx_size, num_vectors); + ABSL_CHECK_LE(row_idx_size, num_vectors); DecodeVectorFromStringView(PopSubstring(row_idx_size, &data), &row_idx); // Records for each vector whether to advance pointer in the vector data array @@ -708,7 +709,7 @@ void FlowPackager::DecodeTrackingData(const BinaryTrackingData& container_data, } } row_idx.swap(row_idx_unpacked); - CHECK_EQ(num_vectors, row_idx.size()); + ABSL_CHECK_EQ(num_vectors, row_idx.size()); // Adjust column start by expansions. int curr_adjust = 0; @@ -718,7 +719,7 @@ void FlowPackager::DecodeTrackingData(const BinaryTrackingData& container_data, } } - CHECK_EQ(num_vectors, col_starts.back()); + ABSL_CHECK_EQ(num_vectors, col_starts.back()); int vector_data_size; DecodeFromStringView(PopSubstring(4, &data), &vector_data_size); @@ -750,7 +751,7 @@ void FlowPackager::DecodeTrackingData(const BinaryTrackingData& container_data, motion_data->add_vector_data(prev_flow_y * flow_denom); } } - CHECK_EQ(vector_data_size, counter); + ABSL_CHECK_EQ(vector_data_size, counter); } else { std::vector vector_data; DecodeVectorFromStringView( @@ -776,7 +777,7 @@ void FlowPackager::DecodeTrackingData(const BinaryTrackingData& container_data, motion_data->add_vector_data(prev_flow_y * flow_denom); } } - CHECK_EQ(vector_data_size, counter); + ABSL_CHECK_EQ(vector_data_size, counter); } for (auto idx : row_idx) { @@ -790,7 +791,7 @@ void FlowPackager::DecodeTrackingData(const BinaryTrackingData& container_data, void FlowPackager::BinaryTrackingDataToContainer( const BinaryTrackingData& binary_data, TrackingContainer* container) const { - CHECK(container != nullptr); + ABSL_CHECK(container != nullptr); container->Clear(); container->set_header("TRAK"); container->set_version(1); @@ -800,17 +801,17 @@ void FlowPackager::BinaryTrackingDataToContainer( void FlowPackager::BinaryTrackingDataFromContainer( const TrackingContainer& container, BinaryTrackingData* binary_data) const { - CHECK_EQ("TRAK", container.header()); - CHECK_EQ(1, container.version()) << "Unsupported version."; + ABSL_CHECK_EQ("TRAK", container.header()); + ABSL_CHECK_EQ(1, container.version()) << "Unsupported version."; *binary_data->mutable_data() = container.data(); } void FlowPackager::DecodeMetaData(const TrackingContainer& container_data, MetaData* meta_data) const { - CHECK(meta_data != nullptr); + ABSL_CHECK(meta_data != nullptr); - CHECK_EQ("META", container_data.header()); - CHECK_EQ(1, container_data.version()) << "Unsupported version."; + ABSL_CHECK_EQ("META", container_data.header()); + ABSL_CHECK_EQ(1, container_data.version()) << "Unsupported version."; absl::string_view data(container_data.data()); @@ -834,14 +835,14 @@ void FlowPackager::DecodeMetaData(const TrackingContainer& container_data, void FlowPackager::FinalizeTrackingContainerFormat( std::vector* timestamps, TrackingContainerFormat* container_format) { - CHECK(container_format != nullptr); + ABSL_CHECK(container_format != nullptr); // Compute binary sizes of track_data. const int num_frames = container_format->track_data_size(); std::vector msecs(num_frames, 0); if (timestamps) { - CHECK_EQ(num_frames, timestamps->size()); + ABSL_CHECK_EQ(num_frames, timestamps->size()); msecs = *timestamps; } std::vector sizes(num_frames, 0); @@ -878,14 +879,14 @@ void FlowPackager::FinalizeTrackingContainerFormat( void FlowPackager::FinalizeTrackingContainerProto( std::vector* timestamps, TrackingContainerProto* proto) { - CHECK(proto != nullptr); + ABSL_CHECK(proto != nullptr); // Compute binary sizes of track_data. const int num_frames = proto->track_data_size(); std::vector msecs(num_frames, 0); if (timestamps) { - CHECK_EQ(num_frames, timestamps->size()); + ABSL_CHECK_EQ(num_frames, timestamps->size()); msecs = *timestamps; } @@ -910,8 +911,8 @@ void FlowPackager::InitializeMetaData(int num_frames, const std::vector& data_sizes, MetaData* meta_data) const { meta_data->set_num_frames(num_frames); - CHECK_EQ(num_frames, msecs.size()); - CHECK_EQ(num_frames, data_sizes.size()); + ABSL_CHECK_EQ(num_frames, msecs.size()); + ABSL_CHECK_EQ(num_frames, data_sizes.size()); int curr_offset = 0; for (int f = 0; f < num_frames; ++f) { @@ -924,9 +925,9 @@ void FlowPackager::InitializeMetaData(int num_frames, void FlowPackager::AddContainerToString(const TrackingContainer& container, std::string* binary_data) { - CHECK(binary_data != nullptr); + ABSL_CHECK(binary_data != nullptr); std::string header_string(container.header()); - CHECK_EQ(4, header_string.size()); + ABSL_CHECK_EQ(4, header_string.size()); std::vector header{header_string[0], header_string[1], header_string[2], header_string[3]}; @@ -937,10 +938,10 @@ void FlowPackager::AddContainerToString(const TrackingContainer& container, std::string FlowPackager::SplitContainerFromString( absl::string_view* binary_data, TrackingContainer* container) { - CHECK(binary_data != nullptr); - CHECK(container != nullptr); - CHECK_GE(binary_data->size(), 12) << "Data does not contain " - << "valid container"; + ABSL_CHECK(binary_data != nullptr); + ABSL_CHECK(container != nullptr); + ABSL_CHECK_GE(binary_data->size(), 12) << "Data does not contain " + << "valid container"; container->set_header(PopSubstring(4, binary_data)); @@ -962,7 +963,7 @@ std::string FlowPackager::SplitContainerFromString( void FlowPackager::TrackingContainerFormatToBinary( const TrackingContainerFormat& container_format, std::string* binary) { - CHECK(binary != nullptr); + ABSL_CHECK(binary != nullptr); binary->clear(); AddContainerToString(container_format.meta_data(), binary); @@ -975,28 +976,28 @@ void FlowPackager::TrackingContainerFormatToBinary( void FlowPackager::TrackingContainerFormatFromBinary( const std::string& binary, TrackingContainerFormat* container_format) { - CHECK(container_format != nullptr); + ABSL_CHECK(container_format != nullptr); container_format->Clear(); absl::string_view data(binary); - CHECK_EQ("META", SplitContainerFromString( - &data, container_format->mutable_meta_data())); + ABSL_CHECK_EQ("META", SplitContainerFromString( + &data, container_format->mutable_meta_data())); MetaData meta_data; DecodeMetaData(container_format->meta_data(), &meta_data); for (int f = 0; f < meta_data.num_frames(); ++f) { TrackingContainer* container = container_format->add_track_data(); - CHECK_EQ("TRAK", SplitContainerFromString(&data, container)); + ABSL_CHECK_EQ("TRAK", SplitContainerFromString(&data, container)); } - CHECK_EQ("TERM", SplitContainerFromString( - &data, container_format->mutable_term_data())); + ABSL_CHECK_EQ("TERM", SplitContainerFromString( + &data, container_format->mutable_term_data())); } void FlowPackager::SortRegionFlowFeatureList( float scale_x, float scale_y, RegionFlowFeatureList* feature_list) const { - CHECK(feature_list != nullptr); + ABSL_CHECK(feature_list != nullptr); // Sort features lexicographically. std::sort(feature_list->mutable_feature()->begin(), feature_list->mutable_feature()->end(), diff --git a/mediapipe/util/tracking/image_util.cc b/mediapipe/util/tracking/image_util.cc index 391ba15e1..d376ca308 100644 --- a/mediapipe/util/tracking/image_util.cc +++ b/mediapipe/util/tracking/image_util.cc @@ -17,6 +17,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "mediapipe/util/tracking/motion_models.h" #include "mediapipe/util/tracking/region_flow.h" @@ -25,8 +26,8 @@ namespace mediapipe { // Returns median of the L1 color distance between img_1 and img_2 float FrameDifferenceMedian(const cv::Mat& img_1, const cv::Mat& img_2) { - CHECK(img_1.size() == img_2.size()); - CHECK_EQ(img_1.channels(), img_2.channels()); + ABSL_CHECK(img_1.size() == img_2.size()); + ABSL_CHECK_EQ(img_1.channels(), img_2.channels()); std::vector color_diffs; color_diffs.reserve(img_1.cols * img_1.rows); @@ -52,7 +53,7 @@ float FrameDifferenceMedian(const cv::Mat& img_1, const cv::Mat& img_2) { } void JetColoring(int steps, std::vector* color_map) { - CHECK(color_map != nullptr); + ABSL_CHECK(color_map != nullptr); color_map->resize(steps); for (int i = 0; i < steps; ++i) { const float frac = 2.0f * (i * (1.0f / steps) - 0.5f); diff --git a/mediapipe/util/tracking/image_util.h b/mediapipe/util/tracking/image_util.h index ba58d343b..f1e7eda36 100644 --- a/mediapipe/util/tracking/image_util.h +++ b/mediapipe/util/tracking/image_util.h @@ -17,6 +17,7 @@ #include +#include "absl/log/absl_check.h" #include "mediapipe/framework/port/opencv_core_inc.h" #include "mediapipe/framework/port/opencv_imgproc_inc.h" #include "mediapipe/framework/port/vector.h" @@ -75,7 +76,7 @@ void CopyMatBorder(cv::Mat* mat) { } // src and dst should point to same column from here. - DCHECK_EQ(0, (src_ptr - dst_ptr) * sizeof(T) % mat->step[0]); + ABSL_DCHECK_EQ(0, (src_ptr - dst_ptr) * sizeof(T) % mat->step[0]); // Top row copy. memcpy(dst_ptr, src_ptr, width * channels * sizeof(dst_ptr[0])); @@ -122,7 +123,7 @@ void CopyMatBorder(cv::Mat* mat) { } // src and dst should point to same column from here. - DCHECK_EQ(0, (dst_ptr - src_ptr) * sizeof(T) % mat->step[0]); + ABSL_DCHECK_EQ(0, (dst_ptr - src_ptr) * sizeof(T) % mat->step[0]); memcpy(dst_ptr, src_ptr, width * channels * sizeof(dst_ptr[0])); src_ptr += width * channels; // Points one behind the end. dst_ptr += width * channels; diff --git a/mediapipe/util/tracking/measure_time.h b/mediapipe/util/tracking/measure_time.h index 7890da7e9..20b859b42 100644 --- a/mediapipe/util/tracking/measure_time.h +++ b/mediapipe/util/tracking/measure_time.h @@ -31,8 +31,8 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" -#include "absl/log/check.h" #include "absl/strings/str_split.h" #include "absl/strings/string_view.h" #include "absl/synchronization/mutex.h" @@ -102,7 +102,7 @@ class ScopedWallTimer { show_output_(show_output), accumulator_(accumulator) { if (show_output_) { - CHECK(accumulator_); + ABSL_CHECK(accumulator_); start_time_ = GetWallTime(); } } diff --git a/mediapipe/util/tracking/motion_analysis.cc b/mediapipe/util/tracking/motion_analysis.cc index 67baa602f..6d35a3e38 100644 --- a/mediapipe/util/tracking/motion_analysis.cc +++ b/mediapipe/util/tracking/motion_analysis.cc @@ -20,6 +20,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/strings/str_format.h" #include "mediapipe/framework/port/integral_types.h" @@ -92,8 +93,8 @@ MotionAnalysis::MotionAnalysis(const MotionAnalysisOptions& options, use_spatial_bias; if (compute_feature_descriptors_) { - CHECK_EQ(RegionFlowComputationOptions::FORMAT_RGB, - options_.flow_options().image_format()) + ABSL_CHECK_EQ(RegionFlowComputationOptions::FORMAT_RGB, + options_.flow_options().image_format()) << "Feature descriptors only support RGB currently."; prev_frame_.reset(new cv::Mat(frame_height_, frame_width_, CV_8UC3)); } @@ -362,8 +363,8 @@ bool MotionAnalysis::AddFrameGeneric( RegionFlowFeatureList* output_feature_list) { // Don't check input sizes here, RegionFlowComputation does that based // on its internal options. - CHECK(feature_computation_) << "Calls to AddFrame* can NOT be mixed " - << "with AddFeatures"; + ABSL_CHECK(feature_computation_) << "Calls to AddFrame* can NOT be mixed " + << "with AddFeatures"; // Compute RegionFlow. { @@ -461,7 +462,7 @@ void MotionAnalysis::AddFeatures(const RegionFlowFeatureList& features) { void MotionAnalysis::EnqueueFeaturesAndMotions( const RegionFlowFeatureList& features, const CameraMotion& motion) { feature_computation_ = false; - CHECK(buffer_->HaveEqualSize({"motion", "features"})) + ABSL_CHECK(buffer_->HaveEqualSize({"motion", "features"})) << "Can not be mixed with other Add* calls"; buffer_->EmplaceDatum("features", new RegionFlowFeatureList(features)); buffer_->EmplaceDatum("motion", new CameraMotion(motion)); @@ -479,7 +480,7 @@ int MotionAnalysis::GetResults( const int num_features_lists = buffer_->BufferSize("features"); const int num_new_feature_lists = num_features_lists - overlap_start_; - CHECK_GE(num_new_feature_lists, 0); + ABSL_CHECK_GE(num_new_feature_lists, 0); if (!flush && num_new_feature_lists < options_.estimation_clip_size()) { // Nothing to compute, return. @@ -487,7 +488,7 @@ int MotionAnalysis::GetResults( } const bool compute_saliency = options_.compute_motion_saliency(); - CHECK_EQ(compute_saliency, saliency != nullptr) + ABSL_CHECK_EQ(compute_saliency, saliency != nullptr) << "Computing saliency requires saliency output and vice versa"; // Estimate motions for newly buffered RegionFlowFeatureLists, which also @@ -514,7 +515,7 @@ int MotionAnalysis::GetResults( } } - CHECK(buffer_->HaveEqualSize({"features", "motion"})); + ABSL_CHECK(buffer_->HaveEqualSize({"features", "motion"})); if (compute_saliency) { ComputeSaliency(); @@ -528,9 +529,9 @@ int MotionAnalysis::OutputResults( std::vector>* camera_motion, std::vector>* saliency) { const bool compute_saliency = options_.compute_motion_saliency(); - CHECK_EQ(compute_saliency, saliency != nullptr) + ABSL_CHECK_EQ(compute_saliency, saliency != nullptr) << "Computing saliency requires saliency output and vice versa"; - CHECK(buffer_->HaveEqualSize({"features", "motion"})); + ABSL_CHECK(buffer_->HaveEqualSize({"features", "motion"})); // Discard prev. overlap (already output, just used for filtering here). buffer_->DiscardData(buffer_->AllTags(), prev_overlap_start_); @@ -598,9 +599,9 @@ int MotionAnalysis::OutputResults( // Reset for next chunk. prev_overlap_start_ = num_output_frames - new_overlap_start; - CHECK_GE(prev_overlap_start_, 0); + ABSL_CHECK_GE(prev_overlap_start_, 0); - CHECK(buffer_->TruncateBuffer(flush)); + ABSL_CHECK(buffer_->TruncateBuffer(flush)); overlap_start_ = buffer_->MaxBufferSize(); return num_output_frames; @@ -611,9 +612,9 @@ void MotionAnalysis::RenderResults(const RegionFlowFeatureList& feature_list, const SalientPointFrame* saliency, cv::Mat* rendered_results) { #ifndef NO_RENDERING - CHECK(rendered_results != nullptr); - CHECK_EQ(frame_width_, rendered_results->cols); - CHECK_EQ(frame_height_, rendered_results->rows); + ABSL_CHECK(rendered_results != nullptr); + ABSL_CHECK_EQ(frame_width_, rendered_results->cols); + ABSL_CHECK_EQ(frame_height_, rendered_results->rows); const auto viz_options = options_.visualization_options(); @@ -698,10 +699,10 @@ void MotionAnalysis::ComputeDenseForeground( &foreground_weights); // Setup push pull map (with border). Ensure constructor used the right type. - CHECK(foreground_push_pull_->filter_type() == - PushPullFilteringC1::BINOMIAL_5X5 || - foreground_push_pull_->filter_type() == - PushPullFilteringC1::GAUSSIAN_5X5); + ABSL_CHECK(foreground_push_pull_->filter_type() == + PushPullFilteringC1::BINOMIAL_5X5 || + foreground_push_pull_->filter_type() == + PushPullFilteringC1::GAUSSIAN_5X5); cv::Mat foreground_map(frame_height_ + 4, frame_width_ + 4, CV_32FC2); std::vector feature_locations; @@ -741,8 +742,8 @@ void MotionAnalysis::ComputeDenseForeground( void MotionAnalysis::VisualizeDenseForeground(const cv::Mat& foreground_mask, cv::Mat* output) { - CHECK(output != nullptr); - CHECK(foreground_mask.size() == output->size()); + ABSL_CHECK(output != nullptr); + ABSL_CHECK(foreground_mask.size() == output->size()); // Map foreground measure to color (green by default). std::vector color_map; if (options_.visualization_options().foreground_jet_coloring()) { @@ -780,7 +781,7 @@ void MotionAnalysis::VisualizeDenseForeground(const cv::Mat& foreground_mask, } void MotionAnalysis::VisualizeBlurAnalysisRegions(cv::Mat* input_view) { - CHECK(input_view != nullptr); + ABSL_CHECK(input_view != nullptr); cv::Mat intensity; cv::cvtColor(*input_view, intensity, cv::COLOR_RGB2GRAY); @@ -797,7 +798,7 @@ void MotionAnalysis::VisualizeBlurAnalysisRegions(cv::Mat* input_view) { void MotionAnalysis::ComputeSaliency() { MEASURE_TIME << "Saliency computation."; - CHECK_EQ(overlap_start_, buffer_->BufferSize("saliency")); + ABSL_CHECK_EQ(overlap_start_, buffer_->BufferSize("saliency")); const int num_features_lists = buffer_->BufferSize("features"); @@ -821,7 +822,7 @@ void MotionAnalysis::ComputeSaliency() { buffer_->AddDatum("saliency", std::move(saliency)); } - CHECK(buffer_->HaveEqualSize({"features", "motion", "saliency"})); + ABSL_CHECK(buffer_->HaveEqualSize({"features", "motion", "saliency"})); // Clear output saliency and copy from saliency. buffer_->DiscardDatum("output_saliency", diff --git a/mediapipe/util/tracking/motion_estimation.cc b/mediapipe/util/tracking/motion_estimation.cc index 07515cbc5..4406359a6 100644 --- a/mediapipe/util/tracking/motion_estimation.cc +++ b/mediapipe/util/tracking/motion_estimation.cc @@ -31,6 +31,7 @@ #include "Eigen/SVD" #include "absl/container/node_hash_map.h" #include "absl/container/node_hash_set.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/strings/str_cat.h" #include "mediapipe/util/tracking/camera_motion.h" @@ -173,9 +174,9 @@ class InlierMask { // estimated translation. void MotionPrior(const RegionFlowFeatureList& feature_list, std::vector* motion_prior) { - CHECK(motion_prior != nullptr); + ABSL_CHECK(motion_prior != nullptr); const int num_features = feature_list.feature_size(); - CHECK_EQ(num_features, motion_prior->size()); + ABSL_CHECK_EQ(num_features, motion_prior->size()); // Return, if prior is too low. const float kMinTranslationPrior = 0.5f; @@ -185,7 +186,7 @@ class InlierMask { } const float prev_magnitude = translation_.Norm(); - CHECK_EQ(num_features, motion_prior->size()); + ABSL_CHECK_EQ(num_features, motion_prior->size()); const float inv_prev_magnitude = prev_magnitude < options_.min_translation_norm() ? (1.0f / options_.min_translation_norm()) @@ -350,7 +351,7 @@ struct MotionEstimation::SingleTrackClipData { // feature's irls weight. If weight_backup is set, allocates storage // to backup and reset irls weights. void AllocateIRLSWeightStorage(bool weight_backup) { - CHECK(feature_lists != nullptr); + ABSL_CHECK(feature_lists != nullptr); const int num_frames = feature_lists->size(); if (weight_backup) { irls_weight_backup = &irls_backup_storage; @@ -380,7 +381,7 @@ struct MotionEstimation::SingleTrackClipData { // Returns number of frames in this clip. int num_frames() const { - DCHECK(feature_lists); + ABSL_DCHECK(feature_lists); return feature_lists->size(); } @@ -396,23 +397,23 @@ struct MotionEstimation::SingleTrackClipData { // Checks that SingleTrackClipData is properly initialized. void CheckInitialization() const { - CHECK(feature_lists != nullptr); - CHECK(camera_motions != nullptr); - CHECK_EQ(feature_lists->size(), camera_motions->size()); + ABSL_CHECK(feature_lists != nullptr); + ABSL_CHECK(camera_motions != nullptr); + ABSL_CHECK_EQ(feature_lists->size(), camera_motions->size()); if (feature_lists->empty()) { return; } - CHECK_EQ(num_frames(), irls_weight_input.size()); - CHECK_EQ(num_frames(), homog_irls_weight_input.size()); + ABSL_CHECK_EQ(num_frames(), irls_weight_input.size()); + ABSL_CHECK_EQ(num_frames(), homog_irls_weight_input.size()); if (irls_weight_backup) { - CHECK_EQ(num_frames(), irls_weight_backup->size()); + ABSL_CHECK_EQ(num_frames(), irls_weight_backup->size()); } for (int k = 0; k < num_frames(); ++k) { const int num_features = (*feature_lists)[k]->feature_size(); - CHECK_EQ(num_features, irls_weight_input[k].size()); - CHECK_EQ(num_features, homog_irls_weight_input[k].size()); + ABSL_CHECK_EQ(num_features, irls_weight_input[k].size()); + ABSL_CHECK_EQ(num_features, homog_irls_weight_input[k].size()); } } @@ -502,15 +503,15 @@ void MotionEstimation::InitializeWithOptions( } // Check for deprecated options. - CHECK_NE(options.estimate_similarity(), true) + ABSL_CHECK_NE(options.estimate_similarity(), true) << "Option estimate_similarity is deprecated, use static function " << "EstimateSimilarityModelL2 instead."; - CHECK_NE(options.linear_similarity_estimation(), - MotionEstimationOptions::ESTIMATION_LS_L2_RANSAC) + ABSL_CHECK_NE(options.linear_similarity_estimation(), + MotionEstimationOptions::ESTIMATION_LS_L2_RANSAC) << "Option ESTIMATION_LS_L2_RANSAC is deprecated, use " << "ESTIMATION_LS_IRLS instead."; - CHECK_NE(options.linear_similarity_estimation(), - MotionEstimationOptions::ESTIMATION_LS_L1) + ABSL_CHECK_NE(options.linear_similarity_estimation(), + MotionEstimationOptions::ESTIMATION_LS_L1) << "Option ESTIMATION_LS_L1 is deprecated, use static function " << "EstimateLinearSimilarityL1 instead."; @@ -565,7 +566,7 @@ void MotionEstimation::InitializeWithOptions( } case MotionEstimationOptions::TEMPORAL_IRLS_MASK: - CHECK(options.irls_initialization().activated()) + ABSL_CHECK(options.irls_initialization().activated()) << "To use dependent_initialization, irls_initialization has to " << "be activated. "; inlier_mask_.reset(new InlierMask(options.irls_mask_options(), @@ -580,11 +581,11 @@ void MotionEstimation::EstimateMotion(const RegionFlowFrame& region_flow_frame, const int* intensity_frame, // null const int* prev_intensity_frame, // null CameraMotion* camera_motion) const { - CHECK(camera_motion); + ABSL_CHECK(camera_motion); - CHECK(intensity_frame == NULL) + ABSL_CHECK(intensity_frame == NULL) << "Parameter intensity_frame is deprecated, must be NULL."; - CHECK(prev_intensity_frame == NULL) + ABSL_CHECK(prev_intensity_frame == NULL) << "Parameter prev_intensity_frame is deprecated, must be NULL."; RegionFlowFeatureList feature_list; @@ -823,11 +824,11 @@ void MotionEstimation::EstimateMotionsParallelImpl( std::vector* camera_motions) const { MEASURE_TIME << "Estimate motions: " << feature_lists->size(); - CHECK(feature_lists != nullptr); - CHECK(camera_motions != nullptr); + ABSL_CHECK(feature_lists != nullptr); + ABSL_CHECK(camera_motions != nullptr); const int num_frames = feature_lists->size(); - CHECK_EQ(num_frames, camera_motions->size()); + ABSL_CHECK_EQ(num_frames, camera_motions->size()); // Initialize camera_motions. for (int f = 0; f < num_frames; ++f) { @@ -868,7 +869,7 @@ void MotionEstimation::EstimateMotionsParallelImpl( const int num_motion_models = use_joint_tracks ? options_.joint_track_estimation().num_motion_models() : 1; - CHECK_GT(num_motion_models, 0); + ABSL_CHECK_GT(num_motion_models, 0); // Several single track clip datas, we seek to process. std::vector clip_datas(num_motion_models); @@ -1082,7 +1083,8 @@ void MotionEstimation::EstimateMotionsParallelImpl( // Estimate mixtures across a spectrum a different regularizers, from the // weakest to the most regularized one. const int num_mixture_levels = options_.mixture_regularizer_levels(); - CHECK_LE(num_mixture_levels, 10) << "Only up to 10 mixtures are supported."; + ABSL_CHECK_LE(num_mixture_levels, 10) + << "Only up to 10 mixtures are supported."; // Initialize to weakest regularizer. float regularizer = options_.mixture_regularizer(); @@ -1126,8 +1128,8 @@ void MotionEstimation::EstimateMotionsParallelImpl( // Check that mixture spectrum has sufficient entries. for (const CameraMotion& motion : *camera_motions) { if (motion.mixture_homography_spectrum_size() > 0) { - CHECK_EQ(motion.mixture_homography_spectrum_size(), - options_.mixture_regularizer_levels()); + ABSL_CHECK_EQ(motion.mixture_homography_spectrum_size(), + options_.mixture_regularizer_levels()); } } @@ -1166,7 +1168,7 @@ bool MotionEstimation::EstimateMotionModels( const EstimateModelOptions& model_options, const MotionEstimationThreadStorage* thread_storage, std::vector* clip_datas) const { - CHECK(clip_datas != nullptr); + ABSL_CHECK(clip_datas != nullptr); const int num_datas = clip_datas->size(); if (num_datas == 0) { @@ -1268,7 +1270,7 @@ bool MotionEstimation::EstimateMotionModels( // Traverse frames in order. for (int k = 0; k < clip_data.num_frames(); ++k) { if (clip_data.feature_lists->at(k)->feature_size() > 0) { - CHECK(clip_data.feature_lists->at(k)->long_tracks()) + ABSL_CHECK(clip_data.feature_lists->at(k)->long_tracks()) << "Estimation policy TEMPORAL_LONG_FEATURE_BIAS requires " << "tracking with long tracks."; } @@ -1283,7 +1285,7 @@ bool MotionEstimation::EstimateMotionModels( } if (clip_data.camera_motions->at(k).type() <= max_unstable_type) { - CHECK(clip_data.prior_weights[k].use_full_prior); + ABSL_CHECK(clip_data.prior_weights[k].use_full_prior); clip_data.prior_weights[k].alphas.assign(irls_per_round, 1.0f); clip_data.prior_weights[k].alphas.back() = 0.0; } @@ -1572,7 +1574,7 @@ class IrlsInitializationInvoker { // Initialize priors from irls weights. if (use_prior_weights) { - CHECK_LT(frame, clip_data_->prior_weights.size()); + ABSL_CHECK_LT(frame, clip_data_->prior_weights.size()); if (clip_data_->prior_weights[frame].priors.empty()) { clip_data_->prior_weights[frame].priors.resize( @@ -1606,13 +1608,13 @@ void MotionEstimation::LongFeatureInitialization( const LongFeatureInfo& feature_info, const std::vector& track_length_importance, std::vector* irls_weights) const { - CHECK(irls_weights); + ABSL_CHECK(irls_weights); const int num_features = feature_list.feature_size(); if (num_features == 0) { return; } - CHECK_EQ(num_features, irls_weights->size()); + ABSL_CHECK_EQ(num_features, irls_weights->size()); // Determine actual scale to be applied to each feature. std::vector feature_scales(num_features); @@ -1644,9 +1646,9 @@ void MotionEstimation::LongFeatureInitialization( void MotionEstimation::FeatureDensityNormalization( const RegionFlowFeatureList& feature_list, std::vector* irls_weights) const { - CHECK(irls_weights); + ABSL_CHECK(irls_weights); const int num_features = feature_list.feature_size(); - CHECK_EQ(num_features, irls_weights->size()); + ABSL_CHECK_EQ(num_features, irls_weights->size()); // Compute mask index for each feature. std::vector bin_indices; @@ -1709,13 +1711,13 @@ void MotionEstimation::FeatureDensityNormalization( float normalizer = 0; int bin_idx = int_grid_y * mask_size + int_grid_x; - CHECK_LT(bin_idx, max_bins); + ABSL_CHECK_LT(bin_idx, max_bins); // See above. normalizer += bin_normalizer[bin_idx] * (1 - dx_plus_dy + dxdy); normalizer += bin_normalizer[bin_idx + inc_x] * (dx - dxdy); bin_idx += mask_size * inc_y; - CHECK_LT(bin_idx, max_bins); + ABSL_CHECK_LT(bin_idx, max_bins); normalizer += bin_normalizer[bin_idx] * (dy - dxdy); normalizer += bin_normalizer[bin_idx + inc_x] * dxdy; @@ -1740,8 +1742,8 @@ void MotionEstimation::IrlsInitialization( SingleTrackClipData* clip_data) const { if (options_.estimation_policy() == MotionEstimationOptions::TEMPORAL_LONG_FEATURE_BIAS) { - CHECK_NE(frame, -1) << "Only per frame processing for this policy " - << "supported."; + ABSL_CHECK_NE(frame, -1) << "Only per frame processing for this policy " + << "supported."; } IrlsInitializationInvoker invoker(type, max_unstable_type, model_options, @@ -1765,8 +1767,8 @@ void MotionEstimation::IrlsInitialization( for_function(0, clip_data->num_frames(), 1, invoker); } else { - CHECK_GE(frame, 0); - CHECK_LT(frame, clip_data->num_frames()); + ABSL_CHECK_GE(frame, 0); + ABSL_CHECK_LT(frame, clip_data->num_frames()); invoker(BlockedRange(frame, frame + 1, 1)); } } @@ -1845,7 +1847,7 @@ void MotionEstimation::MinFilterIrlsWeightByTrack( void MotionEstimation::EnforceTrackConsistency( std::vector* clip_datas) const { - CHECK(clip_datas != nullptr); + ABSL_CHECK(clip_datas != nullptr); if (clip_datas->empty()) { return; } @@ -1890,7 +1892,7 @@ void MotionEstimation::EnforceTrackConsistency( void MotionEstimation::BiasFromFeatures( const RegionFlowFeatureList& feature_list, MotionType type, const EstimateModelOptions& model_options, std::vector* bias) const { - CHECK(bias); + ABSL_CHECK(bias); const int num_features = feature_list.feature_size(); bias->resize(num_features); @@ -1930,8 +1932,8 @@ void MotionEstimation::BiasLongFeatures( RegionFlowFeatureList* feature_list, MotionType type, const EstimateModelOptions& model_options, PriorFeatureWeights* prior_weights) const { - CHECK(prior_weights); - CHECK(feature_list); + ABSL_CHECK(prior_weights); + ABSL_CHECK(feature_list); // Don't bias duplicated frames -> should be identity transform. if (feature_list->is_duplicated()) { @@ -1963,7 +1965,7 @@ void MotionEstimation::BiasLongFeatures( prior_weights->priors.resize(num_features, 1.0f); } - CHECK_EQ(num_features, prior_weights->priors.size()); + ABSL_CHECK_EQ(num_features, prior_weights->priors.size()); for (int k = 0; k < num_features; ++k) { prior_weights->priors[k] *= bias[k]; auto* feature = feature_list->mutable_feature(k); @@ -1996,7 +1998,7 @@ void MotionEstimation::ComputeSpatialBias( BuildFeatureGrid(NormalizedDomain().x(), NormalizedDomain().y(), bias_options.grid_size(), {feature_view}, FeatureLocation, &feature_taps_3, nullptr, nullptr, &feature_grids); - CHECK_EQ(1, feature_grids.size()); + ABSL_CHECK_EQ(1, feature_grids.size()); const FeatureGrid& single_grid = feature_grids[0]; const float long_track_threshold = bias_options.long_track_threshold(); @@ -2062,8 +2064,8 @@ void MotionEstimation::ComputeSpatialBias( } } - DCHECK(spatial_bias->find(feature_ptr->track_id()) == - spatial_bias->end()); + ABSL_DCHECK(spatial_bias->find(feature_ptr->track_id()) == + spatial_bias->end()); // Threshold such that few similar tracks do not count. // Set to 0.25% of features. @@ -2121,7 +2123,7 @@ void MotionEstimation::UpdateLongFeatureBias( const auto& bias_options = options_.long_feature_bias_options(); const int num_irls_observations = bias_options.num_irls_observations(); - CHECK_GT(num_irls_observations, 0) << "Specify value > 0"; + ABSL_CHECK_GT(num_irls_observations, 0) << "Specify value > 0"; const float inv_num_irls_observations = 1.0f / num_irls_observations; SpatialBiasMap spatial_bias; @@ -2140,7 +2142,7 @@ void MotionEstimation::UpdateLongFeatureBias( // Scale applied to irls weight for linear interpolation between inlier and // outlier bias. - CHECK_GT(bias_options.inlier_irls_weight(), 0); + ABSL_CHECK_GT(bias_options.inlier_irls_weight(), 0); const float irls_scale = 1.0f / bias_options.inlier_irls_weight(); const float long_track_scale = 1.0f / bias_options.long_track_confidence_fraction(); @@ -2234,7 +2236,8 @@ void MotionEstimation::UpdateLongFeatureBias( // Update feature's weight as well. feature.set_irls_weight(1.0f / (biased_weight + kIrlsEps)); } else { - CHECK(!update_irls_observation) << "Should never happen on >= 2nd round"; + ABSL_CHECK(!update_irls_observation) + << "Should never happen on >= 2nd round"; // Not present, reset to spatial bias. const float biased_weight = spatial_bias[feature.track_id()].first; @@ -2259,7 +2262,7 @@ void MotionEstimation::UpdateLongFeatureBias( } void MotionEstimation::SmoothIRLSWeights(std::deque* irls) const { - CHECK(irls != nullptr); + ABSL_CHECK(irls != nullptr); if (irls->empty()) { return; } @@ -2400,8 +2403,8 @@ int MotionEstimation::IRLSRoundsFromSettings(const MotionType& type) const { void MotionEstimation::PolicyToIRLSRounds(int irls_rounds, int* total_rounds, int* irls_per_round) const { - CHECK(total_rounds != nullptr); - CHECK(irls_per_round != nullptr); + ABSL_CHECK(total_rounds != nullptr); + ABSL_CHECK(irls_per_round != nullptr); // Small optimization: irls_rounds == 0 -> total_rounds = 0 regardless of // settings. @@ -2435,13 +2438,13 @@ void MotionEstimation::CheckModelStability( const std::vector>* reset_irls_weights, std::vector* feature_lists, std::vector* camera_motions) const { - CHECK(feature_lists != nullptr); - CHECK(camera_motions != nullptr); + ABSL_CHECK(feature_lists != nullptr); + ABSL_CHECK(camera_motions != nullptr); const int num_frames = feature_lists->size(); if (reset_irls_weights) { - DCHECK_EQ(num_frames, reset_irls_weights->size()); + ABSL_DCHECK_EQ(num_frames, reset_irls_weights->size()); } - DCHECK_EQ(num_frames, camera_motions->size()); + ABSL_DCHECK_EQ(num_frames, camera_motions->size()); for (int f = 0; f < num_frames; ++f) { CameraMotion& camera_motion = (*camera_motions)[f]; @@ -2475,7 +2478,7 @@ void MotionEstimation::CheckSingleModelStability( camera_motion->translation_variance(), *feature_list)) { // Translation can never be singular. - CHECK_EQ( + ABSL_CHECK_EQ( 0, camera_motion->flags() & CameraMotion::FLAG_SINGULAR_ESTIMATION); } else { // Invalid model. @@ -2587,7 +2590,7 @@ void MotionEstimation::CheckSingleModelStability( void MotionEstimation::ProjectMotionsDown( const MotionType& type, std::vector* camera_motions) const { - CHECK(camera_motions != nullptr); + ABSL_CHECK(camera_motions != nullptr); for (auto& camera_motion : *camera_motions) { switch (type) { case MODEL_AVERAGE_MAGNITUDE: @@ -2633,7 +2636,7 @@ void MotionEstimation::ProjectMotionsDown( void MotionEstimation::IRLSWeightFilter( std::vector* feature_lists) const { - CHECK(feature_lists != nullptr); + ABSL_CHECK(feature_lists != nullptr); for (auto feature_ptr : *feature_lists) { switch (options_.irls_weight_filter()) { case MotionEstimationOptions::IRLS_FILTER_TEXTURE: @@ -2660,7 +2663,7 @@ void MotionEstimation::EstimateMotionsParallel( bool post_irls_weight_smoothing, std::vector* feature_lists, std::vector* camera_motions) const { - CHECK(camera_motions != nullptr); + ABSL_CHECK(camera_motions != nullptr); camera_motions->clear(); camera_motions->resize(feature_lists->size()); @@ -2701,8 +2704,8 @@ void MotionEstimation::EstimateMotionsParallel( void MotionEstimation::DetermineShotBoundaries( const std::vector& feature_lists, std::vector* camera_motions) const { - CHECK(camera_motions != nullptr); - CHECK_EQ(feature_lists.size(), camera_motions->size()); + ABSL_CHECK(camera_motions != nullptr); + ABSL_CHECK_EQ(feature_lists.size(), camera_motions->size()); const auto& shot_options = options_.shot_boundary_options(); // Verify empty feature frames and invalid models via visual consistency. @@ -2763,7 +2766,7 @@ void MotionEstimation::DetermineShotBoundaries( void MotionEstimation::ResetMotionModels(const MotionEstimationOptions& options, CameraMotion* camera_motion) { - CHECK(camera_motion); + ABSL_CHECK(camera_motion); // Clear models. camera_motion->clear_translation(); @@ -3016,8 +3019,8 @@ Vector2_f EstimateTranslationModelDouble( void MotionEstimation::ComputeFeatureMask( const RegionFlowFeatureList& feature_list, std::vector* mask_indices, std::vector* bin_normalizer) const { - CHECK(mask_indices != nullptr); - CHECK(bin_normalizer != nullptr); + ABSL_CHECK(mask_indices != nullptr); + ABSL_CHECK(bin_normalizer != nullptr); const int num_features = feature_list.feature_size(); mask_indices->clear(); @@ -3052,7 +3055,7 @@ bool MotionEstimation::GetTranslationIrlsInitialization( RegionFlowFeatureList* feature_list, const EstimateModelOptions& model_options, float avg_camera_motion, InlierMask* inlier_mask, TranslationModel* best_model) const { - CHECK(best_model != nullptr); + ABSL_CHECK(best_model != nullptr); const int num_features = feature_list->feature_size(); if (!num_features) { @@ -3274,9 +3277,9 @@ LinearSimilarityModel LinearSimilarityL2SolveSystem( const RegionFlowFeatureList& feature_list, Eigen::Matrix* matrix, Eigen::Matrix* rhs, Eigen::Matrix* solution, bool* success) { - CHECK(matrix != nullptr); - CHECK(rhs != nullptr); - CHECK(solution != nullptr); + ABSL_CHECK(matrix != nullptr); + ABSL_CHECK(rhs != nullptr); + ABSL_CHECK(solution != nullptr); *matrix = Eigen::Matrix::Zero(); *rhs = Eigen::Matrix::Zero(); @@ -3357,7 +3360,7 @@ bool MotionEstimation::GetSimilarityIrlsInitialization( RegionFlowFeatureList* feature_list, const EstimateModelOptions& model_options, float avg_camera_motion, InlierMask* inlier_mask, LinearSimilarityModel* best_model) const { - CHECK(best_model != nullptr); + ABSL_CHECK(best_model != nullptr); const int num_features = feature_list->feature_size(); if (!num_features) { @@ -3488,8 +3491,8 @@ bool MotionEstimation::GetSimilarityIrlsInitialization( void MotionEstimation::ComputeSimilarityInliers( const RegionFlowFeatureList& feature_list, int* num_inliers, int* num_strict_inliers) const { - CHECK(num_inliers); - CHECK(num_strict_inliers); + ABSL_CHECK(num_inliers); + ABSL_CHECK(num_strict_inliers); const auto& similarity_bounds = options_.stable_similarity_bounds(); @@ -3498,11 +3501,11 @@ void MotionEstimation::ComputeSimilarityInliers( float threshold = std::max(similarity_bounds.inlier_threshold(), similarity_bounds.frac_inlier_threshold() * hypot(frame_width_, frame_height_)); - CHECK_GT(threshold, 0); + ABSL_CHECK_GT(threshold, 0); threshold = 1.0f / threshold; float strict_threshold = similarity_bounds.strict_inlier_threshold(); - CHECK_GT(strict_threshold, 0); + ABSL_CHECK_GT(strict_threshold, 0); strict_threshold = 1.0f / strict_threshold; if (!options_.irls_use_l0_norm()) { @@ -3764,14 +3767,14 @@ bool HomographyL2QRSolve( float perspective_regularizer, Eigen::Matrix* matrix, // tmp matrix Eigen::Matrix* solution) { - CHECK(matrix); - CHECK(solution); - CHECK_EQ(8, matrix->cols()); + ABSL_CHECK(matrix); + ABSL_CHECK(solution); + ABSL_CHECK_EQ(8, matrix->cols()); const int num_rows = 2 * feature_list.feature_size() + (perspective_regularizer == 0 ? 0 : 1); - CHECK_EQ(num_rows, matrix->rows()); - CHECK_EQ(1, solution->cols()); - CHECK_EQ(8, solution->rows()); + ABSL_CHECK_EQ(num_rows, matrix->rows()); + ABSL_CHECK_EQ(1, solution->cols()); + ABSL_CHECK_EQ(8, solution->rows()); // Compute homography from features (H * location = prev_location). *matrix = Eigen::Matrix::Zero(matrix->rows(), 8); @@ -3853,9 +3856,9 @@ Homography HomographyL2NormalEquationSolve( float perspective_regularizer, Eigen::Matrix* matrix, Eigen::Matrix* rhs, Eigen::Matrix* solution, bool* success) { - CHECK(matrix != nullptr); - CHECK(rhs != nullptr); - CHECK(solution != nullptr); + ABSL_CHECK(matrix != nullptr); + ABSL_CHECK(rhs != nullptr); + ABSL_CHECK(solution != nullptr); *matrix = Eigen::Matrix::Zero(); *rhs = Eigen::Matrix::Zero(); @@ -4059,8 +4062,8 @@ bool MixtureHomographyL2DLTSolve( const MixtureRowWeights& row_weights, float regularizer_lambda, Eigen::MatrixXf* matrix, // least squares matrix Eigen::MatrixXf* solution) { - CHECK(matrix); - CHECK(solution); + ABSL_CHECK(matrix); + ABSL_CHECK(solution); // cv::solve can hang for really bad conditioned systems. const double feature_irls_sum = RegionFlowFeatureIRLSSum(feature_list); @@ -4071,11 +4074,12 @@ bool MixtureHomographyL2DLTSolve( const int num_dof = 8 * num_models; const int num_constraints = num_dof - 8; - CHECK_EQ(matrix->cols(), num_dof); + ABSL_CHECK_EQ(matrix->cols(), num_dof); // 2 Rows (x,y) per feature. - CHECK_EQ(matrix->rows(), 2 * feature_list.feature_size() + num_constraints); - CHECK_EQ(solution->cols(), 1); - CHECK_EQ(solution->rows(), num_dof); + ABSL_CHECK_EQ(matrix->rows(), + 2 * feature_list.feature_size() + num_constraints); + ABSL_CHECK_EQ(solution->cols(), 1); + ABSL_CHECK_EQ(solution->rows(), num_dof); // Compute homography from features. (H * location = prev_location) *matrix = Eigen::MatrixXf::Zero(matrix->rows(), matrix->cols()); @@ -4155,8 +4159,8 @@ bool TransMixtureHomographyL2DLTSolve( const MixtureRowWeights& row_weights, float regularizer_lambda, Eigen::MatrixXf* matrix, // least squares matrix Eigen::MatrixXf* solution) { - CHECK(matrix); - CHECK(solution); + ABSL_CHECK(matrix); + ABSL_CHECK(solution); // cv::solve can hang for really bad conditioned systems. const double feature_irls_sum = RegionFlowFeatureIRLSSum(feature_list); @@ -4167,11 +4171,12 @@ bool TransMixtureHomographyL2DLTSolve( const int num_dof = 6 + 2 * num_models; const int num_constraints = 2 * (num_models - 1); - CHECK_EQ(matrix->cols(), num_dof); + ABSL_CHECK_EQ(matrix->cols(), num_dof); // 2 Rows (x,y) per feature. - CHECK_EQ(matrix->rows(), 2 * feature_list.feature_size() + num_constraints); - CHECK_EQ(solution->cols(), 1); - CHECK_EQ(solution->rows(), num_dof); + ABSL_CHECK_EQ(matrix->rows(), + 2 * feature_list.feature_size() + num_constraints); + ABSL_CHECK_EQ(solution->cols(), 1); + ABSL_CHECK_EQ(solution->rows(), num_dof); // Compute homography from features. (H * location = prev_location) *matrix = Eigen::MatrixXf::Zero(matrix->rows(), matrix->cols()); @@ -4254,8 +4259,8 @@ bool SkewRotMixtureHomographyL2DLTSolve( const MixtureRowWeights& row_weights, float regularizer_lambda, Eigen::MatrixXf* matrix, // least squares matrix Eigen::MatrixXf* solution) { - CHECK(matrix); - CHECK(solution); + ABSL_CHECK(matrix); + ABSL_CHECK(solution); // cv::solve can hang for really bad conditioned systems. const double feature_irls_sum = RegionFlowFeatureIRLSSum(feature_list); @@ -4266,11 +4271,12 @@ bool SkewRotMixtureHomographyL2DLTSolve( const int num_dof = 4 + 4 * num_models; const int num_constraints = 4 * (num_models - 1); - CHECK_EQ(matrix->cols(), num_dof); + ABSL_CHECK_EQ(matrix->cols(), num_dof); // 2 Rows (x,y) per feature. - CHECK_EQ(matrix->rows(), 2 * feature_list.feature_size() + num_constraints); - CHECK_EQ(solution->cols(), 1); - CHECK_EQ(solution->rows(), num_dof); + ABSL_CHECK_EQ(matrix->rows(), + 2 * feature_list.feature_size() + num_constraints); + ABSL_CHECK_EQ(solution->cols(), 1); + ABSL_CHECK_EQ(solution->rows(), num_dof); // Compute homography from features. (H * location = prev_location) *matrix = Eigen::MatrixXf::Zero(matrix->rows(), matrix->cols()); @@ -4354,7 +4360,7 @@ bool SkewRotMixtureHomographyL2DLTSolve( void MotionEstimation::GetHomographyIRLSCenterWeights( const RegionFlowFeatureList& feature_list, std::vector* weights) const { - CHECK(weights != nullptr); + ABSL_CHECK(weights != nullptr); const int num_features = feature_list.feature_size(); weights->clear(); @@ -4441,7 +4447,7 @@ bool MotionEstimation::IsStableTranslation( void MotionEstimation::CheckTranslationAcceleration( std::vector* camera_motions) const { - CHECK(camera_motions != nullptr); + ABSL_CHECK(camera_motions != nullptr); std::vector magnitudes; for (const auto& motion : *camera_motions) { const float translation_magnitude = @@ -4663,7 +4669,7 @@ bool MotionEstimation::IsStableMixtureHomography( float MotionEstimation::GridCoverage( const RegionFlowFeatureList& feature_list, float min_inlier_score, MotionEstimationThreadStorage* thread_storage) const { - CHECK(thread_storage != nullptr); + ABSL_CHECK(thread_storage != nullptr); // 10x10 grid for coverage estimation. const int grid_size = options_.coverage_grid_size(); @@ -4674,7 +4680,7 @@ float MotionEstimation::GridCoverage( const std::vector& grid_cell_weights = thread_storage->GridCoverageInitializationWeights(); - CHECK_EQ(mask_size, grid_cell_weights.size()); + ABSL_CHECK_EQ(mask_size, grid_cell_weights.size()); const float max_inlier_score = 1.75f * min_inlier_score; const float mid_inlier_score = 0.5 * (min_inlier_score + max_inlier_score); @@ -4699,7 +4705,7 @@ float MotionEstimation::GridCoverage( normalized_domain_.x() / grid_size * overlap_x / num_overlaps; std::vector>& irls_mask = *thread_storage->EmptyGridCoverageIrlsMask(); - CHECK_EQ(mask_size, irls_mask.size()); + ABSL_CHECK_EQ(mask_size, irls_mask.size()); // Bin features. for (const auto& feature : feature_list.feature()) { @@ -4743,7 +4749,7 @@ float MotionEstimation::GridCoverage( const float cell_weight_sum = std::accumulate(grid_cell_weights.begin(), grid_cell_weights.end(), 0.0f); - CHECK_GT(cell_weight_sum, 0); + ABSL_CHECK_GT(cell_weight_sum, 0); return std::inner_product(max_coverage.begin(), max_coverage.end(), grid_cell_weights.begin(), 0.0f) / @@ -4966,13 +4972,13 @@ bool MotionEstimation::EstimateHomographyIRLS( } else { bool success = false; if (options_.use_highest_accuracy_for_normal_equations()) { - CHECK(!use_float); + ABSL_CHECK(!use_float); norm_model = HomographyL2NormalEquationSolve( *feature_list, prev_solution, options_.homography_perspective_regularizer(), &matrix_d, &rhs_d, &solution_d, &success); } else { - CHECK(use_float); + ABSL_CHECK(use_float); norm_model = HomographyL2NormalEquationSolve( *feature_list, prev_solution, options_.homography_perspective_regularizer(), &matrix_f, &rhs_f, @@ -5092,9 +5098,9 @@ bool MotionEstimation::MixtureHomographyFromFeature( // Compute weights if necessary. // Compute scale to index mixture weights from normalization. - CHECK(row_weights_.get() != nullptr); - CHECK_EQ(row_weights_->YScale(), frame_height_ / normalized_domain_.y()); - CHECK_EQ(row_weights_->NumModels(), num_mixtures); + ABSL_CHECK(row_weights_.get() != nullptr); + ABSL_CHECK_EQ(row_weights_->YScale(), frame_height_ / normalized_domain_.y()); + ABSL_CHECK_EQ(row_weights_->NumModels(), num_mixtures); const MotionEstimationOptions::MixtureModelMode mixture_mode = options_.mixture_model_mode(); @@ -5444,12 +5450,12 @@ bool MotionEstimation::EstimateMixtureHomographyIRLS( void MotionEstimation::DetermineOverlayIndices( bool irls_weights_preinitialized, std::vector* camera_motions, std::vector* feature_lists) const { - CHECK(camera_motions != nullptr); - CHECK(feature_lists != nullptr); + ABSL_CHECK(camera_motions != nullptr); + ABSL_CHECK(feature_lists != nullptr); // Two stage estimation: First translation only, followed by // overlay analysis. const int num_frames = feature_lists->size(); - CHECK_EQ(num_frames, camera_motions->size()); + ABSL_CHECK_EQ(num_frames, camera_motions->size()); std::vector translation_motions(num_frames); const int irls_per_round = options_.irls_rounds(); @@ -5524,9 +5530,9 @@ float MotionEstimation::OverlayAnalysis( const std::vector& translations, std::vector* feature_lists, std::vector* overlay_indices) const { - CHECK(feature_lists != nullptr); - CHECK(overlay_indices != nullptr); - CHECK_EQ(feature_lists->size(), translations.size()); + ABSL_CHECK(feature_lists != nullptr); + ABSL_CHECK(overlay_indices != nullptr); + ABSL_CHECK_EQ(feature_lists->size(), translations.size()); overlay_indices->clear(); const int grid_size = @@ -5614,7 +5620,7 @@ float MotionEstimation::OverlayAnalysis( void MotionEstimation::PostIRLSSmoothing( const std::vector& camera_motions, std::vector* feature_lists) const { - CHECK(feature_lists != nullptr); + ABSL_CHECK(feature_lists != nullptr); std::vector> feature_grids; std::vector> feature_taps_3; @@ -5694,7 +5700,7 @@ void TemporalIRLSPush(const FeatureGrid& curr_grid, float grid_scale, int grid_dim_x, RegionFlowFeatureView* curr_view, RegionFlowFeatureView* prev_view) { - CHECK(curr_view != nullptr); + ABSL_CHECK(curr_view != nullptr); // Spatial filtering of inverse irls weights and the temporally weighted // pushed result from the next frame. for (auto& feature : *curr_view) { @@ -5722,7 +5728,7 @@ void TemporalIRLSPush(const FeatureGrid& curr_grid, } // Only zero if spatial AND feature sigma = 0. - DCHECK_GT(weight_sum, 0); + ABSL_DCHECK_GT(weight_sum, 0); feature->mutable_internal_irls()->set_weight_sum(weight_sum); feature->mutable_internal_irls()->set_value_sum(value_sum); } @@ -5834,7 +5840,7 @@ void TemporalIRLSPull(const FeatureGrid& curr_grid, } } - CHECK_GT(weight_sum, 0) << feature->irls_weight(); + ABSL_CHECK_GT(weight_sum, 0) << feature->irls_weight(); feature->mutable_internal_irls()->set_weight_sum(weight_sum); feature->mutable_internal_irls()->set_value_sum(value_sum); } @@ -5852,7 +5858,7 @@ void TemporalIRLSPull(const FeatureGrid& curr_grid, void MotionEstimation::InitGaussLUT(float sigma, float max_range, std::vector* lut, float* scale) const { - CHECK(lut); + ABSL_CHECK(lut); // Calculate number of bins if scale is non-zero, otherwise use one bin per // integer in the domain [0, max_range]. const int lut_bins = (scale != nullptr) ? (1 << 10) : std::ceil(max_range); diff --git a/mediapipe/util/tracking/motion_models.cc b/mediapipe/util/tracking/motion_models.cc index 46e77f9b6..898b7e06a 100644 --- a/mediapipe/util/tracking/motion_models.cc +++ b/mediapipe/util/tracking/motion_models.cc @@ -22,6 +22,7 @@ #include "Eigen/Core" #include "Eigen/Dense" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/strings/str_format.h" @@ -44,10 +45,10 @@ AffineModel ModelAdapter::ToAffine( TranslationModel ModelAdapter::FromAffine( const AffineModel& model) { - DCHECK_EQ(model.a(), 1); - DCHECK_EQ(model.b(), 0); - DCHECK_EQ(model.c(), 0); - DCHECK_EQ(model.d(), 1); + ABSL_DCHECK_EQ(model.a(), 1); + ABSL_DCHECK_EQ(model.b(), 0); + ABSL_DCHECK_EQ(model.c(), 0); + ABSL_DCHECK_EQ(model.d(), 1); return TranslationAdapter::FromArgs(model.dx(), model.dy()); } @@ -64,7 +65,7 @@ TranslationModel ModelAdapter::FromHomography( void ModelAdapter::GetJacobianAtPoint(const Vector2_f& pt, float* jacobian) { - DCHECK(jacobian); + ABSL_DCHECK(jacobian); jacobian[0] = 1; jacobian[1] = 0; jacobian[2] = 0; @@ -116,7 +117,7 @@ SimilarityModel ModelAdapter::FromArgs(float dx, float dy, SimilarityModel ModelAdapter::FromFloatPointer( const float* args, bool identity_parametrization) { - DCHECK(args); + ABSL_DCHECK(args); SimilarityModel model; model.set_dx(args[0]); model.set_dy(args[1]); @@ -127,7 +128,7 @@ SimilarityModel ModelAdapter::FromFloatPointer( SimilarityModel ModelAdapter::FromDoublePointer( const double* args, bool identity_parametrization) { - DCHECK(args); + ABSL_DCHECK(args); SimilarityModel model; model.set_dx(args[0]); model.set_dy(args[1]); @@ -236,7 +237,7 @@ std::string ModelAdapter::ToString( SimilarityModel ModelAdapter::NormalizationTransform( float frame_width, float frame_height) { const float scale = std::hypot(frame_width, frame_height); - DCHECK_NE(scale, 0); + ABSL_DCHECK_NE(scale, 0); return SimilarityAdapter::FromArgs(0, 0, 1.0 / scale, 0); } @@ -263,8 +264,8 @@ AffineModel ModelAdapter::ToAffine( LinearSimilarityModel ModelAdapter::FromAffine( const AffineModel& model) { - DCHECK_EQ(model.a(), model.d()); - DCHECK_EQ(model.b(), -model.c()); + ABSL_DCHECK_EQ(model.a(), model.d()); + ABSL_DCHECK_EQ(model.b(), -model.c()); return LinearSimilarityAdapter::FromArgs(model.dx(), model.dy(), model.a(), -model.b()); @@ -314,7 +315,7 @@ LinearSimilarityModel ModelAdapter::AddIdentity( void ModelAdapter::GetJacobianAtPoint( const Vector2_f& pt, float* jacobian) { - DCHECK(jacobian); + ABSL_DCHECK(jacobian); // First row. jacobian[0] = 1; jacobian[1] = 0; @@ -331,7 +332,7 @@ LinearSimilarityModel ModelAdapter::NormalizationTransform( float frame_width, float frame_height) { const float scale = std::hypot(frame_width, frame_height); - DCHECK_NE(scale, 0); + ABSL_DCHECK_NE(scale, 0); return LinearSimilarityAdapter::FromArgs(0, 0, 1.0 / scale, 0); } @@ -369,7 +370,7 @@ std::string ModelAdapter::ToString(const AffineModel& model) { AffineModel ModelAdapter::NormalizationTransform( float frame_width, float frame_height) { const float scale = std::hypot(frame_width, frame_height); - DCHECK_NE(scale, 0); + ABSL_DCHECK_NE(scale, 0); return AffineAdapter::FromArgs(0, 0, 1.0f / scale, 0, 0, 1.0f / scale); } @@ -380,8 +381,8 @@ Homography ModelAdapter::ToHomography(const AffineModel& model) { } AffineModel ModelAdapter::FromHomography(const Homography& model) { - DCHECK_EQ(model.h_20(), 0); - DCHECK_EQ(model.h_21(), 0); + ABSL_DCHECK_EQ(model.h_20(), 0); + ABSL_DCHECK_EQ(model.h_21(), 0); float params[6] = {model.h_02(), model.h_12(), // dx, dy model.h_00(), model.h_01(), // a, b @@ -412,7 +413,7 @@ AffineModel ModelAdapter::AddIdentity( void ModelAdapter::GetJacobianAtPoint(const Vector2_f& pt, float* jacobian) { - DCHECK(jacobian); + ABSL_DCHECK(jacobian); // First row. jacobian[0] = 1; jacobian[1] = 0; @@ -583,8 +584,8 @@ std::string ModelAdapter::ToString(const Homography& model) { } AffineModel ModelAdapter::ToAffine(const Homography& model) { - DCHECK_EQ(model.h_20(), 0); - DCHECK_EQ(model.h_21(), 0); + ABSL_DCHECK_EQ(model.h_20(), 0); + ABSL_DCHECK_EQ(model.h_21(), 0); AffineModel affine_model; affine_model.set_a(model.h_00()); affine_model.set_b(model.h_01()); @@ -605,7 +606,7 @@ bool ModelAdapter::IsAffine(const Homography& model) { void ModelAdapter::GetJacobianAtPoint(const Vector2_f& pt, float* jacobian) { - DCHECK(jacobian); + ABSL_DCHECK(jacobian); // First row. jacobian[0] = pt.x(); jacobian[1] = pt.y(); @@ -630,7 +631,7 @@ void ModelAdapter::GetJacobianAtPoint(const Vector2_f& pt, Homography ModelAdapter::NormalizationTransform( float frame_width, float frame_height) { const float scale = std::hypot(frame_width, frame_height); - DCHECK_NE(scale, 0); + ABSL_DCHECK_NE(scale, 0); return HomographyAdapter::FromArgs(1.0f / scale, 0, 0, 0, 1.0f / scale, 0, 0, 0); } @@ -862,7 +863,7 @@ MixtureRowWeights::MixtureRowWeights(int frame_height, int margin, float sigma, weight_ptr[int_pos] += spline_weights[0]; // Double knot. } - CHECK_LT(int_pos, num_models - 1); + ABSL_CHECK_LT(int_pos, num_models - 1); weight_ptr[int_pos + 1] += spline_weights[2]; if (int_pos + 1 < num_models - 1) { weight_ptr[int_pos + 2] += spline_weights[3]; @@ -899,7 +900,7 @@ MixtureRowWeights::MixtureRowWeights(int frame_height, int margin, float sigma, } // Normalize. - DCHECK_GT(weight_sum, 0); + ABSL_DCHECK_GT(weight_sum, 0); const float inv_weight_sum = 1.0f / weight_sum; for (int j = 0; j < num_models; ++j) { weight_ptr[j] *= inv_weight_sum; diff --git a/mediapipe/util/tracking/motion_models.h b/mediapipe/util/tracking/motion_models.h index 020e3f68b..b0272f971 100644 --- a/mediapipe/util/tracking/motion_models.h +++ b/mediapipe/util/tracking/motion_models.h @@ -21,6 +21,7 @@ #include #include "absl/container/node_hash_map.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "mediapipe/framework/port/logging.h" #include "mediapipe/framework/port/singleton.h" @@ -763,8 +764,8 @@ Model UniformModelParameters(const float value) { template Model BlendModels(const Model& a, const Model& b, float weight_b) { Model blended; - DCHECK_GE(weight_b, 0); - DCHECK_LE(weight_b, 1); + ABSL_DCHECK_GE(weight_b, 0); + ABSL_DCHECK_LE(weight_b, 1); const float weight_a = 1 - weight_b; for (int p = 0; p < ModelAdapter::NumParameters(); ++p) { const float pa = ModelAdapter::GetParameter(a, p); @@ -823,8 +824,8 @@ class MixtureRowWeights { const float* RowWeights(float y) const { int bin_y = y * y_scale_ + 0.5; - DCHECK_LT(bin_y, frame_height_ + margin_); - DCHECK_GE(bin_y, -margin_); + ABSL_DCHECK_LT(bin_y, frame_height_ + margin_); + ABSL_DCHECK_GE(bin_y, -margin_); return &weights_[(bin_y + margin_) * num_models_]; } @@ -867,7 +868,7 @@ inline MixtureRowWeights* MixtureRowWeightsFromCameraMotion( template void SmoothModels(const Model& sigma_time_model, const Model* model_sigma, std::vector* models) { - CHECK(models); + ABSL_CHECK(models); const int num_models = models->size(); @@ -967,7 +968,7 @@ inline TranslationModel ModelAdapter::FromArgs(float dx, inline TranslationModel ModelAdapter::FromFloatPointer( const float* args, bool) { - DCHECK(args); + ABSL_DCHECK(args); TranslationModel model; model.set_dx(args[0]); model.set_dy(args[1]); @@ -976,7 +977,7 @@ inline TranslationModel ModelAdapter::FromFloatPointer( inline TranslationModel ModelAdapter::FromDoublePointer( const double* args, bool) { - DCHECK(args); + ABSL_DCHECK(args); TranslationModel model; model.set_dx(args[0]); model.set_dy(args[1]); @@ -1056,7 +1057,7 @@ inline LinearSimilarityModel ModelAdapter::FromArgs( inline LinearSimilarityModel ModelAdapter::FromFloatPointer( const float* args, bool identity_parametrization) { - DCHECK(args); + ABSL_DCHECK(args); LinearSimilarityModel model; const float id_shift = identity_parametrization ? 1.f : 0.f; model.set_dx(args[0]); @@ -1069,7 +1070,7 @@ ModelAdapter::FromFloatPointer( inline LinearSimilarityModel ModelAdapter::FromDoublePointer( const double* args, bool identity_parametrization) { - DCHECK(args); + ABSL_DCHECK(args); LinearSimilarityModel model; const float id_shift = identity_parametrization ? 1.f : 0.f; model.set_dx(args[0]); @@ -1182,7 +1183,7 @@ inline AffineModel ModelAdapter::FromArgs(float dx, float dy, inline AffineModel ModelAdapter::FromFloatPointer( const float* args, bool identity_parametrization) { - DCHECK(args); + ABSL_DCHECK(args); AffineModel model; const float id_shift = identity_parametrization ? 1.f : 0.f; model.set_dx(args[0]); @@ -1196,7 +1197,7 @@ inline AffineModel ModelAdapter::FromFloatPointer( inline AffineModel ModelAdapter::FromDoublePointer( const double* args, bool identity_parametrization) { - DCHECK(args); + ABSL_DCHECK(args); AffineModel model; const float id_shift = identity_parametrization ? 1.f : 0.f; model.set_dx(args[0]); @@ -1325,7 +1326,7 @@ inline Homography ModelAdapter::FromArgs(float h_00, float h_01, inline Homography ModelAdapter::FromFloatPointer( const float* args, bool identity_parametrization) { - DCHECK(args); + ABSL_DCHECK(args); Homography model; const float id_shift = identity_parametrization ? 1.f : 0.f; model.set_h_00(id_shift + args[0]); @@ -1341,7 +1342,7 @@ inline Homography ModelAdapter::FromFloatPointer( inline Homography ModelAdapter::FromDoublePointer( const double* args, bool identity_parametrization) { - DCHECK(args); + ABSL_DCHECK(args); Homography model; const float id_shift = identity_parametrization ? 1.f : 0.f; model.set_h_00(id_shift + args[0]); @@ -1399,7 +1400,7 @@ inline Homography ModelAdapter::Compose(const Homography& lhs, Homography result; const float z = lhs.h_20() * rhs.h_02() + lhs.h_21() * rhs.h_12() + 1.0f * 1.0f; - CHECK_NE(z, 0) << "Degenerate homography. See proto."; + ABSL_CHECK_NE(z, 0) << "Degenerate homography. See proto."; const float inv_z = 1.0 / z; result.set_h_00((lhs.h_00() * rhs.h_00() + lhs.h_01() * rhs.h_10() + @@ -1632,7 +1633,7 @@ MixtureModelAdapterBase::LinearModel( } const double denom = sum_xx - inv_models * sum_x * sum_x; - CHECK_NE(denom, 0); // As num_models > 1. + ABSL_CHECK_NE(denom, 0); // As num_models > 1. const double a = (sum_xy - inv_models * sum_x * sum_y) * denom; const double b = inv_models * (sum_y - a * sum_x); @@ -1689,7 +1690,7 @@ Vector2_f MixtureModelAdapter::TransformPoint( BaseModelAdapter::TransformPoint3(model.model(i), pt3 * weights[i]); } - DCHECK_NE(result.z(), 0) << "Degenerate mapping."; + ABSL_DCHECK_NE(result.z(), 0) << "Degenerate mapping."; return Vector2_f(result.x() / result.z(), result.y() / result.z()); } @@ -1819,7 +1820,7 @@ inline Vector2_f MixtureModelAdapter::TransformPoint( ABSL_LOG(FATAL) << "Unknown type."; } - DCHECK_NE(result.z(), 0) << "Degenerate mapping."; + ABSL_DCHECK_NE(result.z(), 0) << "Degenerate mapping."; return Vector2_f(result.x() / result.z(), result.y() / result.z()); } diff --git a/mediapipe/util/tracking/motion_models_cv.cc b/mediapipe/util/tracking/motion_models_cv.cc index b9b428adb..e11132b37 100644 --- a/mediapipe/util/tracking/motion_models_cv.cc +++ b/mediapipe/util/tracking/motion_models_cv.cc @@ -14,6 +14,8 @@ #include "mediapipe/util/tracking/motion_models_cv.h" +#include "absl/log/absl_check.h" + namespace mediapipe { void ModelCvConvert::ToCvMat(const TranslationModel& model, @@ -41,7 +43,7 @@ void ModelCvConvert::ToCvMat(const AffineModel& model, void ModelCvConvert::ToCvMat(const Homography& model, cv::Mat* matrix) { - CHECK(matrix != nullptr); + ABSL_CHECK(matrix != nullptr); matrix->create(3, 3, CV_32FC1); matrix->at(0, 0) = model.h_00(); matrix->at(0, 1) = model.h_01(); diff --git a/mediapipe/util/tracking/motion_saliency.cc b/mediapipe/util/tracking/motion_saliency.cc index ec40dfa30..44f4ec5ee 100644 --- a/mediapipe/util/tracking/motion_saliency.cc +++ b/mediapipe/util/tracking/motion_saliency.cc @@ -24,6 +24,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "mediapipe/util/tracking/camera_motion.h" #include "mediapipe/util/tracking/measure_time.h" @@ -44,12 +45,12 @@ void MotionSaliency::SaliencyFromFeatures( const RegionFlowFeatureList& feature_list, std::vector* irls_weights, // optional. SalientPointFrame* salient_frame) { - CHECK(salient_frame); - CHECK_EQ(frame_width_, feature_list.frame_width()); - CHECK_EQ(frame_height_, feature_list.frame_height()); + ABSL_CHECK(salient_frame); + ABSL_CHECK_EQ(frame_width_, feature_list.frame_width()); + ABSL_CHECK_EQ(frame_height_, feature_list.frame_height()); if (irls_weights) { - CHECK_EQ(feature_list.feature_size(), irls_weights->size()); + ABSL_CHECK_EQ(feature_list.feature_size(), irls_weights->size()); } if (feature_list.feature_size() < 1) { @@ -105,8 +106,8 @@ void MotionSaliency::SaliencyFromPoints(const std::vector* points, const std::vector* weights, SalientPointFrame* salient_frame) { // TODO: Handle vectors of size zero. - CHECK(salient_frame); - CHECK_EQ(points->size(), weights->size()); + ABSL_CHECK(salient_frame); + ABSL_CHECK_EQ(points->size(), weights->size()); float max_weight = *std::max_element(weights->begin(), weights->end()); @@ -212,7 +213,7 @@ void MotionSaliency::SelectSaliencyInliers( void MotionSaliency::FilterMotionSaliency( std::vector* saliency_point_list) { - CHECK(saliency_point_list != nullptr); + ABSL_CHECK(saliency_point_list != nullptr); const float sigma_time = options_.filtering_sigma_time(); const float sigma_space = options_.filtering_sigma_space(); @@ -329,7 +330,7 @@ void MotionSaliency::FilterMotionSaliency( void MotionSaliency::CollapseMotionSaliency( const SaliencyPointList& input_saliency, const Vector4_f& bounds, SaliencyPointList* output_saliency) { - CHECK(output_saliency); + ABSL_CHECK(output_saliency); output_saliency->clear(); output_saliency->resize(input_saliency.size()); @@ -378,8 +379,8 @@ void DetermineFeatureModes( const std::vector& space_lut, float space_scale, std::vector>* mode_grid, std::vector* mode_ptrs) { - CHECK(mode_grid); - CHECK(mode_ptrs); + ABSL_CHECK(mode_grid); + ABSL_CHECK(mode_ptrs); const int num_features = features.size(); mode_ptrs->reserve(num_features); @@ -439,8 +440,8 @@ void DetermineFeatureModes( void MotionSaliency::SalientModeFinding(std::vector* locations, std::vector* modes) { - CHECK(modes); - CHECK(locations); + ABSL_CHECK(modes); + ABSL_CHECK(locations); if (locations->empty()) { return; } @@ -477,7 +478,7 @@ void MotionSaliency::SalientModeFinding(std::vector* locations, nullptr, &grid_dims, &feature_grids); // Just one frame input, expect one grid as output. - CHECK_EQ(1, feature_grids.size()); + ABSL_CHECK_EQ(1, feature_grids.size()); const auto& feature_grid = feature_grids[0]; // Setup Gaussian LUT for smoothing in space, using 2^10 discretization bins. @@ -595,8 +596,8 @@ void MotionSaliency::SalientModeFinding(std::vector* locations, if (angle < 0) { angle += M_PI; } - CHECK_GE(angle, 0); - CHECK_LE(angle, M_PI + 1e-3); + ABSL_CHECK_GE(angle, 0); + ABSL_CHECK_LE(angle, M_PI + 1e-3); } SalientMode irls_mode; @@ -622,7 +623,7 @@ void MotionSaliency::SalientModeFinding(std::vector* locations, // mode finding and scales each point based on frame size. void MotionSaliency::DetermineSalientFrame( std::vector locations, SalientPointFrame* salient_frame) { - CHECK(salient_frame); + ABSL_CHECK(salient_frame); std::vector modes; { @@ -660,12 +661,12 @@ void ForegroundWeightsFromFeatures(const RegionFlowFeatureList& feature_list, float foreground_gamma, const CameraMotion* camera_motion, std::vector* weights) { - CHECK(weights != nullptr); + ABSL_CHECK(weights != nullptr); weights->clear(); constexpr float kEpsilon = 1e-4f; - CHECK_GT(foreground_threshold, 0.0f); + ABSL_CHECK_GT(foreground_threshold, 0.0f); if (camera_motion) { foreground_threshold *= std::max(kEpsilon, InlierCoverage(*camera_motion, false)); @@ -694,7 +695,7 @@ void ForegroundWeightsFromFeatures(const RegionFlowFeatureList& feature_list, std::max(kEpsilon, std::pow(foreground_measure, foreground_gamma))); } } - CHECK_EQ(feature_list.feature_size(), weights->size()); + ABSL_CHECK_EQ(feature_list.feature_size(), weights->size()); } } // namespace mediapipe diff --git a/mediapipe/util/tracking/parallel_invoker.h b/mediapipe/util/tracking/parallel_invoker.h index c9d236a7d..a00b52232 100644 --- a/mediapipe/util/tracking/parallel_invoker.h +++ b/mediapipe/util/tracking/parallel_invoker.h @@ -71,8 +71,8 @@ #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" -#include "absl/log/check.h" #include "absl/synchronization/mutex.h" #ifdef PARALLEL_INVOKER_ACTIVE @@ -285,9 +285,10 @@ inline void CheckAndSetInvokerOptions() { } #endif // PARALLEL_INVOKER_ACTIVE - CHECK_LT(flags_parallel_invoker_mode, PARALLEL_INVOKER_MAX_VALUE) + ABSL_CHECK_LT(flags_parallel_invoker_mode, PARALLEL_INVOKER_MAX_VALUE) + << "Invalid invoker mode specified."; + ABSL_CHECK_GE(flags_parallel_invoker_mode, 0) << "Invalid invoker mode specified."; - CHECK_GE(flags_parallel_invoker_mode, 0) << "Invalid invoker mode specified."; } // Performs parallel iteration from [start to end), scheduling grain_size @@ -304,7 +305,7 @@ void ParallelFor(size_t start, size_t end, size_t grain_size, #if defined(__APPLE__) case PARALLEL_INVOKER_GCD: { int iterations_remain = (end - start + grain_size - 1) / grain_size; - CHECK_GT(iterations_remain, 0); + ABSL_CHECK_GT(iterations_remain, 0); if (iterations_remain == 1) { // Execute invoker serially. invoker(BlockedRange(start, std::min(end, start + grain_size), 1)); @@ -316,7 +317,7 @@ void ParallelFor(size_t start, size_t end, size_t grain_size, dispatch_apply_f(iterations_remain, concurrent_queue, &context, ParallelForGCDTask); #if CHECK_GCD_PARALLEL_WORK_COUNT - CHECK_EQ(iterations_remain, context.count()); + ABSL_CHECK_EQ(iterations_remain, context.count()); #endif } break; @@ -325,7 +326,7 @@ void ParallelFor(size_t start, size_t end, size_t grain_size, case PARALLEL_INVOKER_THREAD_POOL: { int iterations_remain = (end - start + grain_size - 1) / grain_size; - CHECK_GT(iterations_remain, 0); + ABSL_CHECK_GT(iterations_remain, 0); if (iterations_remain == 1) { // Execute invoker serially. invoker(BlockedRange(start, std::min(end, start + grain_size), 1)); @@ -416,7 +417,7 @@ void ParallelFor2D(size_t start_row, size_t end_row, size_t start_col, case PARALLEL_INVOKER_GCD: { const int iterations_remain = (end_row - start_row + grain_size - 1) / grain_size; - CHECK_GT(iterations_remain, 0); + ABSL_CHECK_GT(iterations_remain, 0); if (iterations_remain == 1) { // Execute invoker serially. invoker(BlockedRange2D(BlockedRange(start_row, end_row, 1), @@ -430,7 +431,7 @@ void ParallelFor2D(size_t start_row, size_t end_row, size_t start_col, dispatch_apply_f(iterations_remain, concurrent_queue, &context, ParallelForGCDTask2D); #if CHECK_GCD_PARALLEL_WORK_COUNT - CHECK_EQ(iterations_remain, context.count()); + ABSL_CHECK_EQ(iterations_remain, context.count()); #endif } break; @@ -439,7 +440,7 @@ void ParallelFor2D(size_t start_row, size_t end_row, size_t start_col, case PARALLEL_INVOKER_THREAD_POOL: { int iterations_remain = end_row - start_row; // Guarded by loop_mutex - CHECK_GT(iterations_remain, 0); + ABSL_CHECK_GT(iterations_remain, 0); if (iterations_remain == 1) { // Execute invoker serially. invoker(BlockedRange2D(BlockedRange(start_row, end_row, 1), diff --git a/mediapipe/util/tracking/push_pull_filtering.h b/mediapipe/util/tracking/push_pull_filtering.h index 32010c947..80c631532 100644 --- a/mediapipe/util/tracking/push_pull_filtering.h +++ b/mediapipe/util/tracking/push_pull_filtering.h @@ -33,6 +33,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "mediapipe/framework/port/opencv_core_inc.h" #include "mediapipe/util/tracking/image_util.h" @@ -149,7 +150,7 @@ class PushPullFiltering { // Returns domain size of n-th pyramid level (including border depending on // filter_type). cv::Size NthPyramidDomain(int level) { - CHECK_LT(level, PyramidLevels()); + ABSL_CHECK_LT(level, PyramidLevels()); return downsample_pyramid_[level].size(); } @@ -447,7 +448,7 @@ template void PushPullFiltering::AllocatePyramid( const cv::Size& domain_size, int border, int type, bool allocate_base_level, std::vector* pyramid) { - CHECK(pyramid != nullptr); + ABSL_CHECK(pyramid != nullptr); pyramid->clear(); pyramid->reserve(16); // Do not anticipate videos with dimensions // larger than 2^16. @@ -469,15 +470,15 @@ void PushPullFiltering::AllocatePyramid( template void PushPullFiltering::InitializeImagePyramid( const cv::Mat& input_frame, std::vector* pyramid) { - CHECK(pyramid != nullptr); - CHECK_GT(pyramid->size(), 0); + ABSL_CHECK(pyramid != nullptr); + ABSL_CHECK_GT(pyramid->size(), 0); cv::Mat base_level((*pyramid)[0], cv::Range(border_, (*pyramid)[0].rows - border_), cv::Range(border_, (*pyramid)[0].cols - border_)); - CHECK_EQ(base_level.rows, input_frame.rows); - CHECK_EQ(base_level.cols, input_frame.cols); - CHECK_EQ(base_level.type(), input_frame.type()); + ABSL_CHECK_EQ(base_level.rows, input_frame.rows); + ABSL_CHECK_EQ(base_level.cols, input_frame.cols); + ABSL_CHECK_EQ(base_level.type(), input_frame.type()); input_frame.copyTo(base_level); CopyNecessaryBorder(&(*pyramid)[0]); @@ -744,11 +745,11 @@ void PushPullFiltering::PerformPushPull( cv::Point2i origin, int readout_level, const std::vector* data_weights, const cv::Mat* input_frame, cv::Mat* results) { - CHECK_EQ(data_locations.size(), data_values.size()); - CHECK(results != nullptr); + ABSL_CHECK_EQ(data_locations.size(), data_values.size()); + ABSL_CHECK(results != nullptr); if (data_weights) { - CHECK_EQ(data_weights->size(), data_locations.size()); + ABSL_CHECK_EQ(data_weights->size(), data_locations.size()); } origin.x += border_; @@ -761,13 +762,13 @@ void PushPullFiltering::PerformPushPull( mip_map[i] = &downsample_pyramid_[i]; } - CHECK_GE(readout_level, 0); - CHECK_LT(readout_level, PyramidLevels()); + ABSL_CHECK_GE(readout_level, 0); + ABSL_CHECK_LT(readout_level, PyramidLevels()); // CHECK if passed results matrix is compatible w.r.t. type and domain. - CHECK_EQ(downsample_pyramid_[readout_level].cols, results->cols); - CHECK_EQ(downsample_pyramid_[readout_level].rows, results->rows); - CHECK_EQ(downsample_pyramid_[readout_level].type(), results->type()); + ABSL_CHECK_EQ(downsample_pyramid_[readout_level].cols, results->cols); + ABSL_CHECK_EQ(downsample_pyramid_[readout_level].rows, results->rows); + ABSL_CHECK_EQ(downsample_pyramid_[readout_level].type(), results->type()); // Use caller-allocated results Mat. mip_map[readout_level] = results; @@ -807,7 +808,7 @@ void PushPullFiltering::PerformPushPullMat( int readout_level, // Default: 0. const cv::Mat* input_frame, // Optional. cv::Mat* results) { - CHECK(results != nullptr); + ABSL_CHECK(results != nullptr); // Create mip-map view (concat displacements with downsample_pyramid). std::vector mip_map(PyramidLevels()); @@ -816,18 +817,18 @@ void PushPullFiltering::PerformPushPullMat( mip_map[i] = &downsample_pyramid_[i]; } - CHECK_GE(readout_level, 0); - CHECK_LT(readout_level, PyramidLevels()); + ABSL_CHECK_GE(readout_level, 0); + ABSL_CHECK_LT(readout_level, PyramidLevels()); // CHECK if passed mip_map at level[0] is compatible w.r.t. type and domain. - CHECK_EQ(mip_map_level_0.cols, results->cols); - CHECK_EQ(mip_map_level_0.rows, results->rows); - CHECK_EQ(mip_map_level_0.type(), results->type()); + ABSL_CHECK_EQ(mip_map_level_0.cols, results->cols); + ABSL_CHECK_EQ(mip_map_level_0.rows, results->rows); + ABSL_CHECK_EQ(mip_map_level_0.type(), results->type()); // CHECK if passed results matrix is compatible w.r.t. type and domain. - CHECK_EQ(downsample_pyramid_[readout_level].cols, results->cols); - CHECK_EQ(downsample_pyramid_[readout_level].rows, results->rows); - CHECK_EQ(downsample_pyramid_[readout_level].type(), results->type()); + ABSL_CHECK_EQ(downsample_pyramid_[readout_level].cols, results->cols); + ABSL_CHECK_EQ(downsample_pyramid_[readout_level].rows, results->rows); + ABSL_CHECK_EQ(downsample_pyramid_[readout_level].type(), results->type()); // Use caller-allocated results Mat. mip_map[readout_level] = results; @@ -885,7 +886,7 @@ void PushPullFiltering::PerformPushPullImpl( } if (use_bilateral_) { - CHECK(input_frame != nullptr); + ABSL_CHECK(input_frame != nullptr); InitializeImagePyramid(*input_frame, &input_frame_pyramid_); } @@ -1050,7 +1051,7 @@ void PushPullFiltering::PullDownSampling( } } - DCHECK_GE(weight_sum, 0); + ABSL_DCHECK_GE(weight_sum, 0); if (weight_sum >= kBilateralEps * kBilateralEps) { const float inv_weight_sum = 1.f / weight_sum; diff --git a/mediapipe/util/tracking/region_flow.cc b/mediapipe/util/tracking/region_flow.cc index 7ee7ba4a1..7608b76a1 100644 --- a/mediapipe/util/tracking/region_flow.cc +++ b/mediapipe/util/tracking/region_flow.cc @@ -22,6 +22,7 @@ #include "absl/container/node_hash_map.h" #include "absl/container/node_hash_set.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/strings/str_cat.h" #include "mediapipe/framework/port/integral_types.h" @@ -48,7 +49,7 @@ bool IsPointWithinBounds(const Vector2_f& pt, float bounds, int frame_width, void GetRegionFlowFeatureList(const RegionFlowFrame& region_flow_frame, int distance_from_border, RegionFlowFeatureList* flow_feature_list) { - CHECK(flow_feature_list); + ABSL_CHECK(flow_feature_list); flow_feature_list->clear_feature(); const int frame_width = region_flow_frame.frame_width(); const int frame_height = region_flow_frame.frame_height(); @@ -77,8 +78,8 @@ void GetRegionFlowFeatureList(const RegionFlowFrame& region_flow_frame, float RegionFlowFeatureDistance(const PatchDescriptor& patch_desc_1, const PatchDescriptor& patch_desc_2) { - DCHECK_EQ(patch_desc_1.data_size(), patch_desc_2.data_size()); - DCHECK_GE(patch_desc_1.data_size(), 3); + ABSL_DCHECK_EQ(patch_desc_1.data_size(), patch_desc_2.data_size()); + ABSL_DCHECK_GE(patch_desc_1.data_size(), 3); constexpr int kNumMeans = 3; float sq_distance_sum = 0; @@ -119,7 +120,7 @@ void ClampRegionFlowFeatureIRLSWeights(float lower, float upper, void ComputeRegionFlowFeatureTexturedness( const RegionFlowFeatureList& flow_feature_list, bool use_15percent_as_max, std::vector* texturedness) { - CHECK(texturedness != nullptr); + ABSL_CHECK(texturedness != nullptr); *texturedness = std::vector(flow_feature_list.feature_size(), 1.0f); int texture_idx = 0; @@ -201,7 +202,7 @@ void CornerFilteredRegionFlowFeatureIRLSWeights( void GetRegionFlowFeatureIRLSWeights( const RegionFlowFeatureList& flow_feature_list, std::vector* irls_weights) { - CHECK(irls_weights != nullptr); + ABSL_CHECK(irls_weights != nullptr); irls_weights->clear(); irls_weights->reserve(flow_feature_list.feature_size()); for (auto feature = flow_feature_list.feature().begin(); @@ -212,8 +213,8 @@ void GetRegionFlowFeatureIRLSWeights( void SetRegionFlowFeatureIRLSWeights(const std::vector& irls_weights, RegionFlowFeatureList* flow_feature_list) { - CHECK(flow_feature_list != nullptr); - CHECK_EQ(irls_weights.size(), flow_feature_list->feature_size()); + ABSL_CHECK(flow_feature_list != nullptr); + ABSL_CHECK_EQ(irls_weights.size(), flow_feature_list->feature_size()); int idx = 0; for (auto feature = flow_feature_list->mutable_feature()->begin(); feature != flow_feature_list->mutable_feature()->end(); @@ -285,7 +286,7 @@ void SortRegionFlowById(RegionFlowFrame* flow_frame) { void InvertRegionFlow(const RegionFlowFrame& region_flow_frame, RegionFlowFrame* inverted_flow_frame) { - CHECK(inverted_flow_frame); + ABSL_CHECK(inverted_flow_frame); inverted_flow_frame->CopyFrom(region_flow_frame); for (auto& region_flow : *inverted_flow_frame->mutable_region_flow()) { region_flow.set_centroid_x(region_flow.centroid_x() + region_flow.flow_x()); @@ -304,7 +305,7 @@ void InvertRegionFlow(const RegionFlowFrame& region_flow_frame, void InvertRegionFlowFeatureList(const RegionFlowFeatureList& feature_list, RegionFlowFeatureList* inverted_feature_list) { - CHECK(inverted_feature_list); + ABSL_CHECK(inverted_feature_list); *inverted_feature_list = feature_list; for (auto& feature : *inverted_feature_list->mutable_feature()) { InvertRegionFlowFeature(&feature); @@ -372,7 +373,7 @@ void ScaleSalientPoint(float scale_x, float scale_y, SalientPoint* sp) { void ScaleSaliencyList(float scale, bool normalize_to_scale, SaliencyPointList* saliency_list) { - CHECK(saliency_list != nullptr); + ABSL_CHECK(saliency_list != nullptr); for (auto& point_frame : *saliency_list) { ScaleSalientPointFrame(scale, normalize_to_scale, &point_frame); } @@ -380,7 +381,7 @@ void ScaleSaliencyList(float scale, bool normalize_to_scale, void ScaleSalientPointFrame(float scale, bool normalize_to_scale, SalientPointFrame* saliency) { - CHECK(saliency != nullptr); + ABSL_CHECK(saliency != nullptr); float saliency_scale = scale; if (normalize_to_scale) { float weight_sum = 0.0f; @@ -400,7 +401,7 @@ void ScaleSalientPointFrame(float scale, bool normalize_to_scale, void ResetSaliencyBounds(float left, float bottom, float right, float top, SaliencyPointList* saliency_list) { - CHECK(saliency_list != nullptr); + ABSL_CHECK(saliency_list != nullptr); for (auto& point_frame : *saliency_list) { for (auto& salient_point : *point_frame.mutable_point()) { salient_point.set_left(left); @@ -413,8 +414,8 @@ void ResetSaliencyBounds(float left, float bottom, float right, float top, bool EllipseFromCovariance(float a, float bc, float d, Vector2_f* axis_magnitude, float* angle) { - CHECK(axis_magnitude != nullptr); - CHECK(angle != nullptr); + ABSL_CHECK(axis_magnitude != nullptr); + ABSL_CHECK(angle != nullptr); // Get trace and determinant const float trace = a + d; @@ -476,7 +477,7 @@ bool EllipseFromCovariance(float a, float bc, float d, void BoundingBoxFromEllipse(const Vector2_f& center, float norm_major_axis, float norm_minor_axis, float angle, std::vector* bounding_box) { - CHECK(bounding_box != nullptr); + ABSL_CHECK(bounding_box != nullptr); float dim_x; float dim_y; if (angle < M_PI * 0.25 || angle > M_PI * 0.75) { @@ -502,8 +503,8 @@ void BoundingBoxFromEllipse(const Vector2_f& center, float norm_major_axis, void CopyToEmptyFeatureList(RegionFlowFeatureList* src, RegionFlowFeatureList* dst) { - CHECK(src != nullptr); - CHECK(dst != nullptr); + ABSL_CHECK(src != nullptr); + ABSL_CHECK(dst != nullptr); // Swap out features for empty list. RegionFlowFeatureList empty_list; @@ -516,7 +517,7 @@ void CopyToEmptyFeatureList(RegionFlowFeatureList* src, src->mutable_feature()->Swap(empty_list.mutable_feature()); // src_features should be empty as in the beginning. - CHECK_EQ(0, empty_list.feature_size()); + ABSL_CHECK_EQ(0, empty_list.feature_size()); } void IntersectRegionFlowFeatureList( @@ -524,10 +525,11 @@ void IntersectRegionFlowFeatureList( std::function to_location_eval, RegionFlowFeatureList* from, RegionFlowFeatureList* result, std::vector* source_indices) { - CHECK(from != nullptr); - CHECK(result != nullptr); - CHECK(from->long_tracks()) << "Intersection only works for long features"; - CHECK(to.long_tracks()) << "Intersection only works for long features"; + ABSL_CHECK(from != nullptr); + ABSL_CHECK(result != nullptr); + ABSL_CHECK(from->long_tracks()) + << "Intersection only works for long features"; + ABSL_CHECK(to.long_tracks()) << "Intersection only works for long features"; // Hash features in to, based on track_id. absl::node_hash_map track_map; @@ -595,7 +597,7 @@ void LongFeatureStream::AddFeatures(const RegionFlowFeatureList& feature_list, present_tracks.insert(feature.track_id()); if (check_connectivity) { // A new feature should never have been erased before. - CHECK(old_ids_.find(feature.track_id()) == old_ids_.end()) + ABSL_CHECK(old_ids_.find(feature.track_id()) == old_ids_.end()) << "Feature : " << feature.track_id() << "was already removed."; } @@ -609,10 +611,10 @@ void LongFeatureStream::AddFeatures(const RegionFlowFeatureList& feature_list, if (find_pos != tracks_.end()) { // Track is present, add to it. if (check_connectivity) { - CHECK_LT((FeatureLocation(find_pos->second.back()) - - FeatureMatchLocation(feature)) - .Norm2(), - 1e-4); + ABSL_CHECK_LT((FeatureLocation(find_pos->second.back()) - + FeatureMatchLocation(feature)) + .Norm2(), + 1e-4); } find_pos->second.push_back(feature); } else { @@ -640,7 +642,7 @@ void LongFeatureStream::FlattenTrack( const std::vector& features, std::vector* result, std::vector* irls_weight, std::vector* flow) const { - CHECK(result != nullptr); + ABSL_CHECK(result != nullptr); if (features.empty()) { return; } @@ -733,7 +735,7 @@ void LongFeatureInfo::AddFeature(const RegionFlowFeature& feature) { void LongFeatureInfo::TrackLengths(const RegionFlowFeatureList& feature_list, std::vector* track_lengths) const { - CHECK(track_lengths); + ABSL_CHECK(track_lengths); const int feature_size = feature_list.feature_size(); track_lengths->resize(feature_size); for (int k = 0; k < feature_size; ++k) { @@ -778,7 +780,7 @@ int LongFeatureInfo::GlobalTrackLength(float percentile) const { void GridTaps(int dim_x, int dim_y, int tap_radius, std::vector>* taps) { - CHECK(taps); + ABSL_CHECK(taps); const int grid_size = dim_x * dim_y; const int diam = 2 * tap_radius + 1; taps->resize(grid_size); diff --git a/mediapipe/util/tracking/region_flow.h b/mediapipe/util/tracking/region_flow.h index 55aceee65..221e1f055 100644 --- a/mediapipe/util/tracking/region_flow.h +++ b/mediapipe/util/tracking/region_flow.h @@ -24,6 +24,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "mediapipe/framework/port/vector.h" #include "mediapipe/util/tracking/motion_models.h" @@ -82,9 +83,9 @@ inline float PatchDescriptorColorStdevL1(const PatchDescriptor& descriptor) { constexpr int kRedIdx = 3; constexpr int kGreenIdx = 6; constexpr int kBlueIdx = 8; - DCHECK_GE(descriptor.data(kRedIdx), 0); - DCHECK_GE(descriptor.data(kGreenIdx), 0); - DCHECK_GE(descriptor.data(kBlueIdx), 0); + ABSL_DCHECK_GE(descriptor.data(kRedIdx), 0); + ABSL_DCHECK_GE(descriptor.data(kGreenIdx), 0); + ABSL_DCHECK_GE(descriptor.data(kBlueIdx), 0); if (descriptor.data_size() > kBlueIdx) { return std::sqrt(descriptor.data(kRedIdx)) + @@ -234,7 +235,7 @@ template <> inline void RegionFlowFeatureListViaTransform( const MixtureHomography& mix, RegionFlowFeatureList* flow_feature_list, float a, float b, bool set_match, const MixtureRowWeights* row_weights) { - CHECK(row_weights) << "Row weights required for mixtures."; + ABSL_CHECK(row_weights) << "Row weights required for mixtures."; for (auto& feature : *flow_feature_list->mutable_feature()) { const float* weights = row_weights->RowWeights(feature.y()); @@ -275,7 +276,7 @@ std::pair GetFilteredWeightImpl(const Predicate& predicate, template int FilterRegionFlowFeatureList(const Predicate& predicate, float reset_value, RegionFlowFeatureList* flow_feature_list) { - CHECK(flow_feature_list != nullptr); + ABSL_CHECK(flow_feature_list != nullptr); int num_passing_features = 0; for (auto& feature : *flow_feature_list->mutable_feature()) { std::pair filter_result = @@ -296,7 +297,7 @@ int FilterRegionFlowFeatureWeights(const Predicate& predicate, float reset_value, const RegionFlowFeatureList& feature_list, std::vector* result_weights) { - CHECK(result_weights != nullptr); + ABSL_CHECK(result_weights != nullptr); result_weights->clear(); int num_passing_features = 0; @@ -318,8 +319,8 @@ template void SelectFeaturesFromList(const Predicate& predicate, RegionFlowFeatureList* feature_list, RegionFlowFeatureView* feature_view) { - CHECK(feature_list != nullptr); - CHECK(feature_view != nullptr); + ABSL_CHECK(feature_list != nullptr); + ABSL_CHECK(feature_view != nullptr); for (auto& feature : *feature_list->mutable_feature()) { if (predicate(feature)) { feature_view->push_back(&feature); @@ -329,8 +330,8 @@ void SelectFeaturesFromList(const Predicate& predicate, inline void SelectAllFeaturesFromList(RegionFlowFeatureList* feature_list, RegionFlowFeatureView* feature_view) { - CHECK(feature_list != nullptr); - CHECK(feature_view != nullptr); + ABSL_CHECK(feature_list != nullptr); + ABSL_CHECK(feature_view != nullptr); for (auto& feature : *feature_list->mutable_feature()) { feature_view->push_back(&feature); } @@ -342,7 +343,7 @@ inline void SelectAllFeaturesFromList(RegionFlowFeatureList* feature_list, template void SortRegionFlowFeatureView(const Predicate& predicate, RegionFlowFeatureView* feature_view) { - CHECK(feature_view != nullptr); + ABSL_CHECK(feature_view != nullptr); std::sort(feature_view->begin(), feature_view->end(), predicate); } @@ -590,8 +591,8 @@ void BuildFeatureGrid( std::vector>* feature_taps_5, // Optional. Vector2_i* num_grid_bins, // Optional. std::vector>* feature_grids) { - CHECK(feature_grids); - CHECK_GT(grid_resolution, 0.0f); + ABSL_CHECK(feature_grids); + ABSL_CHECK_GT(grid_resolution, 0.0f); const int num_frames = feature_views.size(); const int grid_dim_x = std::ceil(frame_width / grid_resolution); @@ -612,8 +613,8 @@ void BuildFeatureGrid( Vector2_f feature_loc = evaluator(*feature); const int x = feature_loc.x() * grid_scale; const int y = feature_loc.y() * grid_scale; - DCHECK_LT(y, grid_dim_y); - DCHECK_LT(x, grid_dim_x); + ABSL_DCHECK_LT(y, grid_dim_y); + ABSL_DCHECK_LT(x, grid_dim_x); const int grid_loc = y * grid_dim_x + x; curr_grid[grid_loc].push_back(feature); } diff --git a/mediapipe/util/tracking/region_flow_computation.cc b/mediapipe/util/tracking/region_flow_computation.cc index dde17048e..e9088df2b 100644 --- a/mediapipe/util/tracking/region_flow_computation.cc +++ b/mediapipe/util/tracking/region_flow_computation.cc @@ -28,6 +28,7 @@ #include "Eigen/Core" #include "absl/container/flat_hash_map.h" #include "absl/container/node_hash_set.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/memory/memory.h" #include "mediapipe/framework/port/logging.h" @@ -133,7 +134,7 @@ namespace { void GetPatchDescriptorAtPoint(const cv::Mat& rgb_frame, const Vector2_i& pt, const int radius, cv::Mat* lab_window, PatchDescriptor* descriptor) { - CHECK(descriptor); + ABSL_CHECK(descriptor); descriptor->clear_data(); // Reserve enough data for mean and upper triangular part of @@ -208,19 +209,19 @@ class PatchDescriptorInvoker { ++feature_idx) { RegionFlowFeature* feature = features_->mutable_feature(feature_idx); Vector2_i pt(FeatureIntLocation(*feature)); - DCHECK_GE(pt.x(), radius_); - DCHECK_GE(pt.y(), radius_); - DCHECK_LT(pt.x(), rgb_frame_.cols - radius_); - DCHECK_LT(pt.y(), rgb_frame_.rows - radius_); + ABSL_DCHECK_GE(pt.x(), radius_); + ABSL_DCHECK_GE(pt.y(), radius_); + ABSL_DCHECK_LT(pt.x(), rgb_frame_.cols - radius_); + ABSL_DCHECK_LT(pt.y(), rgb_frame_.rows - radius_); GetPatchDescriptorAtPoint(rgb_frame_, pt, radius_, &lab_window, feature->mutable_feature_descriptor()); if (prev_rgb_frame_) { Vector2_i pt_match(FeatureMatchIntLocation(*feature)); - DCHECK_GE(pt_match.x(), radius_); - DCHECK_GE(pt_match.y(), radius_); - DCHECK_LT(pt_match.x(), rgb_frame_.cols - radius_); - DCHECK_LT(pt_match.y(), rgb_frame_.rows - radius_); + ABSL_DCHECK_GE(pt_match.x(), radius_); + ABSL_DCHECK_GE(pt_match.y(), radius_); + ABSL_DCHECK_LT(pt_match.x(), rgb_frame_.cols - radius_); + ABSL_DCHECK_LT(pt_match.y(), rgb_frame_.rows - radius_); GetPatchDescriptorAtPoint(*prev_rgb_frame_, pt_match, radius_, &lab_window, feature->mutable_feature_match_descriptor()); @@ -248,17 +249,18 @@ void ComputeRegionFlowFeatureDescriptors( int patch_descriptor_radius, RegionFlowFeatureList* flow_feature_list) { const int rows = rgb_frame.rows; const int cols = rgb_frame.cols; - CHECK_EQ(rgb_frame.depth(), CV_8U); - CHECK_EQ(rgb_frame.channels(), 3); + ABSL_CHECK_EQ(rgb_frame.depth(), CV_8U); + ABSL_CHECK_EQ(rgb_frame.channels(), 3); if (prev_rgb_frame) { - CHECK_EQ(prev_rgb_frame->depth(), CV_8U); - CHECK_EQ(prev_rgb_frame->channels(), 3); - CHECK_EQ(prev_rgb_frame->rows, rows); - CHECK_EQ(prev_rgb_frame->cols, cols); + ABSL_CHECK_EQ(prev_rgb_frame->depth(), CV_8U); + ABSL_CHECK_EQ(prev_rgb_frame->channels(), 3); + ABSL_CHECK_EQ(prev_rgb_frame->rows, rows); + ABSL_CHECK_EQ(prev_rgb_frame->cols, cols); } - CHECK_LE(patch_descriptor_radius, flow_feature_list->distance_from_border()); + ABSL_CHECK_LE(patch_descriptor_radius, + flow_feature_list->distance_from_border()); ParallelFor( 0, flow_feature_list->feature_size(), 1, @@ -381,7 +383,7 @@ struct RegionFlowComputation::FrameTrackingData { iwidth = (iwidth + 1) / 2; iheight = (iheight + 1) / 2; } - CHECK_GE(extraction_levels, 1); + ABSL_CHECK_GE(extraction_levels, 1); // Frame is the same as first extraction level. frame = extraction_pyramid[0]; @@ -459,7 +461,7 @@ struct RegionFlowComputation::FrameTrackingData { } void RemoveFeature(int pos) { - DCHECK_LT(pos, features.size()); + ABSL_DCHECK_LT(pos, features.size()); features.erase(features.begin() + pos); feature_source_map.erase(feature_source_map.begin() + pos); corner_responses.erase(corner_responses.begin() + pos); @@ -473,7 +475,7 @@ struct RegionFlowComputation::FrameTrackingData { // Stores grayscale square patch with length patch_size extracted at center in // image frame and stores result in patch. void ExtractPatch(const cv::Point2f& center, int patch_size, cv::Mat* patch) { - CHECK(patch != nullptr); + ABSL_CHECK(patch != nullptr); patch->create(patch_size, patch_size, CV_8UC1); cv::getRectSubPix(frame, cv::Size(patch_size, patch_size), center, *patch); } @@ -533,13 +535,13 @@ struct RegionFlowComputation::LongTrackData { float MotionMagForId(int id) const { auto id_iter = track_info.find(id); - DCHECK(id_iter != track_info.end()); + ABSL_DCHECK(id_iter != track_info.end()); return id_iter->second.motion_mag; } void UpdateMotion(int id, float motion_mag) { auto id_iter = track_info.find(id); - DCHECK(id_iter != track_info.end()); + ABSL_DCHECK(id_iter != track_info.end()); if (id_iter->second.motion_mag >= 0) { id_iter->second.motion_mag = id_iter->second.motion_mag * 0.5f + 0.5f * motion_mag; @@ -618,8 +620,8 @@ RegionFlowComputation::RegionFlowComputation( } } - CHECK_NE(options.tracking_options().output_flow_direction(), - TrackingOptions::CONSECUTIVELY) + ABSL_CHECK_NE(options.tracking_options().output_flow_direction(), + TrackingOptions::CONSECUTIVELY) << "Output direction must be either set to FORWARD or BACKWARD."; use_downsampling_ = options_.downsample_mode() != RegionFlowComputationOptions::DOWNSAMPLE_NONE; @@ -652,7 +654,7 @@ RegionFlowComputation::RegionFlowComputation( } case RegionFlowComputationOptions::DOWNSAMPLE_BY_FACTOR: case RegionFlowComputationOptions::DOWNSAMPLE_TO_INPUT_SIZE: { - CHECK_GE(options_.downsample_factor(), 1); + ABSL_CHECK_GE(options_.downsample_factor(), 1); downsample_scale_ = options_.downsample_factor(); break; } @@ -730,7 +732,7 @@ RegionFlowComputation::RegionFlowComputation( frames_to_track_ = 1; break; case TrackingOptions::POLICY_MULTI_FRAME: - CHECK_GT(options_.tracking_options().multi_frames_to_track(), 0); + ABSL_CHECK_GT(options_.tracking_options().multi_frames_to_track(), 0); frames_to_track_ = options_.tracking_options().multi_frames_to_track(); break; case TrackingOptions::POLICY_LONG_TRACKS: @@ -759,7 +761,7 @@ RegionFlowComputation::RegionFlowComputation( break; } - CHECK(!options_.gain_correction() || !IsVerifyLongFeatures()) + ABSL_CHECK(!options_.gain_correction() || !IsVerifyLongFeatures()) << "Gain correction mode with verification of long features is not " << "supported."; @@ -812,7 +814,7 @@ RegionFlowComputation::RegionFlowComputation( // Compute settings for block based flow. const float block_size = options_.fast_estimation_block_size(); - CHECK_GT(block_size, 0) << "Need positive block size"; + ABSL_CHECK_GT(block_size, 0) << "Need positive block size"; block_width_ = block_size < 1 ? block_size * original_width_ : block_size; block_height_ = block_size < 1 ? block_size * original_height_ : block_size; @@ -873,18 +875,18 @@ RegionFlowComputation::RetrieveRegionFlowFeatureListImpl( int track_index, bool compute_feature_descriptor, bool compute_match_descriptor, const cv::Mat* curr_color_image, const cv::Mat* prev_color_image) { - CHECK_GT(region_flow_results_.size(), track_index); - CHECK(region_flow_results_[track_index].get()); + ABSL_CHECK_GT(region_flow_results_.size(), track_index); + ABSL_CHECK(region_flow_results_[track_index].get()); std::unique_ptr feature_list( std::move(region_flow_results_[track_index])); if (compute_feature_descriptor) { - CHECK(curr_color_image != nullptr); - CHECK_EQ(3, curr_color_image->channels()); + ABSL_CHECK(curr_color_image != nullptr); + ABSL_CHECK_EQ(3, curr_color_image->channels()); if (compute_match_descriptor) { - CHECK(prev_color_image != nullptr); - CHECK_EQ(3, prev_color_image->channels()); + ABSL_CHECK(prev_color_image != nullptr); + ABSL_CHECK_EQ(3, prev_color_image->channels()); } ComputeRegionFlowFeatureDescriptors( @@ -892,8 +894,9 @@ RegionFlowComputation::RetrieveRegionFlowFeatureListImpl( compute_match_descriptor ? prev_color_image : nullptr, options_.patch_descriptor_radius(), feature_list.get()); } else { - CHECK(!compute_match_descriptor) << "Set compute_feature_descriptor also " - << "if setting compute_match_descriptor"; + ABSL_CHECK(!compute_match_descriptor) + << "Set compute_feature_descriptor also " + << "if setting compute_match_descriptor"; } return feature_list; @@ -1010,7 +1013,7 @@ bool RegionFlowComputation::InitFrame(const cv::Mat& source, ABSL_LOG(ERROR) << "Expecting 1 channel input for GRAYSCALE."; return false; } - CHECK_EQ(1, source_ptr->channels()); + ABSL_CHECK_EQ(1, source_ptr->channels()); if (source_ptr != &dest_frame) { source_ptr->copyTo(dest_frame); } @@ -1028,8 +1031,8 @@ bool RegionFlowComputation::InitFrame(const cv::Mat& source, } // Consistency checks; not input governed. - CHECK_EQ(dest_frame.cols, frame_width_); - CHECK_EQ(dest_frame.rows, frame_height_); + ABSL_CHECK_EQ(dest_frame.cols, frame_width_); + ABSL_CHECK_EQ(dest_frame.rows, frame_height_); data->BuildPyramid(pyramid_levels_, options_.tracking_options().tracking_window_size(), @@ -1093,8 +1096,8 @@ bool RegionFlowComputation::AddImageAndTrack( curr_data->Reset(frame_num_, timestamp_usec); if (!IsModelIdentity(initial_transform)) { - CHECK_EQ(1, frames_to_track_) << "Initial transform is not supported " - << "for multi frame tracking"; + ABSL_CHECK_EQ(1, frames_to_track_) << "Initial transform is not supported " + << "for multi frame tracking"; Homography transform = initial_transform; if (downsample_scale_ != 1) { const float scale = 1.0f / downsample_scale_; @@ -1208,17 +1211,17 @@ bool RegionFlowComputation::AddImageAndTrack( } cv::Mat RegionFlowComputation::GetGrayscaleFrameFromResults() { - CHECK_GT(data_queue_.size(), 0) << "Empty queue, was AddImage* called?"; + ABSL_CHECK_GT(data_queue_.size(), 0) << "Empty queue, was AddImage* called?"; FrameTrackingData* curr_data = data_queue_.back().get(); - CHECK(curr_data); + ABSL_CHECK(curr_data); return curr_data->frame; } void RegionFlowComputation::GetFeatureTrackInliers( bool skip_estimation, TrackedFeatureList* features, TrackedFeatureView* inliers) const { - CHECK(features != nullptr); - CHECK(inliers != nullptr); + ABSL_CHECK(features != nullptr); + ABSL_CHECK(inliers != nullptr); inliers->clear(); if (skip_estimation) { inliers->reserve(features->size()); @@ -1232,9 +1235,9 @@ void RegionFlowComputation::GetFeatureTrackInliers( float RegionFlowComputation::ComputeVisualConsistency( FrameTrackingData* previous, FrameTrackingData* current) const { - CHECK_EQ(previous->frame_num + 1, current->frame_num); + ABSL_CHECK_EQ(previous->frame_num + 1, current->frame_num); const int total = previous->tiny_image.total(); - CHECK_GT(total, 0) << "Tiny image dimension set to zero."; + ABSL_CHECK_GT(total, 0) << "Tiny image dimension set to zero."; current->tiny_image_diff = FrameDifferenceMedian(previous->tiny_image, current->tiny_image) * (1.0f / total); @@ -1267,10 +1270,10 @@ void RegionFlowComputation::ComputeRegionFlow( } else { const int index1 = data_queue_.size() + from - 1; const int index2 = data_queue_.size() + to - 1; - CHECK_GE(index1, 0); - CHECK_LT(index1, data_queue_.size()); - CHECK_GE(index2, 0); - CHECK_LT(index2, data_queue_.size()); + ABSL_CHECK_GE(index1, 0); + ABSL_CHECK_LT(index1, data_queue_.size()); + ABSL_CHECK_GE(index2, 0); + ABSL_CHECK_LT(index2, data_queue_.size()); data1 = data_queue_[index1].get(); data2 = data_queue_[index2].get(); @@ -1302,7 +1305,7 @@ void RegionFlowComputation::ComputeRegionFlow( bool track_features = true; bool force_feature_extraction_next_frame = false; if (options_.tracking_options().wide_baseline_matching()) { - CHECK(initial_transform == nullptr) + ABSL_CHECK(initial_transform == nullptr) << "Can't use wide baseline matching and initial transform as the " << "same time."; @@ -1615,14 +1618,14 @@ class GridFeatureLocator { // or adds K to the existing mask if add is set to true. template inline void SetMaskNeighborhood(int mask_x, int mask_y, cv::Mat* mask) { - DCHECK_EQ(mask->type(), CV_8U); + ABSL_DCHECK_EQ(mask->type(), CV_8U); const int mask_start_x = max(0, mask_x - N); const int mask_end_x = min(mask->cols - 1, mask_x + N); const int mask_dx = mask_end_x - mask_start_x + 1; const int mask_start_y = max(0, mask_y - N); const int mask_end_y = min(mask->rows - 1, mask_y + N); - DCHECK_LE(mask_start_x, mask_end_x); - DCHECK_LE(mask_start_y, mask_end_y); + ABSL_DCHECK_LE(mask_start_x, mask_end_x); + ABSL_DCHECK_LE(mask_start_y, mask_end_y); if (!add) { for (int i = mask_start_y; i <= mask_end_y; ++i) { @@ -1644,9 +1647,9 @@ inline void SetMaskNeighborhood(int mask_x, int mask_y, cv::Mat* mask) { void RegionFlowComputation::AdaptiveGoodFeaturesToTrack( const std::vector& extraction_pyramid, int max_features, float mask_scale, cv::Mat* mask, FrameTrackingData* data) { - CHECK(data != nullptr); - CHECK(feature_tmp_image_1_.get() != nullptr); - CHECK(feature_tmp_image_2_.get() != nullptr); + ABSL_CHECK(data != nullptr); + ABSL_CHECK(feature_tmp_image_1_.get() != nullptr); + ABSL_CHECK(feature_tmp_image_2_.get() != nullptr); cv::Mat* eig_image = feature_tmp_image_1_.get(); cv::Mat* tmp_image = feature_tmp_image_2_.get(); @@ -1655,7 +1658,7 @@ void RegionFlowComputation::AdaptiveGoodFeaturesToTrack( // Setup grid information. const float block_size = tracking_options.adaptive_features_block_size(); - CHECK_GT(block_size, 0) << "Need positive block size"; + ABSL_CHECK_GT(block_size, 0) << "Need positive block size"; int block_width = block_size < 1 ? block_size * frame_width_ : block_size; int block_height = block_size < 1 ? block_size * frame_height_ : block_size; @@ -1707,8 +1710,8 @@ void RegionFlowComputation::AdaptiveGoodFeaturesToTrack( std::vector fast_keypoints; if (e == 0) { MEASURE_TIME << "Corner extraction"; - CHECK_EQ(rows, frame_height_); - CHECK_EQ(cols, frame_width_); + ABSL_CHECK_EQ(rows, frame_height_); + ABSL_CHECK_EQ(cols, frame_width_); if (use_fast) { fast_detector->detect(image, fast_keypoints); @@ -1720,8 +1723,8 @@ void RegionFlowComputation::AdaptiveGoodFeaturesToTrack( } else { // Compute corner response on a down-scaled image and upsample. step *= 2; - CHECK_EQ(rows, (extraction_pyramid[e - 1].rows + 1) / 2); - CHECK_EQ(cols, (extraction_pyramid[e - 1].cols + 1) / 2); + ABSL_CHECK_EQ(rows, (extraction_pyramid[e - 1].rows + 1) / 2); + ABSL_CHECK_EQ(cols, (extraction_pyramid[e - 1].cols + 1) / 2); if (use_fast) { fast_detector->detect(image, fast_keypoints); @@ -1889,7 +1892,7 @@ void RegionFlowComputation::AdaptiveGoodFeaturesToTrack( AffineModel RegionFlowComputation::AffineModelFromFeatures( TrackedFeatureList* features) const { - CHECK(features != nullptr); + ABSL_CHECK(features != nullptr); // Downscaled domain as output. MotionEstimation motion_estimation(MotionEstimationOptions(), frame_width_, @@ -1912,7 +1915,7 @@ AffineModel RegionFlowComputation::AffineModelFromFeatures( void RegionFlowComputation::ZeroMotionGridFeatures( int frame_width, int frame_height, float frac_grid_step_x, float frac_grid_step_y, RegionFlowFeatureList* result) { - CHECK(result != nullptr); + ABSL_CHECK(result != nullptr); result->Clear(); TrackedFeatureList features; @@ -1935,7 +1938,7 @@ void RegionFlowComputation::ZeroMotionGridFeatures( void RegionFlowComputation::DenseZeroMotionSamples( int frame_width, int frame_height, float frac_diameter, float frac_steps_x, float frac_steps_y, RegionFlowFeatureList* result) { - CHECK(result != nullptr); + ABSL_CHECK(result != nullptr); // Ensure patch fits into frame. const int radius = @@ -1982,7 +1985,7 @@ int RegionFlowComputation::ZeroMotionGridTracks(int frame_width, float frac_grid_step_x, float frac_grid_step_y, TrackedFeatureList* results) { - CHECK(results); + ABSL_CHECK(results); auto& tracked_features = *results; tracked_features.clear(); @@ -2018,9 +2021,9 @@ bool RegionFlowComputation::GainCorrectFrame(const cv::Mat& reference_frame, float reference_mean, float input_mean, cv::Mat* calibrated_frame) const { - CHECK(calibrated_frame); - CHECK_EQ(reference_frame.rows, input_frame.rows); - CHECK_EQ(reference_frame.cols, input_frame.cols); + ABSL_CHECK(calibrated_frame); + ABSL_CHECK_EQ(reference_frame.rows, input_frame.rows); + ABSL_CHECK_EQ(reference_frame.cols, input_frame.cols); // Do not attempt gain correction for tiny images. if (std::min(reference_frame.rows, reference_frame.cols) < 10) { @@ -2184,12 +2187,12 @@ void RegionFlowComputation::WideBaselineMatchFeatures( void RegionFlowComputation::RemoveAbsentFeatures( const TrackedFeatureList& prev_result, FrameTrackingData* data) { - CHECK(long_track_data_ != nullptr); + ABSL_CHECK(long_track_data_ != nullptr); // Build hash set of track ids. absl::node_hash_set track_ids; for (const auto& feature : prev_result) { - DCHECK_NE(feature.track_id, -1); + ABSL_DCHECK_NE(feature.track_id, -1); track_ids.insert(feature.track_id); } @@ -2237,8 +2240,8 @@ void RegionFlowComputation::ExtractFeatures( if (data->last_feature_extraction_time == 0) { // Features already extracted from this frame. - CHECK_EQ(data->corner_responses.size(), data->features.size()); - CHECK_EQ(data->octaves.size(), data->features.size()); + ABSL_CHECK_EQ(data->corner_responses.size(), data->features.size()); + ABSL_CHECK_EQ(data->octaves.size(), data->features.size()); VLOG(1) << "Features already present (extracted from this frame)"; return; } @@ -2246,8 +2249,8 @@ void RegionFlowComputation::ExtractFeatures( // Remove features that lie outside feature extraction mask. RemoveFeaturesOutsideMask(data); - CHECK_EQ(data->corner_responses.size(), data->features.size()); - CHECK_EQ(data->octaves.size(), data->features.size()); + ABSL_CHECK_EQ(data->corner_responses.size(), data->features.size()); + ABSL_CHECK_EQ(data->octaves.size(), data->features.size()); float feature_fraction = 0; if (data->num_original_extracted_and_tracked > 0) { @@ -2313,7 +2316,7 @@ void RegionFlowComputation::ExtractFeatures( data->neighborhoods->reserve(features_to_allocate); } - CHECK_EQ(data->extraction_pyramid.size(), extraction_levels_); + ABSL_CHECK_EQ(data->extraction_pyramid.size(), extraction_levels_); for (int i = 1; i < extraction_levels_; ++i) { // Need factor 2 as OpenCV stores image + gradient pairs when // "with_derivative" is set to true. @@ -2333,7 +2336,7 @@ void RegionFlowComputation::ExtractFeatures( if (prev_result) { // Seed feature mask and results with tracking ids. - CHECK(long_track_data_ != nullptr); + ABSL_CHECK(long_track_data_ != nullptr); const int max_track_length = options_.tracking_options().long_tracks_max_frames(); // Drop a feature with a propability X, such that all qualifying @@ -2361,8 +2364,8 @@ void RegionFlowComputation::ExtractFeatures( // For FORWARD output flow, we need to add flow to obtain the match // position, for BACKWARD output flow, flow is inverted, so that feature // locations already point to locations in the current frame. - CHECK_EQ(options_.tracking_options().internal_tracking_direction(), - TrackingOptions::FORWARD); + ABSL_CHECK_EQ(options_.tracking_options().internal_tracking_direction(), + TrackingOptions::FORWARD); float match_sign = options_.tracking_options().output_flow_direction() == TrackingOptions::FORWARD ? 1.0f @@ -2430,9 +2433,9 @@ void RegionFlowComputation::ExtractFeatures( mask_scale, &mask, data); const int num_features = data->features.size(); - CHECK_EQ(num_features, data->octaves.size()); - CHECK_EQ(num_features, data->corner_responses.size()); - CHECK_EQ(num_features, data->track_ids.size()); + ABSL_CHECK_EQ(num_features, data->octaves.size()); + ABSL_CHECK_EQ(num_features, data->corner_responses.size()); + ABSL_CHECK_EQ(num_features, data->track_ids.size()); } // Selects features based on lambda evaluator: bool (int index) @@ -2443,23 +2446,23 @@ int RegionFlowComputation::InplaceFeatureSelection( std::vector*> float_vecs, const Eval& eval) { int num_selected_features = 0; const int num_features = data->features.size(); - DCHECK_EQ(num_features, data->corner_responses.size()); - DCHECK_EQ(num_features, data->octaves.size()); - DCHECK_EQ(num_features, data->track_ids.size()); - DCHECK_EQ(num_features, data->feature_source_map.size()); + ABSL_DCHECK_EQ(num_features, data->corner_responses.size()); + ABSL_DCHECK_EQ(num_features, data->octaves.size()); + ABSL_DCHECK_EQ(num_features, data->track_ids.size()); + ABSL_DCHECK_EQ(num_features, data->feature_source_map.size()); if (data->neighborhoods != nullptr) { - DCHECK_EQ(num_features, data->neighborhoods->size()); + ABSL_DCHECK_EQ(num_features, data->neighborhoods->size()); } for (const auto vec_ptr : int_vecs) { - DCHECK_EQ(num_features, vec_ptr->size()); + ABSL_DCHECK_EQ(num_features, vec_ptr->size()); } for (const auto vec_ptr : float_vecs) { - DCHECK_EQ(num_features, vec_ptr->size()); + ABSL_DCHECK_EQ(num_features, vec_ptr->size()); } for (int i = 0; i < num_features; ++i) { - DCHECK_LE(num_selected_features, i); + ABSL_DCHECK_LE(num_selected_features, i); if (eval(i)) { data->features[num_selected_features] = data->features[i]; data->corner_responses[num_selected_features] = data->corner_responses[i]; @@ -2553,14 +2556,14 @@ void RegionFlowComputation::TrackFeatures(FrameTrackingData* from_data_ptr, octaves2.resize(num_features); data2.source = from_data_ptr; } else { - CHECK_EQ(data2.source, from_data_ptr); - CHECK_EQ(num_features, features2.size()); + ABSL_CHECK_EQ(data2.source, from_data_ptr); + ABSL_CHECK_EQ(num_features, features2.size()); tracking_flags |= cv::OPTFLOW_USE_INITIAL_FLOW; } const int track_win_size = options_.tracking_options().tracking_window_size(); - CHECK_GT(track_win_size, 1) << "Needs to be at least 2 pixels in each " - << "direction"; + ABSL_CHECK_GT(track_win_size, 1) << "Needs to be at least 2 pixels in each " + << "direction"; // Proceed with gain correction only if it succeeds, and set flag accordingly. bool frame1_gain_reference = true; @@ -2644,7 +2647,7 @@ void RegionFlowComputation::TrackFeatures(FrameTrackingData* from_data_ptr, // Init neighborhoods if needed. if (IsVerifyLongFeatures()) { // data1 should be initialized at this point. - CHECK(data1.neighborhoods != nullptr); + ABSL_CHECK(data1.neighborhoods != nullptr); if (data2.neighborhoods == nullptr) { data2.neighborhoods.reset(new std::vector()); data2.neighborhoods->resize(num_valid_features); @@ -2950,17 +2953,17 @@ void RegionFlowComputation::InitializeFeatureLocationsFromTransform( void RegionFlowComputation::InitializeFeatureLocationsFromPreviousResult( int from, int to) { - CHECK_NE(from, to) << "Cannot initialize FrameTrackingData from itself."; + ABSL_CHECK_NE(from, to) << "Cannot initialize FrameTrackingData from itself."; const int index1 = data_queue_.size() + from - 1; const int index2 = data_queue_.size() + to - 1; - CHECK_GE(index1, 0); - CHECK_LT(index1, data_queue_.size()); - CHECK_GE(index2, 0); - CHECK_LT(index2, data_queue_.size()); + ABSL_CHECK_GE(index1, 0); + ABSL_CHECK_LT(index1, data_queue_.size()); + ABSL_CHECK_GE(index2, 0); + ABSL_CHECK_LT(index2, data_queue_.size()); const FrameTrackingData& data1 = *data_queue_[index1]; FrameTrackingData* data2 = data_queue_[index2].get(); - CHECK(data1.source != nullptr); + ABSL_CHECK(data1.source != nullptr); if (!data1.features_initialized) { data2->features = data1.source->features; @@ -2969,7 +2972,7 @@ void RegionFlowComputation::InitializeFeatureLocationsFromPreviousResult( } } else { data2->features = data1.features; - CHECK_EQ(data1.features.size(), data1.source->features.size()); + ABSL_CHECK_EQ(data1.features.size(), data1.source->features.size()); } data2->source = data1.source; data2->features_initialized = true; @@ -3142,7 +3145,7 @@ void RegionFlowComputation::ComputeBlockBasedFlow( void RegionFlowComputation::DetermineRegionFlowInliers( const TrackedFeatureMap& region_feature_map, TrackedFeatureView* inliers) const { - CHECK(inliers); + ABSL_CHECK(inliers); inliers->clear(); // Run RANSAC on each region. @@ -3245,7 +3248,7 @@ int RegionFlowComputation::GetMinNumFeatureInliers( total_features += region_features.size(); } - CHECK(!region_feature_map.empty()) + ABSL_CHECK(!region_feature_map.empty()) << "Empty grid passed. Check input dimensions"; const float threshold = @@ -3258,7 +3261,7 @@ int RegionFlowComputation::GetMinNumFeatureInliers( void RegionFlowComputation::RegionFlowFeatureListToRegionFlow( const RegionFlowFeatureList& feature_list, RegionFlowFrame* frame) const { - CHECK(frame != nullptr); + ABSL_CHECK(frame != nullptr); frame->set_num_total_features(feature_list.feature_size()); frame->set_unstable_frame(feature_list.unstable()); diff --git a/mediapipe/util/tracking/region_flow_computation_test.cc b/mediapipe/util/tracking/region_flow_computation_test.cc index e707356fc..40a1ed54b 100644 --- a/mediapipe/util/tracking/region_flow_computation_test.cc +++ b/mediapipe/util/tracking/region_flow_computation_test.cc @@ -22,6 +22,7 @@ #include #include "absl/flags/flag.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/time/clock.h" #include "mediapipe/framework/deps/file_path.h" @@ -104,8 +105,8 @@ INSTANTIATE_TEST_SUITE_P(FlowDirection, RegionFlowComputationTest, void RegionFlowComputationTest::MakeMovie( int num_frames, RegionFlowComputationOptions::ImageFormat format, std::vector* movie, std::vector* positions) { - CHECK(positions != nullptr); - CHECK(movie != nullptr); + ABSL_CHECK(positions != nullptr); + ABSL_CHECK(movie != nullptr); const int border = 40; int frame_width = original_frame_.cols - 2 * border; @@ -178,7 +179,7 @@ void RegionFlowComputationTest::MakeMovie( void RegionFlowComputationTest::GetResizedFrame(int width, int height, cv::Mat* result) const { - CHECK(result != nullptr); + ABSL_CHECK(result != nullptr); cv::resize(original_frame_, *result, cv::Size(width, height)); } diff --git a/mediapipe/util/tracking/region_flow_visualization.cc b/mediapipe/util/tracking/region_flow_visualization.cc index dc067da7c..901dce19f 100644 --- a/mediapipe/util/tracking/region_flow_visualization.cc +++ b/mediapipe/util/tracking/region_flow_visualization.cc @@ -19,6 +19,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/strings/str_cat.h" #include "mediapipe/framework/port/integral_types.h" #include "mediapipe/util/tracking/measure_time.h" @@ -47,7 +48,7 @@ void VisualizeRegionFlowImpl(const RegionFlowFrame& region_flow_frame, void VisualizeRegionFlow(const RegionFlowFrame& region_flow_frame, cv::Mat* output) { - CHECK(output); + ABSL_CHECK(output); VisualizeRegionFlowImpl(region_flow_frame, output); } @@ -118,7 +119,7 @@ void VisualizeRegionFlowFeatures(const RegionFlowFeatureList& feature_list, const cv::Scalar& outlier, bool irls_visualization, float scale_x, float scale_y, cv::Mat* output) { - CHECK(output); + ABSL_CHECK(output); VisualizeRegionFlowFeaturesImpl(feature_list, color, outlier, irls_visualization, scale_x, scale_y, output); } @@ -138,7 +139,7 @@ void VisualizeLongFeatureStreamImpl(const LongFeatureStream& stream, if (min_track_length > 0 && pts.size() < min_track_length) { continue; } - CHECK_GT(pts.size(), 1); // Should have at least two points per track. + ABSL_CHECK_GT(pts.size(), 1); // Should have at least two points per track. // Tracks are ordered with oldest point first, most recent one last. const int start_k = @@ -186,7 +187,7 @@ void VisualizeLongFeatureStream(const LongFeatureStream& stream, const cv::Scalar& outlier, int min_track_length, int max_points_per_track, float scale_x, float scale_y, cv::Mat* output) { - CHECK(output); + ABSL_CHECK(output); VisualizeLongFeatureStreamImpl(stream, color, outlier, min_track_length, max_points_per_track, scale_x, scale_y, diff --git a/mediapipe/util/tracking/streaming_buffer.cc b/mediapipe/util/tracking/streaming_buffer.cc index 169c76a04..218ca0467 100644 --- a/mediapipe/util/tracking/streaming_buffer.cc +++ b/mediapipe/util/tracking/streaming_buffer.cc @@ -14,6 +14,7 @@ #include "mediapipe/util/tracking/streaming_buffer.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/strings/str_cat.h" @@ -22,9 +23,9 @@ namespace mediapipe { StreamingBuffer::StreamingBuffer( const std::vector& data_configuration, int overlap) : overlap_(overlap) { - CHECK_GE(overlap, 0); + ABSL_CHECK_GE(overlap, 0); for (auto& item : data_configuration) { - CHECK(data_config_.find(item.first) == data_config_.end()) + ABSL_CHECK(data_config_.find(item.first) == data_config_.end()) << "Tag " << item.first << " already exists"; data_config_[item.first] = item.second; // Init deque. @@ -46,7 +47,7 @@ bool StreamingBuffer::HasTags(const std::vector& tags) const { } int StreamingBuffer::BufferSize(const std::string& tag) const { - CHECK(HasTag(tag)); + ABSL_CHECK(HasTag(tag)); return data_.find(tag)->second.size(); } @@ -120,7 +121,7 @@ bool StreamingBuffer::TruncateBuffer(bool flush) { } void StreamingBuffer::DiscardDatum(const std::string& tag, int num_frames) { - CHECK(HasTag(tag)); + ABSL_CHECK(HasTag(tag)); auto& queue = data_[tag]; if (queue.empty()) { return; @@ -131,7 +132,7 @@ void StreamingBuffer::DiscardDatum(const std::string& tag, int num_frames) { void StreamingBuffer::DiscardDatumFromEnd(const std::string& tag, int num_frames) { - CHECK(HasTag(tag)); + ABSL_CHECK(HasTag(tag)); auto& queue = data_[tag]; if (queue.empty()) { return; diff --git a/mediapipe/util/tracking/streaming_buffer.h b/mediapipe/util/tracking/streaming_buffer.h index f7cbaa875..ea4a5f274 100644 --- a/mediapipe/util/tracking/streaming_buffer.h +++ b/mediapipe/util/tracking/streaming_buffer.h @@ -23,8 +23,8 @@ #include #include "absl/container/node_hash_map.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" -#include "absl/log/check.h" #include "absl/types/any.h" #include "mediapipe/framework/tool/type_util.h" @@ -78,7 +78,7 @@ namespace mediapipe { // // Reached chunk boundary? // if (buffer_size == 100) { // // Check that we buffered one frame for each motion. -// CHECK(streaming_buffer.HaveEqualSize({"frame", "motion"})); +// ABSL_CHECK(streaming_buffer.HaveEqualSize({"frame", "motion"})); // // // Compute saliency. // for (int k = 0; k < 100; ++k) { @@ -297,7 +297,7 @@ class StreamingBuffer { // Terminates recursive template expansion for AddDataImpl. Will never be // called. void AddDataImpl(const std::vector& tags) { - CHECK(tags.empty()); + ABSL_CHECK(tags.empty()); } private: @@ -324,8 +324,8 @@ StreamingBuffer::PointerType StreamingBuffer::CreatePointer(T* t) { template void StreamingBuffer::AddDatum(const std::string& tag, std::unique_ptr pointer) { - CHECK(HasTag(tag)); - CHECK_EQ(data_config_[tag], kTypeId>.hash_code()); + ABSL_CHECK(HasTag(tag)); + ABSL_CHECK_EQ(data_config_[tag], kTypeId>.hash_code()); auto& buffer = data_[tag]; absl::any packet(PointerType(CreatePointer(pointer.release()))); buffer.push_back(packet); @@ -345,7 +345,7 @@ void StreamingBuffer::AddDatumCopy(const std::string& tag, const T& datum) { template void StreamingBuffer::AddData(const std::vector& tags, std::unique_ptr... pointers) { - CHECK_EQ(tags.size(), sizeof...(pointers)) + ABSL_CHECK_EQ(tags.size(), sizeof...(pointers)) << "Number of tags and data pointers is inconsistent"; return AddDataImpl(tags, std::move(pointers)...); } @@ -388,8 +388,8 @@ T& StreamingBuffer::GetDatumRef(const std::string& tag, int frame_index) const { template T* StreamingBuffer::GetMutableDatum(const std::string& tag, int frame_index) const { - CHECK_GE(frame_index, 0); - CHECK(HasTag(tag)); + ABSL_CHECK_GE(frame_index, 0); + ABSL_CHECK(HasTag(tag)); auto& buffer = data_.find(tag)->second; if (frame_index > buffer.size()) { return nullptr; @@ -441,12 +441,12 @@ StreamingBuffer::GetConstReferenceVector(const std::string& tag) const { template bool StreamingBuffer::IsInitialized(const std::string& tag) const { - CHECK(HasTag(tag)); + ABSL_CHECK(HasTag(tag)); const auto& buffer = data_.find(tag)->second; int idx = 0; for (const auto& item : buffer) { const PointerType* pointer = absl::any_cast>(&item); - CHECK(pointer != nullptr); + ABSL_CHECK(pointer != nullptr); if (*pointer == nullptr) { ABSL_LOG(ERROR) << "Data for " << tag << " at frame " << idx << " is not initialized."; @@ -459,7 +459,7 @@ bool StreamingBuffer::IsInitialized(const std::string& tag) const { template std::vector StreamingBuffer::GetMutableDatumVector( const std::string& tag) const { - CHECK(HasTag(tag)); + ABSL_CHECK(HasTag(tag)); auto& buffer = data_.find(tag)->second; std::vector result; for (const auto& packet : buffer) { @@ -478,7 +478,7 @@ std::vector StreamingBuffer::GetMutableDatumVector( template void StreamingBuffer::OutputDatum(bool flush, const std::string& tag, const Functor& functor) { - CHECK(HasTag(tag)); + ABSL_CHECK(HasTag(tag)); const int end_frame = MaxBufferSize() - (flush ? 0 : overlap_); for (int k = 0; k < end_frame; ++k) { functor(k, ReleaseDatum(tag, k)); @@ -488,8 +488,8 @@ void StreamingBuffer::OutputDatum(bool flush, const std::string& tag, template std::unique_ptr StreamingBuffer::ReleaseDatum(const std::string& tag, int frame_index) { - CHECK(HasTag(tag)); - CHECK_GE(frame_index, 0); + ABSL_CHECK(HasTag(tag)); + ABSL_CHECK_GE(frame_index, 0); auto& buffer = data_.find(tag)->second; if (frame_index >= buffer.size()) { diff --git a/mediapipe/util/tracking/tone_estimation.cc b/mediapipe/util/tracking/tone_estimation.cc index 2e83ced0a..2f2c23562 100644 --- a/mediapipe/util/tracking/tone_estimation.cc +++ b/mediapipe/util/tracking/tone_estimation.cc @@ -21,6 +21,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "mediapipe/util/tracking/motion_models.pb.h" #include "mediapipe/util/tracking/tone_models.pb.h" @@ -59,7 +60,7 @@ ToneEstimation::ToneEstimation(const ToneEstimationOptions& options, break; } case ToneEstimationOptions::DOWNSAMPLE_BY_FACTOR: { - CHECK_GE(options_.downsample_factor(), 1); + ABSL_CHECK_GE(options_.downsample_factor(), 1); frame_width_ /= options_.downsample_factor(); frame_height_ /= options_.downsample_factor(); downsample_scale_ = options_.downsample_factor(); @@ -81,9 +82,9 @@ void ToneEstimation::EstimateToneChange( const RegionFlowFeatureList& feature_list_input, const cv::Mat& curr_frame_input, const cv::Mat* prev_frame_input, ToneChange* tone_change, cv::Mat* debug_output) { - CHECK_EQ(original_height_, curr_frame_input.rows); - CHECK_EQ(original_width_, curr_frame_input.cols); - CHECK(tone_change != nullptr); + ABSL_CHECK_EQ(original_height_, curr_frame_input.rows); + ABSL_CHECK_EQ(original_width_, curr_frame_input.cols); + ABSL_CHECK(tone_change != nullptr); const cv::Mat& curr_frame = use_downsampling_ ? *resized_input_ : curr_frame_input; @@ -107,8 +108,8 @@ void ToneEstimation::EstimateToneChange( TransformRegionFlowFeatureList(scale_transform, &scaled_feature_list); } - CHECK_EQ(frame_height_, curr_frame.rows); - CHECK_EQ(frame_width_, curr_frame.cols); + ABSL_CHECK_EQ(frame_height_, curr_frame.rows); + ABSL_CHECK_EQ(frame_width_, curr_frame.cols); ClipMask<3> curr_clip; ComputeClipMask<3>(options_.clip_mask_options(), curr_frame, &curr_clip); @@ -213,15 +214,15 @@ void ToneEstimation::IntensityPercentiles(const cv::Mat& frame, void ToneEstimation::EstimateGainBiasModel(int irls_iterations, ColorToneMatches* color_tone_matches, GainBiasModel* gain_bias_model) { - CHECK(color_tone_matches != nullptr); - CHECK(gain_bias_model != nullptr); + ABSL_CHECK(color_tone_matches != nullptr); + ABSL_CHECK(gain_bias_model != nullptr); // Effectively estimate each model independently. float solution_ptr[6] = {1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f}; const int num_channels = color_tone_matches->size(); - CHECK_GT(num_channels, 0); - CHECK_LE(num_channels, 3); + ABSL_CHECK_GT(num_channels, 0); + ABSL_CHECK_LE(num_channels, 3); // TODO: One IRLS weight per color match. for (int c = 0; c < num_channels; ++c) { diff --git a/mediapipe/util/tracking/tone_estimation.h b/mediapipe/util/tracking/tone_estimation.h index 0fa049e2b..3d7defd2e 100644 --- a/mediapipe/util/tracking/tone_estimation.h +++ b/mediapipe/util/tracking/tone_estimation.h @@ -25,6 +25,7 @@ #include #include +#include "absl/log/absl_check.h" #include "mediapipe/framework/port/integral_types.h" #include "mediapipe/framework/port/logging.h" #include "mediapipe/framework/port/opencv_core_inc.h" @@ -150,8 +151,8 @@ template void ToneEstimation::ComputeClipMask(const ClipMaskOptions& options, const cv::Mat& frame, ClipMask* clip_mask) { - CHECK(clip_mask != nullptr); - CHECK_EQ(frame.channels(), C); + ABSL_CHECK(clip_mask != nullptr); + ABSL_CHECK_EQ(frame.channels(), C); // Over / Underexposure handling. // Masks pixels affected by clipping. @@ -163,7 +164,7 @@ void ToneEstimation::ComputeClipMask(const ClipMaskOptions& options, std::vector planes; cv::split(frame, planes); - CHECK_EQ(C, planes.size()); + ABSL_CHECK_EQ(C, planes.size()); float min_exposure[C]; float max_exposure[C]; for (int c = 0; c < C; ++c) { @@ -223,9 +224,9 @@ void ToneEstimation::ComputeToneMatches( const ClipMask& curr_clip_mask, // Optional. const ClipMask& prev_clip_mask, // Optional. ColorToneMatches* color_tone_matches, cv::Mat* debug_output) { - CHECK(color_tone_matches != nullptr); - CHECK_EQ(curr_frame.channels(), C); - CHECK_EQ(prev_frame.channels(), C); + ABSL_CHECK(color_tone_matches != nullptr); + ABSL_CHECK_EQ(curr_frame.channels(), C); + ABSL_CHECK_EQ(prev_frame.channels(), C); color_tone_matches->clear(); color_tone_matches->resize(C); diff --git a/mediapipe/util/tracking/tone_models.cc b/mediapipe/util/tracking/tone_models.cc index 9410834bd..ecc59d4b8 100644 --- a/mediapipe/util/tracking/tone_models.cc +++ b/mediapipe/util/tracking/tone_models.cc @@ -16,6 +16,7 @@ #include +#include "absl/log/absl_check.h" #include "absl/strings/str_format.h" namespace mediapipe { @@ -47,13 +48,13 @@ void ToneModelMethods::MapImage(const Model& model, bool normalized_model, const cv::Mat& input, cv::Mat* output) { - CHECK(output != nullptr); + ABSL_CHECK(output != nullptr); const int out_channels = output->channels(); - CHECK_EQ(input.channels(), 3); - CHECK_LE(out_channels, 3); - CHECK_EQ(input.rows, output->rows); - CHECK_EQ(input.cols, output->cols); + ABSL_CHECK_EQ(input.channels(), 3); + ABSL_CHECK_LE(out_channels, 3); + ABSL_CHECK_EQ(input.rows, output->rows); + ABSL_CHECK_EQ(input.cols, output->cols); float norm_scale = normalized_model diff --git a/mediapipe/util/tracking/tone_models.h b/mediapipe/util/tracking/tone_models.h index 8d2d3c152..bcbf15854 100644 --- a/mediapipe/util/tracking/tone_models.h +++ b/mediapipe/util/tracking/tone_models.h @@ -23,6 +23,7 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "mediapipe/framework/port/integral_types.h" #include "mediapipe/framework/port/opencv_core_inc.h" @@ -246,7 +247,7 @@ typedef MixtureToneAdapter MixtureAffineToneModelAdapter; template GainBiasModel ToneModelAdapter::FromPointer(const T* args, bool identity) { - DCHECK(args); + ABSL_DCHECK(args); GainBiasModel model; const float id_shift = identity ? 1.0f : 0.0f; model.set_gain_c1(args[0] + id_shift); @@ -346,7 +347,7 @@ inline float ToneModelAdapter::GetParameter( template AffineToneModel ToneModelAdapter::FromPointer(const T* args, bool identity) { - DCHECK(args); + ABSL_DCHECK(args); AffineToneModel model; const float id_shift = identity ? 1.0f : 0.0f; model.set_g_00(args[0] + id_shift); @@ -369,7 +370,7 @@ AffineToneModel ToneModelAdapter::FromPointer(const T* args, template void ToneModelAdapter::ToPointerPad( const AffineToneModel& model, bool pad_square, T* args) { - DCHECK(args); + ABSL_DCHECK(args); args[0] = model.g_00(); args[1] = model.g_01(); args[2] = model.g_02(); @@ -592,9 +593,9 @@ template void ToneModelMethods::MapImageIndependent( const Model& model, bool log_domain, bool normalized_model, const cv::Mat& input, cv::Mat* output) { - CHECK(output != nullptr); - CHECK_EQ(input.channels(), C); - CHECK_EQ(output->channels(), C); + ABSL_CHECK(output != nullptr); + ABSL_CHECK_EQ(input.channels(), C); + ABSL_CHECK_EQ(output->channels(), C); // Input LUT which will be mapped to the output LUT by the tone change model. // Needs 3 channels to represent input RGB colors, but since they are assumed diff --git a/mediapipe/util/tracking/tracking.cc b/mediapipe/util/tracking/tracking.cc index 9c6b36507..7c9bfa700 100644 --- a/mediapipe/util/tracking/tracking.cc +++ b/mediapipe/util/tracking/tracking.cc @@ -25,6 +25,7 @@ #include "Eigen/Dense" #include "Eigen/SVD" #include "absl/algorithm/container.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/memory/memory.h" #include "mediapipe/framework/port/logging.h" @@ -64,7 +65,7 @@ void StoreInternalState(const std::vector& vectors, const std::vector& inlier_weights, float aspect_ratio, MotionBoxInternalState* internal) { const int num_vectors = vectors.size(); - CHECK_EQ(num_vectors, inlier_weights.size()); + ABSL_CHECK_EQ(num_vectors, inlier_weights.size()); float scale_x = 1.0f; float scale_y = 1.0f; @@ -159,7 +160,7 @@ bool PointWithinInlierExtent(const Vector2_f pt, const MotionBoxState& state) { bool LinearSimilarityL2Solve( const std::vector& motion_vectors, const std::vector& weights, LinearSimilarityModel* model) { - CHECK(model); + ABSL_CHECK(model); if (motion_vectors.size() < 4) { ABSL_LOG(ERROR) << "Requiring at least 4 input vectors for sufficient solve."; @@ -173,7 +174,7 @@ bool LinearSimilarityL2Solve( matrix.setTo(0); rhs.setTo(0); - CHECK_EQ(motion_vectors.size(), weights.size()); + ABSL_CHECK_EQ(motion_vectors.size(), weights.size()); for (int k = 0; k < motion_vectors.size(); ++k) { const float x = motion_vectors[k]->pos.x(); const float y = motion_vectors[k]->pos.y(); @@ -236,7 +237,7 @@ bool LinearSimilarityL2Solve( // Taken from MotionEstimation::HomographyL2NormalEquationSolve bool HomographyL2Solve(const std::vector& motion_vectors, const std::vector& weights, Homography* model) { - CHECK(model); + ABSL_CHECK(model); cv::Mat matrix(8, 8, CV_32F); cv::Mat solution(8, 1, CV_32F); @@ -247,7 +248,7 @@ bool HomographyL2Solve(const std::vector& motion_vectors, // Matrix multiplications are hand-coded for speed improvements vs. // opencv's cvGEMM calls. - CHECK_EQ(motion_vectors.size(), weights.size()); + ABSL_CHECK_EQ(motion_vectors.size(), weights.size()); for (int k = 0; k < motion_vectors.size(); ++k) { const float x = motion_vectors[k]->pos.x(); const float y = motion_vectors[k]->pos.y(); @@ -376,7 +377,7 @@ bool HomographyL2Solve(const std::vector& motion_vectors, void TransformQuadInMotionBoxState(const MotionBoxState& curr_pos, const Homography& homography, MotionBoxState* next_pos) { - CHECK(next_pos != nullptr); + ABSL_CHECK(next_pos != nullptr); if (!curr_pos.has_pos_x() || !curr_pos.has_pos_y() || !curr_pos.has_width() || !curr_pos.has_height()) { ABSL_LOG(ERROR) << "Previous box does not exist, cannot transform!"; @@ -648,7 +649,7 @@ std::array MotionBoxCorners(const MotionBoxState& state, bool MotionBoxLines(const MotionBoxState& state, const Vector2_f& scaling, std::array* box_lines) { - CHECK(box_lines); + ABSL_CHECK(box_lines); std::array corners = MotionBoxCorners(state, scaling); for (int k = 0; k < 4; ++k) { const Vector2_f diff = corners[(k + 1) % 4] - corners[k]; @@ -668,8 +669,8 @@ bool MotionBoxLines(const MotionBoxState& state, const Vector2_f& scaling, void MotionBoxBoundingBox(const MotionBoxState& state, Vector2_f* top_left, Vector2_f* bottom_right) { - CHECK(top_left); - CHECK(bottom_right); + ABSL_CHECK(top_left); + ABSL_CHECK(bottom_right); std::array corners = MotionBoxCorners(state); @@ -690,7 +691,7 @@ void MotionBoxBoundingBox(const MotionBoxState& state, Vector2_f* top_left, void MotionBoxInlierLocations(const MotionBoxState& state, std::vector* inlier_pos) { - CHECK(inlier_pos); + ABSL_CHECK(inlier_pos); inlier_pos->clear(); for (int k = 0; k < state.inlier_id_match_pos_size(); k += 2) { inlier_pos->push_back( @@ -701,7 +702,7 @@ void MotionBoxInlierLocations(const MotionBoxState& state, void MotionBoxOutlierLocations(const MotionBoxState& state, std::vector* outlier_pos) { - CHECK(outlier_pos); + ABSL_CHECK(outlier_pos); outlier_pos->clear(); for (int k = 0; k < state.outlier_id_match_pos_size(); k += 2) { outlier_pos->push_back( @@ -739,7 +740,7 @@ std::array GetCornersOfRotatedRect(const MotionBoxState& state, } void InitializeQuadInMotionBoxState(MotionBoxState* state) { - CHECK(state != nullptr); + ABSL_CHECK(state != nullptr); // Every quad has 4 vertices. Each vertex has x and y 2 coordinates. So // a total of 8 floating point values. if (state->quad().vertices_size() != 8) { @@ -831,7 +832,7 @@ void InitializePnpHomographyInMotionBoxState( } const int kQuadCornersSize = 4; - CHECK_EQ(state->quad().vertices_size(), kQuadCornersSize * 2); + ABSL_CHECK_EQ(state->quad().vertices_size(), kQuadCornersSize * 2); float scale_x, scale_y; ScaleFromAspect(tracking.frame_aspect(), false, &scale_x, &scale_y); std::vector corners_2d(kQuadCornersSize); @@ -913,7 +914,7 @@ void InitializePnpHomographyInMotionBoxState( state->set_aspect_ratio(width_norm / height_norm); } - CHECK_GT(state->aspect_ratio(), 0.0f); + ABSL_CHECK_GT(state->aspect_ratio(), 0.0f); const float half_width = state->aspect_ratio(); const float half_height = 1.0f; @@ -976,7 +977,7 @@ void ScaleStateAspect(float aspect, bool invert, MotionBoxState* state) { MotionVector MotionVector::FromInternalState( const MotionBoxInternalState& internal, int index) { - CHECK_LT(index, internal.pos_x_size()); + ABSL_CHECK_LT(index, internal.pos_x_size()); MotionVector v; v.pos = Vector2_f(internal.pos_x(index), internal.pos_y(index)); v.object = Vector2_f(internal.dx(index), internal.dy(index)); @@ -1153,9 +1154,9 @@ void ComputeSpatialPrior(bool interpolate, bool use_next_position, std::vector old_confidence(update_pos->spatial_confidence().begin(), update_pos->spatial_confidence().end()); - CHECK_EQ(old_confidence.size(), old_prior.size()); - CHECK(old_confidence.empty() || - grid_size * grid_size == old_confidence.size()) + ABSL_CHECK_EQ(old_confidence.size(), old_prior.size()); + ABSL_CHECK(old_confidence.empty() || + grid_size * grid_size == old_confidence.size()) << "Empty or priors of constant size expected"; update_pos->clear_spatial_prior(); @@ -1195,10 +1196,10 @@ void ComputeSpatialPrior(bool interpolate, bool use_next_position, const int int_x = static_cast(grid_pos.x()); const int int_y = static_cast(grid_pos.y()); - CHECK_GE(grid_pos.x(), 0) << pos.x() << ", " << update_pos->pos_x(); - CHECK_GE(grid_pos.y(), 0); - CHECK_LE(grid_pos.x(), grid_size - 1); - CHECK_LE(grid_pos.y(), grid_size - 1); + ABSL_CHECK_GE(grid_pos.x(), 0) << pos.x() << ", " << update_pos->pos_x(); + ABSL_CHECK_GE(grid_pos.y(), 0); + ABSL_CHECK_LE(grid_pos.x(), grid_size - 1); + ABSL_CHECK_LE(grid_pos.y(), grid_size - 1); const float dx = grid_pos.x() - int_x; const float dy = grid_pos.y() - int_y; @@ -1284,9 +1285,9 @@ void MotionBox::GetStartPosition(const MotionBoxState& curr_pos, float aspect_ratio, float* expand_mag, Vector2_f* top_left, Vector2_f* bottom_right) const { - CHECK(top_left); - CHECK(bottom_right); - CHECK(expand_mag); + ABSL_CHECK(top_left); + ABSL_CHECK(bottom_right); + ABSL_CHECK(expand_mag); MotionBoxBoundingBox(curr_pos, top_left, bottom_right); @@ -1313,8 +1314,8 @@ void MotionBox::GetSpatialGaussWeights(const MotionBoxState& box_state, const Vector2_f& inv_box_domain, float* spatial_gauss_x, float* spatial_gauss_y) const { - CHECK(spatial_gauss_x); - CHECK(spatial_gauss_y); + ABSL_CHECK(spatial_gauss_x); + ABSL_CHECK(spatial_gauss_y); // Space sigma depends on how much the tracked object fills the rectangle. // We get this information from the inlier extent of the previous @@ -1343,7 +1344,7 @@ bool ComputeGridPositions(const Vector2_f& top_left, const Vector2_f& bottom_right, const std::vector& vectors, std::vector* grid_positions) { - CHECK(grid_positions); + ABSL_CHECK(grid_positions); // Slightly larger domain to avoid boundary issues. const Vector2_f inv_grid_domain( @@ -1434,8 +1435,8 @@ MotionBox::DistanceWeightsComputer::DistanceWeightsComputer( tracking_degrees_ = options.tracking_degrees(); const Vector2_f box_domain(current_state.width() * current_state.scale(), current_state.height() * current_state.scale()); - CHECK_GT(box_domain.x(), 0.0f); - CHECK_GT(box_domain.y(), 0.0f); + ABSL_CHECK_GT(box_domain.x(), 0.0f); + ABSL_CHECK_GT(box_domain.y(), 0.0f); inv_box_domain_ = Vector2_f(1.0f / box_domain.x(), 1.0f / box_domain.y()); // Space sigma depends on how much the tracked object fills the rectangle. @@ -1476,8 +1477,8 @@ MotionBox::DistanceWeightsComputer::DistanceWeightsComputer( std::min(kMaxBoxCenterBlendWeight, current_state.prior_weight())); if (tracking_degrees_ == TrackStepOptions::TRACKING_DEGREE_OBJECT_PERSPECTIVE) { - CHECK(initial_state.has_quad()); - CHECK(current_state.has_quad()); + ABSL_CHECK(initial_state.has_quad()); + ABSL_CHECK(current_state.has_quad()); homography_ = ComputeHomographyFromQuad(current_state.quad(), initial_state.quad()); box_center_transformed_ = @@ -1564,10 +1565,10 @@ bool MotionBox::GetVectorsAndWeights( const std::vector& history, std::vector* vectors, std::vector* weights, int* number_of_good_prior, int* number_of_cont_inliers) const { - CHECK(weights); - CHECK(vectors); - CHECK(number_of_good_prior); - CHECK(number_of_cont_inliers); + ABSL_CHECK(weights); + ABSL_CHECK(vectors); + ABSL_CHECK(number_of_good_prior); + ABSL_CHECK(number_of_cont_inliers); const int num_max_vectors = end_idx - start_idx; weights->clear(); @@ -1578,8 +1579,8 @@ bool MotionBox::GetVectorsAndWeights( const Vector2_f box_domain(box_state.width() * box_state.scale(), box_state.height() * box_state.scale()); - CHECK_GT(box_domain.x(), 0.0f); - CHECK_GT(box_domain.y(), 0.0f); + ABSL_CHECK_GT(box_domain.x(), 0.0f); + ABSL_CHECK_GT(box_domain.y(), 0.0f); const Vector2_f inv_box_domain(1.0f / box_domain.x(), 1.0f / box_domain.y()); // The four lines of the rotated and scaled box. @@ -1674,8 +1675,8 @@ bool MotionBox::GetVectorsAndWeights( is_outlier.push_back(is_outlier_flag); } - CHECK_EQ(vectors->size(), is_inlier.size()); - CHECK_EQ(vectors->size(), is_outlier.size()); + ABSL_CHECK_EQ(vectors->size(), is_inlier.size()); + ABSL_CHECK_EQ(vectors->size(), is_outlier.size()); const float prev_motion_mag = MotionBoxVelocity(box_state).Norm(); @@ -1818,7 +1819,7 @@ bool MotionBox::GetVectorsAndWeights( } const int num_vectors = vectors->size(); - CHECK_EQ(num_vectors, weights->size()); + ABSL_CHECK_EQ(num_vectors, weights->size()); const float weight_sum = std::accumulate(weights->begin(), weights->end(), 0.0f); @@ -1916,13 +1917,13 @@ void MotionBox::EstimateObjectMotion( const Vector2_f& irls_scale, std::vector* weights, Vector2_f* object_translation, LinearSimilarityModel* object_similarity, Homography* object_homography) const { - CHECK(object_translation); - CHECK(object_similarity); - CHECK(object_homography); + ABSL_CHECK(object_translation); + ABSL_CHECK(object_similarity); + ABSL_CHECK(object_homography); const int num_vectors = motion_vectors.size(); - CHECK_EQ(num_vectors, prior_weights.size()); - CHECK_EQ(num_vectors, weights->size()); + ABSL_CHECK_EQ(num_vectors, prior_weights.size()); + ABSL_CHECK_EQ(num_vectors, weights->size()); // Create backup of weights if needed. std::vector similarity_weights; @@ -2011,8 +2012,8 @@ void MotionBox::EstimateTranslation( const std::vector& motion_vectors, const std::vector& prior_weights, const Vector2_f& irls_scale, std::vector* weights, Vector2_f* translation) const { - CHECK(weights); - CHECK(translation); + ABSL_CHECK(weights); + ABSL_CHECK(translation); const int iterations = options_.irls_iterations(); @@ -2061,8 +2062,8 @@ bool MotionBox::EstimateSimilarity( const std::vector& motion_vectors, const std::vector& prior_weights, const Vector2_f& irls_scale, std::vector* weights, LinearSimilarityModel* lin_sim) const { - CHECK(weights); - CHECK(lin_sim); + ABSL_CHECK(weights); + ABSL_CHECK(lin_sim); const int iterations = options_.irls_iterations(); LinearSimilarityModel object_similarity; @@ -2101,7 +2102,7 @@ bool MotionBox::EstimateHomography( const std::vector& motion_vectors, const std::vector& prior_weights, const Vector2_f& irls_scale, std::vector* weights, Homography* object_homography) const { - CHECK(weights); + ABSL_CHECK(weights); const int iterations = options_.irls_iterations(); Homography homography; @@ -2311,12 +2312,12 @@ void MotionBox::ScoreAndRecordInliers( std::vector* inlier_weights, std::vector* inlier_density, int* continued_inliers, int* swapped_inliers, float* motion_inliers_out, float* kinetic_average_out) const { - CHECK(inlier_weights); - CHECK(inlier_density); - CHECK(continued_inliers); - CHECK(swapped_inliers); - CHECK(motion_inliers_out); - CHECK(kinetic_average_out); + ABSL_CHECK(inlier_weights); + ABSL_CHECK(inlier_density); + ABSL_CHECK(continued_inliers); + ABSL_CHECK(swapped_inliers); + ABSL_CHECK(motion_inliers_out); + ABSL_CHECK(kinetic_average_out); std::unordered_map prev_inliers; MotionBoxInliers(curr_pos, &prev_inliers); @@ -2437,15 +2438,15 @@ void MotionBox::ComputeInlierCenterAndExtent( const std::vector& weights, const std::vector& density, const MotionBoxState& box_state, float* min_inlier_sum, Vector2_f* center, Vector2_f* extent) const { - CHECK(min_inlier_sum); - CHECK(center); - CHECK(extent); + ABSL_CHECK(min_inlier_sum); + ABSL_CHECK(center); + ABSL_CHECK(extent); float weight_sum = 0; float inlier_sum = 0; const int num_vectors = motion_vectors.size(); - CHECK_EQ(num_vectors, weights.size()); - CHECK_EQ(num_vectors, density.size()); + ABSL_CHECK_EQ(num_vectors, weights.size()); + ABSL_CHECK_EQ(num_vectors, density.size()); Vector2_f first_moment(0.0f, 0.0f); Vector2_f second_moment(0.0f, 0.0f); @@ -2502,7 +2503,7 @@ float MotionBox::ScaleEstimate( const std::vector& motion_vectors, const std::vector& weights, float min_sum) const { const int num_vectors = motion_vectors.size(); - CHECK_EQ(num_vectors, weights.size()); + ABSL_CHECK_EQ(num_vectors, weights.size()); float scale_sum = 0; @@ -2656,7 +2657,7 @@ void MotionBox::TrackStepImplDeNormalized( const MotionVectorFrame& motion_frame, const std::vector& history, MotionBoxState* next_pos) const { - CHECK(next_pos); + ABSL_CHECK(next_pos); constexpr float kDefaultPeriodMs = 1000.0f / kTrackingDefaultFps; float temporal_scale = (motion_frame.duration_ms == 0) @@ -2797,7 +2798,7 @@ void MotionBox::TrackStepImplDeNormalized( VLOG(1) << "Good inits: " << num_good_inits; const int num_vectors = vectors.size(); - CHECK_EQ(num_vectors, prior_weights.size()); + ABSL_CHECK_EQ(num_vectors, prior_weights.size()); Vector2_f object_translation; @@ -3166,7 +3167,7 @@ void MotionBox::TrackStepImplDeNormalized( void MotionVectorFrameFromTrackingData(const TrackingData& tracking_data, MotionVectorFrame* motion_vector_frame) { - CHECK(motion_vector_frame != nullptr); + ABSL_CHECK(motion_vector_frame != nullptr); const auto& motion_data = tracking_data.motion_data(); float aspect_ratio = tracking_data.frame_aspect(); @@ -3294,7 +3295,7 @@ void FeatureAndDescriptorFromTrackingData( void InvertMotionVectorFrame(const MotionVectorFrame& input, MotionVectorFrame* output) { - CHECK(output != nullptr); + ABSL_CHECK(output != nullptr); output->background_model.CopyFrom(ModelInvert(input.background_model)); output->valid_background_model = input.valid_background_model; @@ -3347,7 +3348,7 @@ void GetFeatureIndicesWithinBox(const std::vector& features, const Vector2_f& box_scaling, float max_enlarge_size, int min_num_features, std::vector* inlier_indices) { - CHECK(inlier_indices); + ABSL_CHECK(inlier_indices); inlier_indices->clear(); if (features.empty()) return; diff --git a/mediapipe/util/tracking/tracking.h b/mediapipe/util/tracking/tracking.h index 5f2d01038..4a12a19ea 100644 --- a/mediapipe/util/tracking/tracking.h +++ b/mediapipe/util/tracking/tracking.h @@ -26,6 +26,7 @@ #include #include "absl/container/flat_hash_set.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "mediapipe/framework/port/vector.h" #include "mediapipe/util/tracking/flow_packager.pb.h" @@ -121,9 +122,9 @@ void MotionBoxBoundingBox(const MotionBoxState& state, Vector2_f* top_left, // existing score. inline void MotionBoxInliers(const MotionBoxState& state, std::unordered_map* inliers) { - CHECK(inliers); + ABSL_CHECK(inliers); const int num_inliers = state.inlier_ids_size(); - DCHECK_EQ(num_inliers, state.inlier_length_size()); + ABSL_DCHECK_EQ(num_inliers, state.inlier_length_size()); for (int k = 0; k < num_inliers; ++k) { (*inliers)[state.inlier_ids(k)] = @@ -573,7 +574,7 @@ class MotionBox { // Check if it is a convex quad. static bool IsValidQuad(const MotionBoxState::Quad& quad) { const int kQuadVerticesSize = 8; - CHECK_EQ(quad.vertices_size(), kQuadVerticesSize); + ABSL_CHECK_EQ(quad.vertices_size(), kQuadVerticesSize); for (int a = 0; a < kQuadVerticesSize; a += 2) { int b = (a + 2) % kQuadVerticesSize; int c = (a - 2 + kQuadVerticesSize) % kQuadVerticesSize; @@ -596,7 +597,7 @@ class MotionBox { static bool IsQuadOutOfFov(const MotionBoxState::Quad& quad, const Vector2_f& fov) { const int kQuadVerticesSize = 8; - CHECK_EQ(quad.vertices_size(), kQuadVerticesSize); + ABSL_CHECK_EQ(quad.vertices_size(), kQuadVerticesSize); bool too_far = true; for (int j = 0; j < kQuadVerticesSize; j += 2) { if (quad.vertices(j) < fov.x() && quad.vertices(j) > 0.0f && diff --git a/mediapipe/util/tracking/tracking_visualization_utilities.cc b/mediapipe/util/tracking/tracking_visualization_utilities.cc index be3572d62..5ce45042e 100644 --- a/mediapipe/util/tracking/tracking_visualization_utilities.cc +++ b/mediapipe/util/tracking/tracking_visualization_utilities.cc @@ -14,6 +14,7 @@ #include "mediapipe/util/tracking/tracking_visualization_utilities.h" +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/strings/str_format.h" #include "mediapipe/framework/port/opencv_imgproc_inc.h" @@ -25,7 +26,7 @@ namespace mediapipe { void RenderState(const MotionBoxState& box_state, bool print_stats, cv::Mat* frame) { #ifndef NO_RENDERING - CHECK(frame != nullptr); + ABSL_CHECK(frame != nullptr); const int frame_width = frame->cols; const int frame_height = frame->rows; @@ -137,7 +138,7 @@ void RenderState(const MotionBoxState& box_state, bool print_stats, void RenderInternalState(const MotionBoxInternalState& internal, cv::Mat* frame) { #ifndef NO_RENDERING - CHECK(frame != nullptr); + ABSL_CHECK(frame != nullptr); const int num_vectors = internal.pos_x_size(); @@ -177,7 +178,7 @@ void RenderInternalState(const MotionBoxInternalState& internal, void RenderTrackingData(const TrackingData& data, cv::Mat* mat, bool antialiasing) { #ifndef NO_RENDERING - CHECK(mat != nullptr); + ABSL_CHECK(mat != nullptr); MotionVectorFrame mvf; MotionVectorFrameFromTrackingData(data, &mvf); @@ -206,7 +207,7 @@ void RenderTrackingData(const TrackingData& data, cv::Mat* mat, void RenderBox(const TimedBoxProto& box_proto, cv::Mat* mat) { #ifndef NO_RENDERING - CHECK(mat != nullptr); + ABSL_CHECK(mat != nullptr); TimedBox box = TimedBox::FromProto(box_proto); std::array corners = box.Corners(mat->cols, mat->rows);