Skip to content

Commit 03c2c84

Browse files
Merge pull request #713 from khanhlvg:c-object-detection-headers
PiperOrigin-RevId: 411174291
2 parents 203fd0c + dfdec7c commit 03c2c84

File tree

6 files changed

+351
-20
lines changed

6 files changed

+351
-20
lines changed

tensorflow_lite_support/c/task/processor/BUILD

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,20 @@ package(
33
licenses = ["notice"], # Apache 2.0
44
)
55

6+
cc_library(
7+
name = "category",
8+
hdrs = ["category.h"],
9+
)
10+
611
cc_library(
712
name = "classification_result",
813
srcs = [
914
"classification_result.cc",
1015
],
1116
hdrs = ["classification_result.h"],
17+
deps = [
18+
":category",
19+
],
1220
)
1321

1422
cc_library(
@@ -20,3 +28,15 @@ cc_library(
2028
name = "classification_options",
2129
hdrs = ["classification_options.h"],
2230
)
31+
32+
cc_library(
33+
name = "detection_result",
34+
srcs = [
35+
"detection_result.cc",
36+
],
37+
hdrs = ["detection_result.h"],
38+
deps = [
39+
":bounding_box",
40+
":category",
41+
],
42+
)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* Copyright 2021 The TensorFlow Authors. All Rights Reserved.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
==============================================================================*/
15+
#ifndef TENSORFLOW_LITE_SUPPORT_C_TASK_PROCESSOR_CATEGORY_H_
16+
#define TENSORFLOW_LITE_SUPPORT_C_TASK_PROCESSOR_CATEGORY_H_
17+
18+
// Defines C structure for a Category which encapsulates a single predicted
19+
// class.
20+
21+
#ifdef __cplusplus
22+
extern "C" {
23+
#endif // __cplusplus
24+
25+
// A single predicted class.
26+
typedef struct TfLiteCategory {
27+
// The index of the class in the corresponding label map, usually packed in
28+
// the TFLite Model Metadata [1].
29+
//
30+
// [1]: https://www.tensorflow.org/lite/convert/metadata
31+
int index;
32+
33+
// The score for this class e.g. (but not necessarily) a probability in [0,1].
34+
float score;
35+
36+
// A human readable name of the class filled from the label map.
37+
char* display_name;
38+
// An ID for the class, not necessarily human-readable (e.g. a Google
39+
// Knowledge Graph ID [1]), filled from the label map.
40+
//
41+
// [1]: https://developers.google.com/knowledge-graph
42+
char* label;
43+
} TfLiteCategory;
44+
45+
#ifdef __cplusplus
46+
} // extern "C"
47+
#endif // __cplusplus
48+
49+
#endif // TENSORFLOW_LITE_SUPPORT_C_TASK_VISION_CATEGORY_H_

tensorflow_lite_support/c/task/processor/classification_result.h

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,14 @@ limitations under the License.
1515
#ifndef TENSORFLOW_LITE_SUPPORT_C_TASK_PROCESSOR_CLASSIFICATION_RESULT_H_
1616
#define TENSORFLOW_LITE_SUPPORT_C_TASK_PROCESSOR_CLASSIFICATION_RESULT_H_
1717

18+
#include "tensorflow_lite_support/c/task/processor/category.h"
19+
1820
// Defines C structure for Classification Results and associated helper methods.
1921

2022
#ifdef __cplusplus
2123
extern "C" {
2224
#endif // __cplusplus
2325

24-
// A single predicted class.
25-
typedef struct TfLiteCategory {
26-
// The index of the class in the corresponding label map, usually packed in
27-
// the TFLite Model Metadata [1].
28-
//
29-
// [1]: https://www.tensorflow.org/lite/convert/metadata
30-
int index;
31-
32-
// The score for this class e.g. (but not necessarily) a probability in [0,1].
33-
float score;
34-
35-
// A human readable name of the class filled from the label map.
36-
char* display_name;
37-
// An ID for the class, not necessarily human-readable (e.g. a Google
38-
// Knowledge Graph ID [1]), filled from the label map.
39-
//
40-
// [1]: https://developers.google.com/knowledge-graph
41-
char* label;
42-
} TfLiteCategory;
43-
4426
// List of predicted classes (aka labels) for a given image classifier head.
4527
typedef struct TfLiteClassifications {
4628
// The index of the image classifier head these classes refer to. This is
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/* Copyright 2021 The TensorFlow Authors. All Rights Reserved.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
==============================================================================*/
15+
#ifndef TENSORFLOW_LITE_SUPPORT_C_TASK_PROCESSOR_DETECTION_RESULT_H_
16+
#define TENSORFLOW_LITE_SUPPORT_C_TASK_PROCESSOR_DETECTION_RESULT_H_
17+
18+
#include "tensorflow_lite_support/c/task/processor/bounding_box.h"
19+
#include "tensorflow_lite_support/c/task/processor/category.h"
20+
21+
// Defines C structure for Object Detection Results and associated helper
22+
// methods.
23+
24+
#ifdef __cplusplus
25+
extern "C" {
26+
#endif // __cplusplus
27+
28+
// Bounding box and list of predicted classes (aka labels) for a detected
29+
// object.
30+
typedef struct TfLiteDetection {
31+
// The bounding box of the detected object.
32+
TfLiteBoundingBox bounding_box;
33+
34+
// The array of predicted classes for the object detection represented by an
35+
// instance of TfLiteDetection, usually sorted by descending scores (e.g. from
36+
// high to low probability). Since this array is dynamically allocated, use
37+
// size to traverse through the array.
38+
TfLiteCategory* categories;
39+
40+
// Number of detectd objects be used to traverse the array of the detected
41+
// objects.
42+
int size;
43+
} TfLiteDetection;
44+
45+
// Holds Object Detection results.
46+
// Contains one set of results per detected object.
47+
typedef struct TfLiteDetectionResult {
48+
// Number of detectd objects be used to traverse the array of the detected
49+
// objects.
50+
int size;
51+
52+
// Array of results per detected object. This array can
53+
// have any number of results. size holds the size of this array. size should
54+
// be used to traverse this array.
55+
TfLiteDetection* detections;
56+
} TfLiteDetectionResult;
57+
58+
// Frees up the DetectionResult Structure.
59+
void TfLiteDetectionResultDelete(TfLiteDetectionResult* detection_result);
60+
61+
#ifdef __cplusplus
62+
} // extern "C"
63+
#endif // __cplusplus
64+
65+
#endif // TENSORFLOW_LITE_SUPPORT_C_TASK_VISION_DETECTION_H_

tensorflow_lite_support/c/task/vision/BUILD

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,20 @@ cc_library_with_tflite(
3131
"//tensorflow_lite_support/cc/task/vision/proto:image_classifier_options_proto_inc",
3232
],
3333
)
34+
35+
cc_library_with_tflite(
36+
name = "object_detector",
37+
hdrs = [
38+
"object_detector.h",
39+
],
40+
tflite_deps = [
41+
"//tensorflow_lite_support/cc/task/vision:object_detector",
42+
],
43+
deps = [
44+
"//tensorflow_lite_support/c:common",
45+
"//tensorflow_lite_support/c/task/core:base_options",
46+
"//tensorflow_lite_support/c/task/processor:classification_options",
47+
"//tensorflow_lite_support/c/task/processor:detection_result",
48+
"//tensorflow_lite_support/c/task/vision/core:frame_buffer",
49+
],
50+
)

0 commit comments

Comments
 (0)