Internal change

PiperOrigin-RevId: 336109212
Change-Id: I5e2bec9f4923e4b446ef15fab23c19433a92e526
This commit is contained in:
A. Unique TensorFlower 2020-10-08 10:07:16 -07:00 committed by TensorFlower Gardener
parent b8fc0b69e3
commit 4147aa9700
7 changed files with 124 additions and 18 deletions

View File

@ -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"],

View File

@ -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",

View File

@ -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_

View File

@ -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 {

View File

@ -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.
///

View File

@ -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",

View File

@ -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 {