diff --git a/tensorflow/lite/BUILD b/tensorflow/lite/BUILD index 6fccce0f792..274c0524200 100644 --- a/tensorflow/lite/BUILD +++ b/tensorflow/lite/BUILD @@ -233,9 +233,7 @@ cc_library( "interpreter.cc", "interpreter_builder.cc", "model_builder.cc", - "mutable_op_resolver.cc", "optional_debug_tools.cc", - "stderr_reporter.cc", ], hdrs = FRAMEWORK_LIB_HDRS, compatible_with = get_compatible_with_portable(), @@ -251,14 +249,17 @@ cc_library( ":kernel_api", ":memory_planner", ":minimal_logging", + ":mutable_op_resolver", ":shared_library", ":simple_memory_arena", + ":stderr_reporter", ":string", ":type_to_tflitetype", ":util", ":version", "//tensorflow/lite/c:common", "//tensorflow/lite/core/api", + "//tensorflow/lite/core/api:verifier", "//tensorflow/lite/delegates:status", "//tensorflow/lite/delegates/nnapi:nnapi_delegate", "//tensorflow/lite/experimental/resource", @@ -294,6 +295,7 @@ cc_library( ":version", "//tensorflow/lite/c:common", "//tensorflow/lite/core/api", + "//tensorflow/lite/core/api:verifier", "//tensorflow/lite/delegates/nnapi:nnapi_delegate", "//tensorflow/lite/experimental/resource", "//tensorflow/lite/nnapi:nnapi_implementation", @@ -301,6 +303,70 @@ cc_library( ], ) +cc_library( + name = "error_reporter", + hdrs = ["error_reporter.h"], + compatible_with = get_compatible_with_portable(), + copts = tflite_copts() + TFLITE_DEFAULT_COPTS, + visibility = [ + "//tensorflow/lite:__subpackages__", + "//tensorflow_lite_support:__subpackages__", + ], + deps = [ + "//tensorflow/lite:stderr_reporter", + "//tensorflow/lite/core/api", + ], +) + +cc_library( + name = "stderr_reporter", + srcs = ["stderr_reporter.cc"], + hdrs = ["stderr_reporter.h"], + compatible_with = get_compatible_with_portable(), + copts = tflite_copts() + TFLITE_DEFAULT_COPTS, + visibility = [ + "//tensorflow/lite:__subpackages__", + "//tensorflow_lite_support:__subpackages__", + ], + deps = [ + ":minimal_logging", + "//tensorflow/lite/c:common", + "//tensorflow/lite/core/api", + ], +) + +cc_library( + name = "op_resolver", + hdrs = ["op_resolver.h"], + compatible_with = get_compatible_with_portable(), + copts = tflite_copts() + TFLITE_DEFAULT_COPTS, + visibility = [ + "//tensorflow/lite:__subpackages__", + "//tensorflow_lite_support:__subpackages__", + ], + deps = [ + "//tensorflow/lite:mutable_op_resolver", + "//tensorflow/lite/core/api", + ], +) + +cc_library( + name = "mutable_op_resolver", + srcs = ["mutable_op_resolver.cc"], + hdrs = ["mutable_op_resolver.h"], + compatible_with = get_compatible_with_portable(), + copts = tflite_copts() + TFLITE_DEFAULT_COPTS, + visibility = [ + "//tensorflow/lite:__subpackages__", + "//tensorflow_lite_support:__subpackages__", + ], + deps = [ + ":util", + "//tensorflow/lite/core/api", + "//tensorflow/lite/schema:schema_fbs", + ], +) + cc_library( name = "string_util", srcs = ["string_util.cc"], diff --git a/tensorflow/lite/core/api/BUILD b/tensorflow/lite/core/api/BUILD index d244c15a6d1..4d2fe310050 100644 --- a/tensorflow/lite/core/api/BUILD +++ b/tensorflow/lite/core/api/BUILD @@ -3,7 +3,7 @@ load("//tensorflow/lite/micro:build_def.bzl", "micro_copts") load("//tensorflow:tensorflow.bzl", "get_compatible_with_portable") package( - default_visibility = ["//visibility:public"], + default_visibility = ["//visibility:private"], licenses = ["notice"], # Apache 2.0 ) @@ -24,6 +24,7 @@ cc_library( ], compatible_with = get_compatible_with_portable(), copts = tflite_copts() + micro_copts(), + visibility = ["//visibility:public"], deps = [ "@flatbuffers//:runtime_cc", "//tensorflow/lite/c:common", @@ -35,6 +36,18 @@ cc_library( ], ) +cc_library( + name = "verifier", + hdrs = ["verifier.h"], + compatible_with = get_compatible_with_portable(), + copts = tflite_copts() + micro_copts(), + visibility = [ + "//tensorflow/lite:__subpackages__", + "//tensorflow_lite_support:__subpackages__", + ], + deps = [":api"], +) + cc_test( name = "error_reporter_test", size = "small", diff --git a/tensorflow/lite/core/api/verifier.h b/tensorflow/lite/core/api/verifier.h new file mode 100644 index 00000000000..ca1cfb044bd --- /dev/null +++ b/tensorflow/lite/core/api/verifier.h @@ -0,0 +1,38 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +/// \file +/// Abstract interface for verifying a model. +#ifndef TENSORFLOW_LITE_CORE_API_VERIFIER_H_ +#define TENSORFLOW_LITE_CORE_API_VERIFIER_H_ + +#include "tensorflow/lite/core/api/error_reporter.h" + +namespace tflite { + +/// Abstract interface that verifies whether a given model is legit. +/// It facilitates the use-case to verify and build a model without loading it +/// twice. +/// (See also "tensorflow/lite/tools/verifier.h".) +class TfLiteVerifier { + public: + /// Returns true if the model is legit. + virtual bool Verify(const char* data, int length, + ErrorReporter* reporter) = 0; + virtual ~TfLiteVerifier() {} +}; + +} // namespace tflite + +#endif // TENSORFLOW_LITE_CORE_API_VERIFIER_H_ diff --git a/tensorflow/lite/kernels/register.h b/tensorflow/lite/kernels/register.h index 1a6095c7140..e5cd7bcb4ad 100644 --- a/tensorflow/lite/kernels/register.h +++ b/tensorflow/lite/kernels/register.h @@ -15,7 +15,6 @@ limitations under the License. #ifndef TENSORFLOW_LITE_KERNELS_REGISTER_H_ #define TENSORFLOW_LITE_KERNELS_REGISTER_H_ -#include "tensorflow/lite/model.h" #include "tensorflow/lite/mutable_op_resolver.h" namespace tflite { diff --git a/tensorflow/lite/model_builder.h b/tensorflow/lite/model_builder.h index e4233998a30..9ffb54ce2b8 100644 --- a/tensorflow/lite/model_builder.h +++ b/tensorflow/lite/model_builder.h @@ -26,23 +26,13 @@ limitations under the License. #include "tensorflow/lite/c/common.h" #include "tensorflow/lite/core/api/error_reporter.h" #include "tensorflow/lite/core/api/op_resolver.h" +#include "tensorflow/lite/core/api/verifier.h" #include "tensorflow/lite/mutable_op_resolver.h" #include "tensorflow/lite/schema/schema_generated.h" #include "tensorflow/lite/stderr_reporter.h" namespace tflite { -/// Abstract interface that verifies whether a given model is legit. -/// It facilitates the use-case to verify and build a model without loading it -/// twice. -class TfLiteVerifier { - public: - /// Returns true if the model is legit. - virtual bool Verify(const char* data, int length, - ErrorReporter* reporter) = 0; - virtual ~TfLiteVerifier() {} -}; - /// An RAII object that represents a read-only tflite model, copied from disk, /// or mmapped. This uses flatbuffers as the serialization format. /// diff --git a/tensorflow/lite/tools/BUILD b/tensorflow/lite/tools/BUILD index 152dd424b25..150ab907a66 100644 --- a/tensorflow/lite/tools/BUILD +++ b/tensorflow/lite/tools/BUILD @@ -191,10 +191,10 @@ cc_library( srcs = ["verifier.cc"], hdrs = ["verifier.h"], deps = [ - "//tensorflow/lite:framework", "//tensorflow/lite:schema_fbs_version", "//tensorflow/lite:string_util", "//tensorflow/lite/c:common", + "//tensorflow/lite/core/api", "//tensorflow/lite/schema:schema_fbs", "//tensorflow/lite/schema:schema_utils", "@com_google_absl//absl/container:flat_hash_set", diff --git a/tensorflow/lite/tools/verifier.h b/tensorflow/lite/tools/verifier.h index 50b6432d4e3..a19dfcf5fc0 100644 --- a/tensorflow/lite/tools/verifier.h +++ b/tensorflow/lite/tools/verifier.h @@ -18,8 +18,8 @@ limitations under the License. #include <stdio.h> -#include "tensorflow/lite/error_reporter.h" -#include "tensorflow/lite/model.h" +#include "tensorflow/lite/core/api/error_reporter.h" +#include "tensorflow/lite/core/api/op_resolver.h" namespace tflite {