Split getter and setter functions in schema utility files.

This enables TFLite Micro to selectively include these setter functions in unit tests. The APIs used in creating the flatbuffer introduce new and delete symbols which can cause issues for libraries not fully building with --gc-sections in linker flags.

PiperOrigin-RevId: 339324965
Change-Id: I720b8dab6d80a94a47b7c8c427067966e2c42943
This commit is contained in:
Nick Kreeger 2020-10-27 14:03:55 -07:00 committed by TensorFlower Gardener
parent 71aaef09d1
commit 48c3bae94a
37 changed files with 172 additions and 107 deletions

View File

@ -671,8 +671,8 @@ cc_library(
"//tensorflow/lite:string_util",
"//tensorflow/lite/delegates/flex:allowlisted_flex_ops_lib",
"//tensorflow/lite/kernels/internal:kernel_utils",
"//tensorflow/lite/schema:schema_conversion_utils",
"//tensorflow/lite/schema:schema_fbs",
"//tensorflow/lite/schema:schema_utils",
"//tensorflow/lite/tools/versioning",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/container:flat_hash_map",

View File

@ -74,8 +74,8 @@ limitations under the License.
#include "tensorflow/core/platform/status.h"
#include "tensorflow/lite/delegates/flex/allowlisted_flex_ops.h"
#include "tensorflow/lite/kernels/internal/kernel_utils.h"
#include "tensorflow/lite/schema/schema_conversion_utils.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "tensorflow/lite/schema/schema_utils.h"
#include "tensorflow/lite/string_util.h"
#include "tensorflow/lite/tools/versioning/op_version.h"
#include "tensorflow/lite/tools/versioning/runtime_version.h"

View File

@ -97,7 +97,7 @@ cc_test(
srcs = ["op_resolver_test.cc"],
deps = [
":api",
"//tensorflow/lite/schema:schema_utils",
"//tensorflow/lite/schema:schema_conversion_utils",
"@com_google_googletest//:gtest",
],
)

View File

@ -18,7 +18,7 @@ limitations under the License.
#include <cstring>
#include <gtest/gtest.h>
#include "tensorflow/lite/schema/schema_utils.h"
#include "tensorflow/lite/schema/schema_conversion_utils.h"
namespace tflite {
namespace {

View File

@ -85,8 +85,8 @@ cc_test(
"//tensorflow/lite/kernels:builtin_ops",
"//tensorflow/lite/kernels:kernel_util",
"//tensorflow/lite/kernels/internal:compatibility",
"//tensorflow/lite/schema:schema_conversion_utils",
"//tensorflow/lite/schema:schema_fbs",
"//tensorflow/lite/schema:schema_utils",
"//tensorflow/lite/testing:util",
"//third_party/eigen3",
"@com_google_googletest//:gtest",

View File

@ -30,8 +30,8 @@ limitations under the License.
#include "tensorflow/lite/kernels/internal/compatibility.h"
#include "tensorflow/lite/kernels/kernel_util.h"
#include "tensorflow/lite/kernels/register.h"
#include "tensorflow/lite/schema/schema_conversion_utils.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "tensorflow/lite/schema/schema_utils.h"
#include "tensorflow/lite/testing/util.h"
#include "tensorflow/lite/util.h"
#include "tensorflow/lite/version.h"

View File

@ -76,8 +76,8 @@ cc_library(
"//tensorflow/lite:schema_fbs_version",
"//tensorflow/lite/c:common",
"//tensorflow/lite/kernels:builtin_ops",
"//tensorflow/lite/schema:schema_conversion_utils",
"//tensorflow/lite/schema:schema_fbs",
"//tensorflow/lite/schema:schema_utils",
"@FP16",
"@com_google_googletest//:gtest",
"@flatbuffers",
@ -94,8 +94,8 @@ cc_library(
"//tensorflow/lite:schema_fbs_version",
"//tensorflow/lite/c:common",
"//tensorflow/lite/kernels:builtin_ops",
"//tensorflow/lite/schema:schema_conversion_utils",
"//tensorflow/lite/schema:schema_fbs",
"//tensorflow/lite/schema:schema_utils",
"@FP16",
"@com_google_googletest//:gtest",
"@flatbuffers",
@ -112,8 +112,8 @@ cc_library(
"//tensorflow/lite:schema_fbs_version",
"//tensorflow/lite/c:common",
"//tensorflow/lite/kernels:builtin_ops",
"//tensorflow/lite/schema:schema_conversion_utils",
"//tensorflow/lite/schema:schema_fbs",
"//tensorflow/lite/schema:schema_utils",
"@FP16",
"@com_google_googletest//:gtest",
"@flatbuffers",
@ -130,8 +130,8 @@ cc_library(
"//tensorflow/lite:schema_fbs_version",
"//tensorflow/lite/c:common",
"//tensorflow/lite/kernels:builtin_ops",
"//tensorflow/lite/schema:schema_conversion_utils",
"//tensorflow/lite/schema:schema_fbs",
"//tensorflow/lite/schema:schema_utils",
"@FP16",
"@com_google_googletest//:gtest",
"@flatbuffers",
@ -148,8 +148,8 @@ cc_library(
"//tensorflow/lite:schema_fbs_version",
"//tensorflow/lite/c:common",
"//tensorflow/lite/kernels:builtin_ops",
"//tensorflow/lite/schema:schema_conversion_utils",
"//tensorflow/lite/schema:schema_fbs",
"//tensorflow/lite/schema:schema_utils",
"@com_google_googletest//:gtest",
"@flatbuffers",
],
@ -165,8 +165,8 @@ cc_library(
"//tensorflow/lite:schema_fbs_version",
"//tensorflow/lite/c:common",
"//tensorflow/lite/kernels:builtin_ops",
"//tensorflow/lite/schema:schema_conversion_utils",
"//tensorflow/lite/schema:schema_fbs",
"//tensorflow/lite/schema:schema_utils",
"@com_google_googletest//:gtest",
"@flatbuffers",
],
@ -182,8 +182,8 @@ cc_library(
"//tensorflow/lite:schema_fbs_version",
"//tensorflow/lite/c:common",
"//tensorflow/lite/kernels:builtin_ops",
"//tensorflow/lite/schema:schema_conversion_utils",
"//tensorflow/lite/schema:schema_fbs",
"//tensorflow/lite/schema:schema_utils",
"@com_google_googletest//:gtest",
"@flatbuffers",
],
@ -199,8 +199,8 @@ cc_library(
"//tensorflow/lite:schema_fbs_version",
"//tensorflow/lite/c:common",
"//tensorflow/lite/kernels:builtin_ops",
"//tensorflow/lite/schema:schema_conversion_utils",
"//tensorflow/lite/schema:schema_fbs",
"//tensorflow/lite/schema:schema_utils",
"@FP16",
"@com_google_googletest//:gtest",
"@flatbuffers",
@ -217,8 +217,8 @@ cc_library(
"//tensorflow/lite:schema_fbs_version",
"//tensorflow/lite/c:common",
"//tensorflow/lite/kernels:builtin_ops",
"//tensorflow/lite/schema:schema_conversion_utils",
"//tensorflow/lite/schema:schema_fbs",
"//tensorflow/lite/schema:schema_utils",
"@com_google_googletest//:gtest",
"@flatbuffers",
],
@ -234,8 +234,8 @@ cc_library(
"//tensorflow/lite:schema_fbs_version",
"//tensorflow/lite/c:common",
"//tensorflow/lite/kernels:builtin_ops",
"//tensorflow/lite/schema:schema_conversion_utils",
"//tensorflow/lite/schema:schema_fbs",
"//tensorflow/lite/schema:schema_utils",
"@com_google_googletest//:gtest",
"@flatbuffers",
],
@ -251,8 +251,8 @@ cc_library(
"//tensorflow/lite:schema_fbs_version",
"//tensorflow/lite/c:common",
"//tensorflow/lite/kernels:builtin_ops",
"//tensorflow/lite/schema:schema_conversion_utils",
"//tensorflow/lite/schema:schema_fbs",
"//tensorflow/lite/schema:schema_utils",
"@com_google_googletest//:gtest",
"@flatbuffers",
],
@ -268,8 +268,8 @@ cc_library(
"//tensorflow/lite:schema_fbs_version",
"//tensorflow/lite/c:common",
"//tensorflow/lite/kernels:builtin_ops",
"//tensorflow/lite/schema:schema_conversion_utils",
"//tensorflow/lite/schema:schema_fbs",
"//tensorflow/lite/schema:schema_utils",
"@com_google_googletest//:gtest",
"@flatbuffers",
],
@ -285,8 +285,8 @@ cc_library(
"//tensorflow/lite:schema_fbs_version",
"//tensorflow/lite/c:common",
"//tensorflow/lite/kernels:builtin_ops",
"//tensorflow/lite/schema:schema_conversion_utils",
"//tensorflow/lite/schema:schema_fbs",
"//tensorflow/lite/schema:schema_utils",
"@com_google_googletest//:gtest",
"@flatbuffers",
],

View File

@ -28,8 +28,8 @@ limitations under the License.
#include "tensorflow/lite/interpreter.h"
#include "tensorflow/lite/kernels/register.h"
#include "tensorflow/lite/model.h"
#include "tensorflow/lite/schema/schema_conversion_utils.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "tensorflow/lite/schema/schema_utils.h"
#include "tensorflow/lite/version.h"
namespace tflite {

View File

@ -27,8 +27,8 @@ limitations under the License.
#include "tensorflow/lite/interpreter.h"
#include "tensorflow/lite/kernels/register.h"
#include "tensorflow/lite/model.h"
#include "tensorflow/lite/schema/schema_conversion_utils.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "tensorflow/lite/schema/schema_utils.h"
#include "tensorflow/lite/version.h"
namespace tflite {

View File

@ -27,8 +27,8 @@ limitations under the License.
#include "tensorflow/lite/interpreter.h"
#include "tensorflow/lite/kernels/register.h"
#include "tensorflow/lite/model.h"
#include "tensorflow/lite/schema/schema_conversion_utils.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "tensorflow/lite/schema/schema_utils.h"
#include "tensorflow/lite/version.h"
namespace tflite {

View File

@ -28,8 +28,8 @@ limitations under the License.
#include "tensorflow/lite/interpreter.h"
#include "tensorflow/lite/kernels/register.h"
#include "tensorflow/lite/model.h"
#include "tensorflow/lite/schema/schema_conversion_utils.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "tensorflow/lite/schema/schema_utils.h"
#include "tensorflow/lite/version.h"
namespace tflite {

View File

@ -27,8 +27,8 @@ limitations under the License.
#include "tensorflow/lite/interpreter.h"
#include "tensorflow/lite/kernels/register.h"
#include "tensorflow/lite/model.h"
#include "tensorflow/lite/schema/schema_conversion_utils.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "tensorflow/lite/schema/schema_utils.h"
#include "tensorflow/lite/version.h"
namespace tflite {

View File

@ -27,8 +27,8 @@ limitations under the License.
#include "tensorflow/lite/interpreter.h"
#include "tensorflow/lite/kernels/register.h"
#include "tensorflow/lite/model.h"
#include "tensorflow/lite/schema/schema_conversion_utils.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "tensorflow/lite/schema/schema_utils.h"
#include "tensorflow/lite/version.h"
namespace tflite {

View File

@ -26,8 +26,8 @@ limitations under the License.
#include "tensorflow/lite/interpreter.h"
#include "tensorflow/lite/kernels/register.h"
#include "tensorflow/lite/model.h"
#include "tensorflow/lite/schema/schema_conversion_utils.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "tensorflow/lite/schema/schema_utils.h"
#include "tensorflow/lite/version.h"
namespace tflite {

View File

@ -28,8 +28,8 @@ limitations under the License.
#include "tensorflow/lite/interpreter.h"
#include "tensorflow/lite/kernels/register.h"
#include "tensorflow/lite/model.h"
#include "tensorflow/lite/schema/schema_conversion_utils.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "tensorflow/lite/schema/schema_utils.h"
#include "tensorflow/lite/version.h"
namespace tflite {

View File

@ -27,8 +27,8 @@ limitations under the License.
#include "tensorflow/lite/interpreter.h"
#include "tensorflow/lite/kernels/register.h"
#include "tensorflow/lite/model.h"
#include "tensorflow/lite/schema/schema_conversion_utils.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "tensorflow/lite/schema/schema_utils.h"
#include "tensorflow/lite/version.h"
namespace tflite {

View File

@ -27,8 +27,8 @@ limitations under the License.
#include "tensorflow/lite/interpreter.h"
#include "tensorflow/lite/kernels/register.h"
#include "tensorflow/lite/model.h"
#include "tensorflow/lite/schema/schema_conversion_utils.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "tensorflow/lite/schema/schema_utils.h"
#include "tensorflow/lite/version.h"
namespace tflite {

View File

@ -27,8 +27,8 @@ limitations under the License.
#include "tensorflow/lite/interpreter.h"
#include "tensorflow/lite/kernels/register.h"
#include "tensorflow/lite/model.h"
#include "tensorflow/lite/schema/schema_conversion_utils.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "tensorflow/lite/schema/schema_utils.h"
#include "tensorflow/lite/version.h"
namespace tflite {

View File

@ -27,8 +27,8 @@ limitations under the License.
#include "tensorflow/lite/interpreter.h"
#include "tensorflow/lite/kernels/register.h"
#include "tensorflow/lite/model.h"
#include "tensorflow/lite/schema/schema_conversion_utils.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "tensorflow/lite/schema/schema_utils.h"
#include "tensorflow/lite/version.h"
namespace tflite {

View File

@ -27,8 +27,8 @@ limitations under the License.
#include "tensorflow/lite/interpreter.h"
#include "tensorflow/lite/kernels/register.h"
#include "tensorflow/lite/model.h"
#include "tensorflow/lite/schema/schema_conversion_utils.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "tensorflow/lite/schema/schema_utils.h"
#include "tensorflow/lite/version.h"
namespace tflite {

View File

@ -190,8 +190,8 @@ cc_library(
"//tensorflow/lite/delegates/nnapi:nnapi_delegate",
"//tensorflow/lite/kernels/internal:tensor_utils",
"//tensorflow/lite/nnapi:nnapi_implementation",
"//tensorflow/lite/schema:schema_conversion_utils",
"//tensorflow/lite/schema:schema_fbs",
"//tensorflow/lite/schema:schema_utils",
"//tensorflow/lite/testing:util",
"//tensorflow/lite/tools:command_line_flags",
"//tensorflow/lite/tools:logging",

View File

@ -43,8 +43,8 @@ limitations under the License.
#include "tensorflow/lite/kernels/test_delegate_providers.h"
#include "tensorflow/lite/model.h"
#include "tensorflow/lite/nnapi/nnapi_implementation.h"
#include "tensorflow/lite/schema/schema_conversion_utils.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "tensorflow/lite/schema/schema_utils.h"
#include "tensorflow/lite/string_type.h"
#include "tensorflow/lite/string_util.h"
#include "tensorflow/lite/tools/logging.h"

View File

@ -88,7 +88,6 @@ cc_library(
"//tensorflow/lite/kernels/internal:compatibility",
"//tensorflow/lite/kernels/internal:tensor",
"//tensorflow/lite/schema:schema_fbs",
"//tensorflow/lite/schema:schema_utils",
"@flatbuffers//:runtime_cc",
],
)

View File

@ -30,7 +30,8 @@ limitations under the License.
#include "tensorflow/lite/micro/all_ops_resolver.h"
#include "tensorflow/lite/micro/micro_utils.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "tensorflow/lite/schema/schema_utils.h"
// TODO(b/170464050): Use TFLM test only version of schema_utils.
namespace tflite {
namespace testing {

View File

@ -232,6 +232,7 @@ tensorflow/lite/core/api/op_resolver.cc \
tensorflow/lite/core/api/tensor_utils.cc \
tensorflow/lite/kernels/internal/quantization_util.cc \
tensorflow/lite/kernels/kernel_util.cc \
tensorflow/lite/schema/schema_conversion_utils.cc \
tensorflow/lite/schema/schema_utils.cc
MICROLITE_CC_SRCS := $(filter-out $(MICROLITE_TEST_SRCS), $(MICROLITE_CC_BASE_SRCS))
@ -308,6 +309,7 @@ tensorflow/lite/kernels/op_macros.h \
tensorflow/lite/kernels/padding.h \
tensorflow/lite/portable_type_to_tflitetype.h \
tensorflow/lite/schema/schema_generated.h \
tensorflow/lite/schema/schema_conversion_utils.h \
tensorflow/lite/schema/schema_utils.h \
tensorflow/lite/version.h

View File

@ -143,4 +143,17 @@ cc_library(
],
)
cc_library(
name = "schema_conversion_utils",
srcs = ["schema_conversion_utils.cc"],
hdrs = ["schema_conversion_utils.h"],
compatible_with = get_compatible_with_portable(),
visibility = [":utils_friends"],
deps = [
":schema_fbs",
"//tensorflow/lite/kernels/internal:compatibility",
"@flatbuffers",
],
)
tflite_portable_test_suite()

View File

@ -0,0 +1,70 @@
/* 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.
==============================================================================*/
#include "tensorflow/lite/schema/schema_conversion_utils.h"
#include <algorithm>
#include "tensorflow/lite/kernels/internal/compatibility.h"
namespace tflite {
int8_t ConvertBuiltinCodeToDeprecatedBuiltinCode(
const BuiltinOperator builtin_code) {
return (builtin_code < BuiltinOperator_PLACEHOLDER_FOR_GREATER_OP_CODES)
? static_cast<int8_t>(builtin_code)
: static_cast<int8_t>(
BuiltinOperator_PLACEHOLDER_FOR_GREATER_OP_CODES);
}
// The following methods are the following `OperatorCode` table object creation
// methods for backward compatibility. These are manually copied from the
// flatbuffer generated code from schema v3. They serve as overloads for the
// v3a's CreateOperatorCode functions in schema_generated.h and enable code that
// still assumes flatbuffer schema v3 to be unchanged with the inclusion of the
// schema_utils header.
// TODO(b/162392898): remove once all callers are updated to use schema v3a
// functions.
flatbuffers::Offset<OperatorCode> CreateOperatorCode(
flatbuffers::FlatBufferBuilder &_fbb, BuiltinOperator builtin_code,
flatbuffers::Offset<flatbuffers::String> custom_code, int32_t version) {
OperatorCodeBuilder builder_(_fbb);
builder_.add_version(version);
int8_t deprecated_builtin_code =
static_cast<int8_t>(BuiltinOperator_PLACEHOLDER_FOR_GREATER_OP_CODES);
if (builtin_code < BuiltinOperator_PLACEHOLDER_FOR_GREATER_OP_CODES) {
deprecated_builtin_code = static_cast<int8_t>(builtin_code);
}
builder_.add_deprecated_builtin_code(deprecated_builtin_code);
builder_.add_custom_code(custom_code);
builder_.add_builtin_code(builtin_code);
return builder_.Finish();
}
flatbuffers::Offset<OperatorCode> CreateOperatorCodeDirect(
flatbuffers::FlatBufferBuilder &_fbb, BuiltinOperator builtin_code,
const char *custom_code, int32_t version) {
auto custom_code__ = custom_code ? _fbb.CreateString(custom_code) : 0;
int8_t deprecated_builtin_code =
static_cast<int8_t>(BuiltinOperator_PLACEHOLDER_FOR_GREATER_OP_CODES);
if (builtin_code < BuiltinOperator_PLACEHOLDER_FOR_GREATER_OP_CODES) {
deprecated_builtin_code = static_cast<int8_t>(builtin_code);
}
return CreateOperatorCode(_fbb, deprecated_builtin_code, custom_code__,
version, builtin_code);
}
} // namespace tflite

View File

@ -0,0 +1,41 @@
/* 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.
==============================================================================*/
#ifndef TENSORFLOW_LITE_SCHEMA_SCHEMA_CONVERSION_UTILS_H_
#define TENSORFLOW_LITE_SCHEMA_SCHEMA_CONVERSION_UTILS_H_
#include "flatbuffers/flatbuffers.h"
#include "tensorflow/lite/schema/schema_generated.h"
namespace tflite {
int8_t ConvertBuiltinCodeToDeprecatedBuiltinCode(
const BuiltinOperator builtin_code);
// The following methods are for backward compatibility for the early version
// three, which does not have an extended builtin code.
flatbuffers::Offset<OperatorCode> CreateOperatorCode(
flatbuffers::FlatBufferBuilder &_fbb,
BuiltinOperator builtin_code = BuiltinOperator_ADD,
flatbuffers::Offset<flatbuffers::String> custom_code = 0,
int32_t version = 1);
flatbuffers::Offset<OperatorCode> CreateOperatorCodeDirect(
flatbuffers::FlatBufferBuilder &_fbb,
BuiltinOperator builtin_code = BuiltinOperator_ADD,
const char *custom_code = nullptr, int32_t version = 1);
} // namespace tflite
#endif // TENSORFLOW_LITE_SCHEMA_SCHEMA_CONVERSION_UTILS_H_

View File

@ -42,7 +42,7 @@ namespace tflite {
// code. In the case, the maximum value of the two fields will be the value of
// the `builtin_code` as the right value.
BuiltinOperator GetBuiltinCode(const OperatorCode *op_code) {
BuiltinOperator GetBuiltinCode(const OperatorCode* op_code) {
// Caller should guarantee that the given argument value is not a nullptr.
TFLITE_DCHECK(op_code != nullptr);
@ -51,7 +51,7 @@ BuiltinOperator GetBuiltinCode(const OperatorCode *op_code) {
static_cast<BuiltinOperator>(op_code->deprecated_builtin_code()));
}
BuiltinOperator GetBuiltinCode(const OperatorCodeT *op_code) {
BuiltinOperator GetBuiltinCode(const OperatorCodeT* op_code) {
// Caller should guarantee that the given argument value is not a nullptr.
TFLITE_DCHECK(op_code != nullptr);
@ -59,51 +59,4 @@ BuiltinOperator GetBuiltinCode(const OperatorCodeT *op_code) {
op_code->deprecated_builtin_code));
}
int8_t ConvertBuiltinCodeToDeprecatedBuiltinCode(
const BuiltinOperator builtin_code) {
return (builtin_code < BuiltinOperator_PLACEHOLDER_FOR_GREATER_OP_CODES)
? static_cast<int8_t>(builtin_code)
: static_cast<int8_t>(
BuiltinOperator_PLACEHOLDER_FOR_GREATER_OP_CODES);
}
// The following methods are the following `OperatorCode` table object creation
// methods for backward compatibility. These are manually copied from the
// flatbuffer generated code from schema v3. They serve as overloads for the
// v3a's CreateOperatorCode functions in schema_generated.h and enable code that
// still assumes flatbuffer schema v3 to be unchanged with the inclusion of the
// schema_utils header.
// TODO(b/162392898): remove once all callers are updated to use schema v3a
// functions.
flatbuffers::Offset<OperatorCode> CreateOperatorCode(
flatbuffers::FlatBufferBuilder &_fbb, BuiltinOperator builtin_code,
flatbuffers::Offset<flatbuffers::String> custom_code, int32_t version) {
OperatorCodeBuilder builder_(_fbb);
builder_.add_version(version);
int8_t deprecated_builtin_code =
static_cast<int8_t>(BuiltinOperator_PLACEHOLDER_FOR_GREATER_OP_CODES);
if (builtin_code < BuiltinOperator_PLACEHOLDER_FOR_GREATER_OP_CODES) {
deprecated_builtin_code = static_cast<int8_t>(builtin_code);
}
builder_.add_deprecated_builtin_code(deprecated_builtin_code);
builder_.add_custom_code(custom_code);
builder_.add_builtin_code(builtin_code);
return builder_.Finish();
}
flatbuffers::Offset<OperatorCode> CreateOperatorCodeDirect(
flatbuffers::FlatBufferBuilder &_fbb, BuiltinOperator builtin_code,
const char *custom_code, int32_t version) {
auto custom_code__ = custom_code ? _fbb.CreateString(custom_code) : 0;
int8_t deprecated_builtin_code =
static_cast<int8_t>(BuiltinOperator_PLACEHOLDER_FOR_GREATER_OP_CODES);
if (builtin_code < BuiltinOperator_PLACEHOLDER_FOR_GREATER_OP_CODES) {
deprecated_builtin_code = static_cast<int8_t>(builtin_code);
}
return CreateOperatorCode(_fbb, deprecated_builtin_code, custom_code__,
version, builtin_code);
}
} // namespace tflite

View File

@ -28,22 +28,6 @@ BuiltinOperator GetBuiltinCode(const OperatorCode *op_code);
BuiltinOperator GetBuiltinCode(const OperatorCodeT *op_code);
int8_t ConvertBuiltinCodeToDeprecatedBuiltinCode(
const BuiltinOperator builtin_code);
// The following methods are for backward compatibility for the early version
// three, which does not have an extended builtin code.
flatbuffers::Offset<OperatorCode> CreateOperatorCode(
flatbuffers::FlatBufferBuilder &_fbb,
BuiltinOperator builtin_code = BuiltinOperator_ADD,
flatbuffers::Offset<flatbuffers::String> custom_code = 0,
int32_t version = 1);
flatbuffers::Offset<OperatorCode> CreateOperatorCodeDirect(
flatbuffers::FlatBufferBuilder &_fbb,
BuiltinOperator builtin_code = BuiltinOperator_ADD,
const char *custom_code = nullptr, int32_t version = 1);
} // namespace tflite
#endif // TENSORFLOW_LITE_SCHEMA_SCHEMA_UTILS_H_

View File

@ -94,8 +94,8 @@ cc_library(
":operator",
":types",
"//tensorflow/lite:schema_fbs_version",
"//tensorflow/lite/schema:schema_conversion_utils",
"//tensorflow/lite/schema:schema_fbs",
"//tensorflow/lite/schema:schema_utils",
"//tensorflow/lite/toco:model",
"//tensorflow/lite/toco:tooling_util",
"//tensorflow/lite/tools/optimize:quantize_weights",
@ -174,8 +174,8 @@ tf_cc_test(
":import",
"//tensorflow/core:ops",
"//tensorflow/lite:schema_fbs_version",
"//tensorflow/lite/schema:schema_conversion_utils",
"//tensorflow/lite/schema:schema_fbs",
"//tensorflow/lite/schema:schema_utils",
"@com_google_googletest//:gtest_main",
"@flatbuffers",
],

View File

@ -18,8 +18,8 @@ limitations under the License.
#include "absl/strings/str_join.h"
#include "tensorflow/core/lib/core/errors.h"
#include "tensorflow/lite/context.h"
#include "tensorflow/lite/schema/schema_conversion_utils.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "tensorflow/lite/schema/schema_utils.h"
#include "tensorflow/lite/toco/tflite/op_version.h"
#include "tensorflow/lite/toco/tflite/operator.h"
#include "tensorflow/lite/toco/tflite/types.h"

View File

@ -17,8 +17,8 @@ limitations under the License.
#include "flatbuffers/flexbuffers.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/schema/schema_conversion_utils.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "tensorflow/lite/schema/schema_utils.h"
#include "tensorflow/lite/version.h"
namespace toco {

View File

@ -220,8 +220,8 @@ cc_test(
"//tensorflow/lite:schema_fbs_version",
"//tensorflow/lite:util",
"//tensorflow/lite/core/api",
"//tensorflow/lite/schema:schema_conversion_utils",
"//tensorflow/lite/schema:schema_fbs",
"//tensorflow/lite/schema:schema_utils",
"//tensorflow/lite/testing:util",
"@com_google_googletest//:gtest",
"@flatbuffers",

View File

@ -134,6 +134,7 @@ cc_library(
"//tensorflow/lite:framework",
"//tensorflow/lite/kernels/internal:tensor_utils",
"//tensorflow/lite/kernels/internal:types",
"//tensorflow/lite/schema:schema_conversion_utils",
"//tensorflow/lite/schema:schema_fbs",
"//tensorflow/lite/schema:schema_utils",
"@com_google_absl//absl/memory",

View File

@ -20,6 +20,7 @@ limitations under the License.
#include "tensorflow/lite/kernels/internal/tensor_utils.h"
#include "tensorflow/lite/kernels/internal/types.h"
#include "tensorflow/lite/model.h"
#include "tensorflow/lite/schema/schema_conversion_utils.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "tensorflow/lite/schema/schema_utils.h"
#include "tensorflow/lite/tools/optimize/operator_property.h"

View File

@ -29,8 +29,8 @@ limitations under the License.
#include "tensorflow/lite/model.h"
#include "tensorflow/lite/mutable_op_resolver.h"
#include "tensorflow/lite/op_resolver.h"
#include "tensorflow/lite/schema/schema_conversion_utils.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "tensorflow/lite/schema/schema_utils.h"
#include "tensorflow/lite/testing/util.h"
#include "tensorflow/lite/util.h"
#include "tensorflow/lite/version.h"