Convert CHECK macro to ABSL_CHECK.

Chrome can't use Absl's CHECK because of collisions with its own version.

PiperOrigin-RevId: 561740965
This commit is contained in:
MediaPipe Team
2023-08-31 13:20:29 -07:00
committed by Copybara-Service
parent 30802b80cd
commit 7c2d654d67
262 changed files with 1881 additions and 1474 deletions
@@ -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",
],
)
@@ -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));
//}
}
@@ -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",
@@ -6,6 +6,7 @@
#include <string>
#include <vector>
#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<int>& input,
const std::vector<uint8_t>& encoding_table,
const std::vector<float>& 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<int>& input,
@@ -20,6 +20,7 @@ limitations under the License.
#include <string>
#include <vector>
#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) {
@@ -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",
@@ -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<CalculatorGraphConfig> GetConfig(
SubgraphContext* sc) override {
CHECK(sc != nullptr);
ABSL_CHECK(sc != nullptr);
ASSIGN_OR_RETURN(const ModelResources* model_resources,
CreateModelResources<proto::TextEmbedderGraphOptions>(sc));
Graph graph;
+4
View File
@@ -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 = [
@@ -21,6 +21,7 @@ limitations under the License.
#include <string>
#include <vector>
#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<std::string>& subwords = result.subwords;
CHECK_OK(sp_.Encode(input, &subwords));
const auto status = sp_.Encode(input, &subwords);
ABSL_CHECK(status.ok()) << status.ToString();
return result;
}
@@ -21,6 +21,7 @@ limitations under the License.
#include <vector>
#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<std::unique_ptr<TaskRunner>> 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;
}
@@ -18,6 +18,7 @@ limitations under the License.
#include <vector>
#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});
}
@@ -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({
@@ -16,6 +16,7 @@
#include <string>
#include <vector>
#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";
}
@@ -21,6 +21,7 @@ limitations under the License.
#include <vector>
#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<std::unique_ptr<TaskRunner>> 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;
}
@@ -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,
)
@@ -17,6 +17,7 @@ limitations under the License.
#include <utility>
#include <vector>
#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<HandAssociationCalculatorOptions>();
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();
}
@@ -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",
],
@@ -17,7 +17,7 @@ limitations under the License.
#include <utility>
#include <vector>
#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());
@@ -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<std::unique_ptr<TaskRunner>> 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;
}
+1
View File
@@ -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",
@@ -21,6 +21,7 @@ limitations under the License.
#include <type_traits>
#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<ImageTensorSpecs> input_specs_or =
BuildInputImageTensorSpecs(*model_resources);
MP_ASSERT_OK(input_specs_or);