diff --git a/mediapipe/calculators/tflite/BUILD b/mediapipe/calculators/tflite/BUILD index 9dcb0f733..b5b01d937 100644 --- a/mediapipe/calculators/tflite/BUILD +++ b/mediapipe/calculators/tflite/BUILD @@ -14,6 +14,7 @@ # load("//mediapipe/framework/port:build_config.bzl", "mediapipe_proto_library") +load("@org_tensorflow//tensorflow/lite/core/shims:cc_library_with_tflite.bzl", "cc_library_with_tflite") load("@bazel_skylib//lib:selects.bzl", "selects") licenses(["notice"]) @@ -312,15 +313,19 @@ cc_library( alwayslink = 1, ) -cc_library( +# TODO: Re-evaluate which of these libraries we can avoid making +# cc_library_with_tflite and can be changed back to cc_library. +cc_library_with_tflite( name = "tflite_model_calculator", srcs = ["tflite_model_calculator.cc"], + tflite_deps = [ + "@org_tensorflow//tensorflow/lite:framework_stable", + ], deps = [ "//mediapipe/framework:calculator_framework", "//mediapipe/framework:packet", "//mediapipe/framework/port:ret_check", "@com_google_absl//absl/status", - "@org_tensorflow//tensorflow/lite/core/shims:framework_stable", ], alwayslink = 1, ) diff --git a/mediapipe/calculators/tflite/tflite_custom_op_resolver_calculator.cc b/mediapipe/calculators/tflite/tflite_custom_op_resolver_calculator.cc index 3a5ae8282..950d742a9 100644 --- a/mediapipe/calculators/tflite/tflite_custom_op_resolver_calculator.cc +++ b/mediapipe/calculators/tflite/tflite_custom_op_resolver_calculator.cc @@ -66,7 +66,7 @@ class TfLiteCustomOpResolverCalculator : public CalculatorBase { } else { cc->OutputSidePackets() .Index(0) - .Set(); + .Set(); } return absl::OkStatus(); } @@ -77,7 +77,7 @@ class TfLiteCustomOpResolverCalculator : public CalculatorBase { const TfLiteCustomOpResolverCalculatorOptions& options = cc->Options(); - std::unique_ptr op_resolver; + std::unique_ptr op_resolver; if (options.use_gpu()) { op_resolver = absl::make_unique(); } else { diff --git a/mediapipe/calculators/tflite/tflite_model_calculator.cc b/mediapipe/calculators/tflite/tflite_model_calculator.cc index 435ea0127..a8a85ed78 100644 --- a/mediapipe/calculators/tflite/tflite_model_calculator.cc +++ b/mediapipe/calculators/tflite/tflite_model_calculator.cc @@ -21,7 +21,7 @@ #include "mediapipe/framework/packet.h" #include "mediapipe/framework/port/ret_check.h" #include "tensorflow/lite/allocation.h" -#include "tensorflow/lite/core/shims/cc/model.h" +#include "tensorflow/lite/model.h" namespace mediapipe { @@ -82,7 +82,7 @@ class TfLiteModelCalculator : public CalculatorBase { } if (cc->InputSidePackets().HasTag("MODEL_FD")) { -#ifdef ABSL_HAVE_MMAP +#if defined(ABSL_HAVE_MMAP) && !TFLITE_WITH_STABLE_ABI model_packet = cc->InputSidePackets().Tag("MODEL_FD"); const auto& model_fd = model_packet.Get>(); diff --git a/mediapipe/util/tflite/BUILD b/mediapipe/util/tflite/BUILD index da58d59cf..0dec0392a 100644 --- a/mediapipe/util/tflite/BUILD +++ b/mediapipe/util/tflite/BUILD @@ -30,10 +30,16 @@ cc_library( ], ) -cc_library( +# TODO: Re-evaluate which of these libraries we can avoid making +# cc_library_with_tflite and can be changed back to cc_library. +cc_library_with_tflite( name = "cpu_op_resolver", srcs = ["cpu_op_resolver.cc"], hdrs = ["cpu_op_resolver.h"], + tflite_deps = [ + "@org_tensorflow//tensorflow/lite:framework_stable", + "@org_tensorflow//tensorflow/lite/kernels:builtin_ops", + ], visibility = ["//visibility:public"], deps = [ "//mediapipe/framework/port:logging", @@ -44,8 +50,6 @@ cc_library( "//mediapipe/util/tflite/operations:transform_tensor_bilinear", "//mediapipe/util/tflite/operations:transpose_conv_bias", "@org_tensorflow//tensorflow/lite:builtin_op_data", - "@org_tensorflow//tensorflow/lite/core/shims:builtin_ops", - "@org_tensorflow//tensorflow/lite/core/shims:framework_stable", ], # For using the symbol `MediaPipe_RegisterTfLiteOpResolver` in Python # with `tensorflow.lite.python.interpreter.InterpreterWithCustomOps`. @@ -63,13 +67,17 @@ cc_library( ], ) -cc_library( +# TODO: Re-evaluate which of these libraries we can avoid making +# cc_library_with_tflite and can be changed back to cc_library. +cc_library_with_tflite( name = "op_resolver", srcs = ["op_resolver.cc"], hdrs = ["op_resolver.h"], + tflite_deps = [ + "@org_tensorflow//tensorflow/lite/kernels:builtin_ops", + ], deps = [ "@org_tensorflow//tensorflow/lite:builtin_op_data", - "@org_tensorflow//tensorflow/lite/core/shims:builtin_ops", ], ) diff --git a/mediapipe/util/tflite/cpu_op_resolver.h b/mediapipe/util/tflite/cpu_op_resolver.h index 173531f11..887683013 100644 --- a/mediapipe/util/tflite/cpu_op_resolver.h +++ b/mediapipe/util/tflite/cpu_op_resolver.h @@ -15,7 +15,7 @@ #ifndef MEDIAPIPE_UTIL_TFLITE_CPU_OP_RESOLVER_H_ #define MEDIAPIPE_UTIL_TFLITE_CPU_OP_RESOLVER_H_ -#include "tensorflow/lite/core/shims/cc/kernels/register.h" +#include "tensorflow/lite/kernels/register.h" namespace mediapipe { @@ -27,8 +27,8 @@ extern "C" void MediaPipe_RegisterTfLiteOpResolver(tflite::MutableOpResolver*); // This resolver is used for the custom ops introduced by // `MediaPipe_RegisterTfLiteOpResolver` (see above). -class CpuOpResolver : public tflite_shims::ops::builtin:: - BuiltinOpResolverWithoutDefaultDelegates { +class CpuOpResolver + : public tflite::ops::builtin::BuiltinOpResolverWithoutDefaultDelegates { public: CpuOpResolver() { MediaPipe_RegisterTfLiteOpResolver(this); } }; diff --git a/mediapipe/util/tflite/op_resolver.h b/mediapipe/util/tflite/op_resolver.h index 8b04d5f1a..4ca179ef1 100644 --- a/mediapipe/util/tflite/op_resolver.h +++ b/mediapipe/util/tflite/op_resolver.h @@ -15,13 +15,13 @@ #ifndef MEDIAPIPE_UTIL_TFLITE_OP_RESOLVER_H_ #define MEDIAPIPE_UTIL_TFLITE_OP_RESOLVER_H_ -#include "tensorflow/lite/core/shims/cc/kernels/register.h" +#include "tensorflow/lite/kernels/register.h" namespace mediapipe { // This OpResolver is used for supporting "Convolution2DTransposeBias" on GPU. -class OpResolver : public tflite_shims::ops::builtin:: - BuiltinOpResolverWithoutDefaultDelegates { +class OpResolver + : public tflite::ops::builtin::BuiltinOpResolverWithoutDefaultDelegates { public: OpResolver(); };