Skip to content

Commit cf2bec4

Browse files
lu-wang-gtflite-support-robot
authored andcommitted
Enable the Kokoro test for Task C API
PiperOrigin-RevId: 398860212
1 parent 561471b commit cf2bec4

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
lines changed

tensorflow_lite_support/c/task/processor/classification_options.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,17 @@ typedef struct TfLiteClassificationOptions {
4545
// class labels are ignored. Mutually exclusive with label_denylist.
4646
TfLiteStringArrayOption label_allowlist;
4747

48+
// The locale to use for display names specified through the TFLite Model
49+
// Metadata, if any. Defaults to English.
4850
const char* display_names_local;
51+
52+
// The maximum number of top-scored classification results to return. If < 0,
53+
// all available results will be returned. If 0, an invalid argument error is
54+
// returned. Defaults to -1.
4955
int max_results;
56+
57+
// Score threshold, overrides the ones provided in the model metadata
58+
// (if any). Results below this value are rejected.
5059
float score_threshold;
5160
} TfLiteClassificationOptions;
5261

tensorflow_lite_support/c/task/vision/image_classifier.cc

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,6 @@ using ImageClassifierCpp = ::tflite::task::vision::ImageClassifier;
3232
using ImageClassifierOptionsCpp =
3333
::tflite::task::vision::ImageClassifierOptions;
3434
using FrameBufferCpp = ::tflite::task::vision::FrameBuffer;
35-
} // namespace
36-
37-
#ifdef __cplusplus
38-
extern "C" {
39-
#endif // __cplusplus
40-
41-
struct TfLiteImageClassifier {
42-
std::unique_ptr<ImageClassifierCpp> impl;
43-
};
44-
45-
TfLiteImageClassifierOptions TfLiteImageClassifierOptionsCreate() {
46-
return {.classification_options = {.max_results = -1},
47-
.base_options = {
48-
.compute_settings = {.cpu_settings = {.num_threads = -1}}}};
49-
}
5035

5136
std::unique_ptr<ImageClassifierOptionsCpp>
5237
CreateImageClassifierCppOptionsFromCOptions(
@@ -98,6 +83,24 @@ CreateImageClassifierCppOptionsFromCOptions(
9883

9984
return cpp_options;
10085
}
86+
} // namespace
87+
88+
#ifdef __cplusplus
89+
extern "C" {
90+
#endif // __cplusplus
91+
92+
struct TfLiteImageClassifier {
93+
std::unique_ptr<ImageClassifierCpp> impl;
94+
};
95+
96+
TfLiteImageClassifierOptions TfLiteImageClassifierOptionsCreate() {
97+
// Use brace-enclosed initializer list will break the Kokoro test.
98+
TfLiteImageClassifierOptions options = {{{0}}};
99+
options.classification_options.max_results = -1;
100+
options.classification_options.score_threshold = 0.0;
101+
options.base_options.compute_settings.cpu_settings.num_threads = -1;
102+
return options;
103+
}
101104

102105
TfLiteImageClassifier* TfLiteImageClassifierFromOptions(
103106
const TfLiteImageClassifierOptions* options) {

tensorflow_lite_support/tools/ci_build/build_all.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ bazel build -c opt ${BAZEL_PARALLEL} --define=darwinn_portable=1 \
5656
bazel clean
5757

5858
bazel test $BAZEL_PARALLEL --test_output=all \
59+
//tensorflow_lite_support/c/test/... \
5960
//tensorflow_lite_support/cc/test/task/vision:all \
6061
//tensorflow_lite_support/custom_ops/kernel/sentencepiece:all \
6162
//tensorflow_lite_support/metadata/python/tests:metadata_test \

0 commit comments

Comments
 (0)