Skip to content

Commit 0596b0d

Browse files
committed
Merge branch 'master' into image-classifier-c-api
2 parents c8cd3d6 + 15522f4 commit 0596b0d

File tree

68 files changed

+1884
-406
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1884
-406
lines changed

WORKSPACE

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ http_archive(
5151
],
5252
)
5353

54-
# TF on 2021-08-02.
55-
TENSORFLOW_COMMIT = "b1b4548b3e37c245d7de671aae5b827abde9ba29"
56-
TENSORFLOW_SHA256 = "5d941518f93eb0fbfb56312f6f32b096ac769068504ff103df582304c86b3a17"
54+
# TF on 2021-09-29.
55+
TENSORFLOW_COMMIT = "a221f72e69fea7a46977e35961e5cdb1e51fec36"
56+
TENSORFLOW_SHA256 = "d0e57bcf455df772cfdf65fdf59a94dfef7547c6aafd50b382dab3a182b0c5b3"
5757
http_archive(
5858
name = "org_tensorflow",
5959
sha256 = TENSORFLOW_SHA256,

tensorflow_lite_support/cc/task/audio/audio_classifier.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ namespace audio {
5252
// `ImageClassifierOptions` used at creation time ("en" by default, i.e.
5353
// English). If none of these are available, only the `index` field of the
5454
// results will be filled.
55+
//
56+
// An example of such model can be found at:
57+
// https://tfhub.dev/google/lite-model/yamnet/classification/tflite/1
58+
59+
// A CLI demo tool is available for easily trying out this API, and provides
60+
// example usage. See:
61+
// https://github.com/tensorflow/tflite-support/tree/master/tensorflow_lite_support/examples/task/audio/desktop
5562
class AudioClassifier
5663
: public tflite::task::core::BaseTaskApi<ClassificationResult,
5764
const AudioBuffer&> {

tensorflow_lite_support/cc/task/audio/audio_embedder.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ limitations under the License.
1717
#include "external/com_google_absl/absl/status/status.h"
1818
#include "tensorflow_lite_support/cc/common.h"
1919
#include "tensorflow_lite_support/cc/port/status_macros.h"
20-
#include "tensorflow_lite_support/cc/task/audio/proto/audio_embedder_options.proto.h"
20+
#include "tensorflow_lite_support/cc/task/audio/proto/audio_embedder_options.pb.h"
2121
#include "tensorflow_lite_support/cc/task/core/task_api_factory.h"
2222
#include "tensorflow_lite_support/cc/task/processor/audio_preprocessor.h"
2323
#include "tensorflow_lite_support/cc/task/processor/embedding_postprocessor.h"
24-
#include "tensorflow_lite_support/cc/task/processor/proto/embedding_options.proto.h"
24+
#include "tensorflow_lite_support/cc/task/processor/proto/embedding_options.pb.h"
2525

2626
namespace tflite {
2727
namespace task {

tensorflow_lite_support/cc/task/audio/audio_embedder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ limitations under the License.
1919

2020
#include "tensorflow/lite/c/common.h"
2121
#include "tensorflow_lite_support/cc/port/statusor.h"
22-
#include "tensorflow_lite_support/cc/task/audio/proto/audio_embedder_options.proto.h"
22+
#include "tensorflow_lite_support/cc/task/audio/proto/audio_embedder_options.pb.h"
2323
#include "tensorflow_lite_support/cc/task/core/base_task_api.h"
2424
#include "tensorflow_lite_support/cc/task/processor/audio_preprocessor.h"
2525
#include "tensorflow_lite_support/cc/task/processor/embedding_postprocessor.h"
26-
#include "tensorflow_lite_support/cc/task/processor/proto/embedding.proto.h"
26+
#include "tensorflow_lite_support/cc/task/processor/proto/embedding.pb.h"
2727
namespace tflite {
2828
namespace task {
2929
namespace audio {

tensorflow_lite_support/cc/task/core/task_utils.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ std::string LoadBinaryContent(const char* filename) {
6161
return buffer;
6262
}
6363

64+
int FindIndexByMetadataTensorName(
65+
const flatbuffers::Vector<flatbuffers::Offset<TensorMetadata>>*
66+
tensor_metadatas,
67+
const std::string& name) {
68+
if (tensor_metadatas == nullptr) {
69+
return -1;
70+
}
71+
for (int i = 0; i < tensor_metadatas->size(); i++) {
72+
if (strcmp(name.data(), tensor_metadatas->Get(i)->name()->c_str()) == 0) {
73+
return i;
74+
}
75+
}
76+
// Returns -1 if not found.
77+
return -1;
78+
}
79+
6480
} // namespace core
6581
} // namespace task
6682
} // namespace tflite

tensorflow_lite_support/cc/task/core/task_utils.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@ std::string GetStringAtIndex(const TfLiteTensor* labels, int index);
156156
// Loads binary content of a file into a string.
157157
std::string LoadBinaryContent(const char* filename);
158158

159+
// Gets the index from a vector of tensors with name specified inside metadata.
160+
// The range of the return value should be [0, output_tensor_size). If not
161+
// found, returns -1.
162+
int FindIndexByMetadataTensorName(
163+
const flatbuffers::Vector<flatbuffers::Offset<TensorMetadata>>*
164+
tensor_metadatas,
165+
const std::string& name);
166+
159167
// Gets the tensor from a vector of tensors with name specified inside metadata.
160168
template <typename TensorType>
161169
static TensorType* FindTensorByName(
@@ -167,12 +175,8 @@ static TensorType* FindTensorByName(
167175
tensor_metadatas->size() != tensors.size()) {
168176
return nullptr;
169177
}
170-
for (flatbuffers::uoffset_t i = 0; i < tensor_metadatas->size(); i++) {
171-
if (strcmp(name.data(), tensor_metadatas->Get(i)->name()->c_str()) == 0) {
172-
return tensors[i];
173-
}
174-
}
175-
return nullptr;
178+
int i = FindIndexByMetadataTensorName(tensor_metadatas, name);
179+
return i == -1 ? nullptr : tensors[i];
176180
}
177181

178182
} // namespace core

tensorflow_lite_support/cc/task/processor/classification_postprocessor.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ limitations under the License.
2525
#include "tensorflow_lite_support/cc/task/core/score_calibration.h"
2626
#include "tensorflow_lite_support/cc/task/core/task_utils.h"
2727
#include "tensorflow_lite_support/cc/task/processor/processor.h"
28-
#include "tensorflow_lite_support/cc/task/processor/proto/class.proto.h"
29-
#include "tensorflow_lite_support/cc/task/processor/proto/classification_options.proto.h"
30-
#include "tensorflow_lite_support/cc/task/processor/proto/classifications.proto.h"
28+
#include "tensorflow_lite_support/cc/task/processor/proto/class.pb.h"
29+
#include "tensorflow_lite_support/cc/task/processor/proto/classification_options.pb.h"
30+
#include "tensorflow_lite_support/cc/task/processor/proto/classifications.pb.h"
3131

3232
namespace tflite {
3333
namespace task {

tensorflow_lite_support/cc/task/processor/embedding_postprocessor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ limitations under the License.
2222
#include "tensorflow_lite_support/cc/port/statusor.h"
2323
#include "tensorflow_lite_support/cc/task/core/tflite_engine.h"
2424
#include "tensorflow_lite_support/cc/task/processor/processor.h"
25-
#include "tensorflow_lite_support/cc/task/processor/proto/embedding_options.proto.h"
25+
#include "tensorflow_lite_support/cc/task/processor/proto/embedding_options.pb.h"
2626

2727
namespace tflite {
2828
namespace task {

tensorflow_lite_support/cc/task/text/BUILD

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,35 @@ cc_library_with_tflite(
8282
"@com_google_absl//absl/strings",
8383
],
8484
)
85+
86+
cc_library_with_tflite(
87+
name = "universal_sentence_encoder_qa",
88+
srcs = [
89+
"universal_sentence_encoder_qa.cc",
90+
],
91+
hdrs = [
92+
"universal_sentence_encoder_qa.h",
93+
],
94+
tflite_deps = [
95+
"@org_tensorflow//tensorflow/lite/core/shims:builtin_ops",
96+
"//tensorflow_lite_support/cc/task/core:base_task_api",
97+
"//tensorflow_lite_support/cc/task/core:task_api_factory",
98+
"//tensorflow_lite_support/cc/task/core:tflite_engine",
99+
],
100+
deps = [
101+
"//tensorflow_lite_support/cc/port:status_macros",
102+
"//tensorflow_lite_support/cc/port:statusor",
103+
"//tensorflow_lite_support/cc/task/core:task_utils",
104+
"//tensorflow_lite_support/cc/task/processor/proto:embedding_cc_proto",
105+
"//tensorflow_lite_support/cc/task/text/proto:retrieval_cc_proto",
106+
"//tensorflow_lite_support/cc/text/tokenizers:bert_tokenizer",
107+
"//tensorflow_lite_support/cc/text/tokenizers:sentencepiece_tokenizer",
108+
"//tensorflow_lite_support/cc/text/tokenizers:tokenizer",
109+
"//tensorflow_lite_support/cc/text/tokenizers:tokenizer_utils",
110+
"//tensorflow_lite_support/metadata:metadata_schema_cc",
111+
"@com_google_absl//absl/container:flat_hash_map",
112+
"@com_google_absl//absl/status",
113+
"@com_google_absl//absl/strings",
114+
"@com_google_absl//absl/strings:str_format",
115+
],
116+
)

tensorflow_lite_support/cc/task/text/proto/BUILD

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,29 @@ cc_library(
7676
"//tensorflow_lite_support/cc/task/core/proto:base_options_proto_inc",
7777
],
7878
)
79+
80+
proto_library(
81+
name = "retrieval_proto",
82+
srcs = ["retrieval.proto"],
83+
deps = [
84+
"//tensorflow_lite_support/cc/task/core/proto:base_options_proto",
85+
"//tensorflow_lite_support/cc/task/processor/proto:embedding_proto",
86+
],
87+
)
88+
89+
cc_proto_library(
90+
name = "retrieval_cc_proto",
91+
deps = [
92+
":retrieval_proto",
93+
],
94+
)
95+
96+
cc_library(
97+
name = "retrieval_proto_inc",
98+
hdrs = ["retrieval_proto_inc.h"],
99+
deps = [
100+
":retrieval_cc_proto",
101+
"//tensorflow_lite_support/cc/task/core/proto:base_options_proto_inc",
102+
"//tensorflow_lite_support/cc/task/vision/proto:embeddings_proto_inc",
103+
],
104+
)

0 commit comments

Comments
 (0)