-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
13 changed files
with
1,162 additions
and
0 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
tensorflow_lite_support/examples/task/vision/desktop/BUILD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package( | ||
default_visibility = [ | ||
"//tensorflow_lite_support:users", | ||
], | ||
licenses = ["notice"], # Apache 2.0 | ||
) | ||
|
||
cc_binary( | ||
name = "image_classifier_demo", | ||
srcs = ["image_classifier_demo.cc"], | ||
deps = [ | ||
"//tensorflow_lite_support/cc/port:statusor", | ||
"//tensorflow_lite_support/cc/task/core:external_file_handler", | ||
"//tensorflow_lite_support/cc/task/core/proto:external_file_proto_inc", | ||
"//tensorflow_lite_support/cc/task/vision:image_classifier", | ||
"//tensorflow_lite_support/cc/task/vision/proto:class_proto_inc", | ||
"//tensorflow_lite_support/cc/task/vision/proto:classifications_proto_inc", | ||
"//tensorflow_lite_support/cc/task/vision/proto:image_classifier_options_proto_inc", | ||
"//tensorflow_lite_support/cc/task/vision/utils:frame_buffer_common_utils", | ||
"//tensorflow_lite_support/examples/task/vision/desktop/utils:image_utils", | ||
"@com_google_absl//absl/flags:flag", | ||
"@com_google_absl//absl/flags:parse", | ||
"@com_google_absl//absl/status", | ||
"@com_google_absl//absl/strings:str_format", | ||
"@org_tensorflow//tensorflow/core:lib", | ||
], | ||
) | ||
|
||
cc_binary( | ||
name = "object_detector_demo", | ||
srcs = ["object_detector_demo.cc"], | ||
deps = [ | ||
"//tensorflow_lite_support/cc/port:statusor", | ||
"//tensorflow_lite_support/cc/task/core:external_file_handler", | ||
"//tensorflow_lite_support/cc/task/core/proto:external_file_proto_inc", | ||
"//tensorflow_lite_support/cc/task/vision:object_detector", | ||
"//tensorflow_lite_support/cc/task/vision/proto:bounding_box_proto_inc", | ||
"//tensorflow_lite_support/cc/task/vision/proto:class_proto_inc", | ||
"//tensorflow_lite_support/cc/task/vision/proto:detections_proto_inc", | ||
"//tensorflow_lite_support/cc/task/vision/proto:object_detector_options_proto_inc", | ||
"//tensorflow_lite_support/cc/task/vision/utils:frame_buffer_common_utils", | ||
"//tensorflow_lite_support/examples/task/vision/desktop/utils:image_utils", | ||
"@com_google_absl//absl/flags:flag", | ||
"@com_google_absl//absl/flags:parse", | ||
"@com_google_absl//absl/status", | ||
"@com_google_absl//absl/strings", | ||
"@com_google_absl//absl/strings:str_format", | ||
"@org_tensorflow//tensorflow/core:lib", | ||
], | ||
) | ||
|
||
cc_binary( | ||
name = "image_segmenter_demo", | ||
srcs = ["image_segmenter_demo.cc"], | ||
deps = [ | ||
"//tensorflow_lite_support/cc/port:statusor", | ||
"//tensorflow_lite_support/cc/task/core:external_file_handler", | ||
"//tensorflow_lite_support/cc/task/core/proto:external_file_proto_inc", | ||
"//tensorflow_lite_support/cc/task/vision:image_segmenter", | ||
"//tensorflow_lite_support/cc/task/vision/proto:image_segmenter_options_proto_inc", | ||
"//tensorflow_lite_support/cc/task/vision/proto:segmentations_proto_inc", | ||
"//tensorflow_lite_support/cc/task/vision/utils:frame_buffer_common_utils", | ||
"//tensorflow_lite_support/examples/task/vision/desktop/utils:image_utils", | ||
"@com_google_absl//absl/flags:flag", | ||
"@com_google_absl//absl/flags:parse", | ||
"@com_google_absl//absl/status", | ||
"@com_google_absl//absl/strings", | ||
"@com_google_absl//absl/strings:str_format", | ||
"@org_tensorflow//tensorflow/core:lib", | ||
], | ||
) |
181 changes: 181 additions & 0 deletions
181
tensorflow_lite_support/examples/task/vision/desktop/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
# CLI Demos for C++ Vision Task APIs | ||
|
||
This folder contains simple command-line tools for easily trying out the C++ | ||
Vision Task APIs. | ||
|
||
## Image Classifier | ||
|
||
#### Prerequisites | ||
|
||
You will need: | ||
|
||
* a TFLite image classification model (e.g. [aiy/vision/classifier/birds_V1] | ||
(https://tfhub.dev/google/lite-model/aiy/vision/classifier/birds_V1/2), | ||
a bird classification model available on TensorFlow Hub), | ||
* a PNG, JPEG or GIF image to run classification on, e.g.: | ||
|
||
![sparrow](g3doc/sparrow.jpg) | ||
|
||
#### Usage | ||
|
||
In the console, run: | ||
|
||
```bash | ||
# Download the model: | ||
curl \ | ||
-L https://tfhub.dev/google/lite-model/aiy/vision/classifier/birds_V1/2?lite-format=tflite \ | ||
-o /tmp/aiy_vision_classifier_birds_V1_2.tflite | ||
|
||
# Run the classification tool: | ||
bazel run -c opt examples/task/vision/desktop:image_classifier_demo -- \ | ||
--model_path=/tmp/aiy_vision_classifier_birds_V1_2.tflite \ | ||
--image_path=$(pwd)/examples/task/vision/desktop/g3doc/sparrow.jpg \ | ||
--max_results=3 | ||
``` | ||
|
||
#### Results | ||
|
||
In the console, you should get: | ||
|
||
``` | ||
Results: | ||
Rank #0: | ||
index : 671 | ||
score : 0.91797 | ||
class name : /m/01bwbt | ||
display name: Passer montanus | ||
Rank #1: | ||
index : 670 | ||
score : 0.00391 | ||
class name : /m/0193xp | ||
display name: Troglodytes hiemalis | ||
Rank #2: | ||
index : 495 | ||
score : 0.00391 | ||
class name : /m/05sjn7 | ||
display name: Mimus gilvus | ||
``` | ||
|
||
## Object Detector | ||
|
||
#### Prerequisites | ||
|
||
TODO(b/161960089): the model used in this example has an off-by-one error in its | ||
label map, which will cause the model to return "cat" instead of "dog" in the | ||
following example. It will soon be updated on tfhub.dev with a fix. | ||
|
||
You will need: | ||
|
||
* a TFLite object detection model (e.g. [ssd_mobilenet_v1] | ||
(https://tfhub.dev/tensorflow/lite-model/ssd_mobilenet_v1/1/metadata/1), | ||
a generic object detection model available on TensorFlow Hub), | ||
* a PNG, JPEG or GIF image to run detection on, e.g.: | ||
|
||
![dogs](g3doc/dogs.jpg) | ||
|
||
#### Usage | ||
|
||
In the console, run: | ||
|
||
```bash | ||
# Download the model: | ||
curl \ | ||
-L https://tfhub.dev/tensorflow/lite-model/ssd_mobilenet_v1/1/metadata/1?lite-format=tflite \ | ||
-o /tmp/ssd_mobilenet_v1_1_metadata_1.tflite | ||
|
||
# Run the detection tool: | ||
bazel run -c opt examples/task/vision/desktop:object_detector_demo -- \ | ||
--model_path=/tmp/ssd_mobilenet_v1_1_metadata_1.tflite \ | ||
--image_path=$(pwd)/examples/task/vision/desktop/g3doc/dogs.jpg \ | ||
--output_png=/tmp/detection-output.png \ | ||
--max_results=2 | ||
``` | ||
|
||
#### Results | ||
|
||
In the console, you should get: | ||
|
||
``` | ||
Results saved to: /tmp/detection-output.png | ||
Results: | ||
Detection #0 (red): | ||
Box: (x: 355, y: 133, w: 190, h: 206) | ||
Top-1 class: | ||
index : 17 | ||
score : 0.73828 | ||
class name : dog | ||
Detection #1 (green): | ||
Box: (x: 103, y: 15, w: 138, h: 369) | ||
Top-1 class: | ||
index : 17 | ||
score : 0.73047 | ||
class name : dog | ||
``` | ||
|
||
And `/tmp/detection-output.jpg` should contain: | ||
|
||
![detection-output](g3doc/detection-output.png) | ||
|
||
## Image Segmenter | ||
|
||
#### Prerequisites | ||
|
||
TODO(b/161957922): the model used in this example doesn't include a label map, | ||
which will cause the console output to be less complete than in the example | ||
below. It will soon be updated on tfhub.dev with a fix. | ||
|
||
You will need: | ||
|
||
* a TFLite image segmentation model (e.g. [deeplab_v3] | ||
(https://tfhub.dev/tensorflow/lite-model/deeplabv3/1/metadata/1), | ||
a generic segmentation model available on TensorFlow Hub), | ||
* a PNG, JPEG or GIF image to run segmentation on, e.g.: | ||
|
||
![plane](g3doc/plane.jpg) | ||
|
||
#### Usage | ||
|
||
In the console, run: | ||
|
||
```bash | ||
# Download the model: | ||
curl \ | ||
-L https://tfhub.dev/tensorflow/lite-model/deeplabv3/1/metadata/1?lite-format=tflite \ | ||
-o /tmp/deeplabv3_1_metadata_1.tflite | ||
|
||
# Run the segmentation tool: | ||
bazel run -c opt examples/task/vision/desktop:image_segmenter_demo -- \ | ||
--model_path=/tmp/deeplabv3_1_metadata_1.tflite \ | ||
--image_path=$(pwd)/examples/task/vision/desktop/g3doc/plane.jpg \ | ||
--output_mask_png=/tmp/segmentation-output.png | ||
``` | ||
|
||
#### Results | ||
|
||
In the console, you should get: | ||
|
||
``` | ||
Category mask saved to: /tmp/segmentation-output.png | ||
Color Legend: | ||
(r: 000, g: 000, b: 000): | ||
index : 0 | ||
class name : background | ||
(r: 128, g: 000, b: 000): | ||
index : 1 | ||
class name : aeroplane | ||
# (omitting multiple lines for conciseness) ... | ||
(r: 128, g: 192, b: 000): | ||
index : 19 | ||
class name : train | ||
(r: 000, g: 064, b: 128): | ||
index : 20 | ||
class name : tv | ||
Tip: use a color picker on the output PNG file to inspect the output mask with | ||
this legend. | ||
``` | ||
|
||
And `/tmp/segmentation-output.jpg` should contain the segmentation mask: | ||
|
||
![segmentation-output](g3doc/segmentation-output.png) |
Binary file added
BIN
+512 KB
tensorflow_lite_support/examples/task/vision/desktop/g3doc/detection-output.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.01 KB
tensorflow_lite_support/examples/task/vision/desktop/g3doc/segmentation-output.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.