From f208ff6827e17fe773cf59192abaaa3f90bd16ad Mon Sep 17 00:00:00 2001 From: Koan-Sin Tan Date: Mon, 11 May 2020 17:14:11 +0800 Subject: [PATCH 1/2] [tflite] reformat/cleanup label_image readme.md --- .../lite/examples/label_image/README.md | 124 +++++++++++++----- 1 file changed, 88 insertions(+), 36 deletions(-) diff --git a/tensorflow/lite/examples/label_image/README.md b/tensorflow/lite/examples/label_image/README.md index 09e9e77b86a..9d37c153361 100644 --- a/tensorflow/lite/examples/label_image/README.md +++ b/tensorflow/lite/examples/label_image/README.md @@ -90,48 +90,100 @@ adb push tensorflow/lite/examples/label_image/testdata/grace_hopper.bmp /data/l adb push /tmp/labels.txt /data/local/tmp ``` -Run it, `adb shell "/data/local/tmp/label_image \ -m -/data/local/tmp/mobilenet_v1_1.0_224.tflite \ -i -/data/local/tmp/grace_hopper.bmp \ -l /data/local/tmp/labels.txt"` then you -should see something like the followings: `Loaded model -/data/local/tmp/mobilenet_v1_1.0_224.tflite resolved reporter INFO: Initialized -TensorFlow Lite runtime. invoked average time: 25.03 ms 0.907071: 653 military -uniform 0.0372416: 907 Windsor tie 0.00733753: 466 bulletproof vest 0.00592852: -458 bow tie 0.00414091: 514 cornet` +Run it, +``` +adb shell "/data/local/tmp/label_image \ + -m /data/local/tmp/mobilenet_v1_1.0_224.tflite \ + -i /data/local/tmp/grace_hopper.bmp \ + -l /data/local/tmp/labels.txt" +``` +then you should see something like the followings: +``` +Loaded model /data/local/tmp/mobilenet_v1_1.0_224.tflite +resolved reporter +INFO: Initialized +TensorFlow Lite runtime. +invoked +average time: 25.03 ms +0.907071: 653 military uniform +0.0372416: 907 Windsor tie +0.00733753: 466 bulletproof vest +0.00592852: 458 bow tie +0.00414091: 514 cornet +``` -Run the model with NNAPI delegate (`-a 1`), `adb shell -"/data/local/tmp/label_image \ -m /data/local/tmp/mobilenet_v1_1.0_224.tflite \ --i /data/local/tmp/grace_hopper.bmp \ -l /data/local/tmp/labels.txt -a 1 -f 1"` -then you should see something like the followings: `Loaded model -/data/local/tmp/mobilenet_v1_1.0_224.tflite resolved reporter INFO: Initialized -TensorFlow Lite runtime. INFO: Created TensorFlow Lite delegate for NNAPI. -Applied NNAPI delegate. invoked average time:10.348 ms 0.905401: 653 military -uniform 0.0379589: 907 Windsor tie 0.00735866: 466 bulletproof vest 0.00605307: -458 bow tie 0.00422573: 514 cornet` +Run the model with NNAPI delegate (`-a 1`), +``` +adb shell "/data/local/tmp/label_image \ + -m /data/local/tmp/mobilenet_v1_1.0_224.tflite \ + -i /data/local/tmp/grace_hopper.bmp \ + -l /data/local/tmp/labels.txt -a 1 -f 1" +``` +then you should see something like the followings: +``` +Loaded model /data/local/tmp/mobilenet_v1_1.0_224.tflite +resolved reporter +INFO: Initialized +TensorFlow Lite runtime. +INFO: Created TensorFlow Lite delegate for NNAPI. +Applied NNAPI delegate. +invoked +average time:10.348 ms +0.905401: 653 military uniform +0.0379589: 907 Windsor tie +0.00735866: 466 bulletproof vest +0.00605307: 458 bow tie +0.00422573: 514 cornet +``` To run a model with the Hexagon Delegate, assuming we have followed the [Hexagon Delegate Guide](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/g3doc/performance/hexagon_delegate.md) -and installed Hexagon libraries in `/data/local/tmp`. Run it `adb shell -"/data/local/tmp/label_image \ -m -/data/local/tmp/mobilenet_v1_1.0_224_quant.tflite \ -i -/data/local/tmp/grace_hopper.bmp \ -l /data/local/tmp/labels.txt -j 1"` then you -should see something like the followings: ``` Loaded model -/data/local/tmp/mobilenet_v1_1.0_224_quant.tflite resolved reporter INFO: -Initialized TensorFlow Lite runtime. INFO: Created TensorFlow Lite delegate for -Hexagon. INFO: Hexagon delegate: 31 nodes delegated out of 31 nodes. +and installed Hexagon libraries in `/data/local/tmp`. Run it +``` +adb shell \ + "/data/local/tmp/label_image \ + -m /data/local/tmp/mobilenet_v1_1.0_224_quant.tflite \ + -i /data/local/tmp/grace_hopper.bmp \ + -l /data/local/tmp/labels.txt -j 1" +``` +then you should see something like the followings: +``` +Loaded model /data/local/tmp/mobilenet_v1_1.0_224_quant.tflite +resolved reporter +INFO: Initialized TensorFlow Lite runtime. +loaded libcdsprpc.so +INFO: Created TensorFlow Lite delegate for Hexagon. +INFO: Hexagon delegate: 31 nodes delegated out of 31 nodes with 1 partitions. -remote_handle_control available and used Applied Hexagon delegate.invoked -average time: 8.307 ms 0.729412: 653 military uniform 0.0980392: 907 Windsor tie -0.0313726: 466 bulletproof vest 0.0313726: 458 bow tie 0.0117647: 700 panpipe +Applied Hexagon delegate.invoked +average time: 4.231 ms +0.639216: 458 bow tie +0.329412: 653 military uniform +0.00784314: 835 suit +0.00784314: 611 jersey +0.00392157: 514 cornet ``` -Run the model with the XNNPACK delegate (`-x 1`), `adb shell -"/data/local/tmp/label_image \ -m /data/local/tmp/mobilenet_v1_1.0_224.tflite \ --i /data/local/tmp/grace_hopper.bmp \ -l /data/local/tmp/labels.txt -x 1"` then -you should see something like the followings: `Loaded model -/data/local/tmp/mobilenet_v1_1.0_224.tflite resolved reporter INFO: Initialized -TensorFlow Lite runtime. Applied XNNPACK delegate.invoked average time: 11.0237 -ms 0.90707: 653 military uniform 0.0372418: 907 Windsor tie 0.0073376: 466 -bulletproof vest 0.00592856: 458 bow tie 0.00414093: 514 cornet` +Run the model with the XNNPACK delegate (`-x 1`), +``` +adb shell \ + "/data/local/tmp/label_image \ + -m /data/local/tmp/mobilenet_v1_1.0_224.tflite \ + -i /data/local/tmp/grace_hopper.bmp \ + -l /data/local/tmp/labels.txt -x 1" +``` +then you should see something like the followings: +``` +Loaded model /data/local/tmp/mobilenet_v1_1.0_224.tflite +resolved reporter +INFO: Initialized TensorFlow Lite runtime. +Applied XNNPACK delegate.invoked +average time: 17.33 ms +0.90707: 653 military uniform +0.0372418: 907 Windsor tie +0.0073376: 466 bulletproof vest +0.00592857: 458 bow tie +0.00414093: 514 cornet +``` See the `label_image.cc` source code for other command line options. From b79631972128ab60c1f646dca68867459f5cb102 Mon Sep 17 00:00:00 2001 From: Koan-Sin Tan Date: Wed, 13 May 2020 07:06:27 +0800 Subject: [PATCH 2/2] list command line flags in readme And update some `usage()` descriptions --- .../lite/examples/label_image/README.md | 27 ++++++++++++++++++- .../lite/examples/label_image/label_image.cc | 6 ++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/tensorflow/lite/examples/label_image/README.md b/tensorflow/lite/examples/label_image/README.md index 9d37c153361..9ca8fd05e09 100644 --- a/tensorflow/lite/examples/label_image/README.md +++ b/tensorflow/lite/examples/label_image/README.md @@ -138,7 +138,7 @@ average time:10.348 ms To run a model with the Hexagon Delegate, assuming we have followed the [Hexagon Delegate Guide](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/g3doc/performance/hexagon_delegate.md) -and installed Hexagon libraries in `/data/local/tmp`. Run it +and installed Hexagon libraries in `/data/local/tmp`. Run it wth (`-j 1`) ``` adb shell \ "/data/local/tmp/label_image \ @@ -186,4 +186,29 @@ average time: 17.33 ms 0.00414093: 514 cornet ``` +With `-h` or any other unsupported flags, `label_image` will list +supported options +``` +sargo:/data/local/tmp $ ./label_image -h +./label_image: invalid option -- h +label_image +--accelerated, -a: [0|1], use Android NNAPI or not +--old_accelerated, -d: [0|1], use old Android NNAPI delegate or not +--allow_fp16, -f: [0|1], allow running fp32 models with fp16 or not +--count, -c: loop interpreter->Invoke() for certain times +--gl_backend, -g: [0|1]: use GL GPU Delegate on Android +--hexagon_delegate, -j: [0|1]: use Hexagon Delegate on Android +--input_mean, -b: input mean +--input_std, -s: input standard deviation +--image, -i: image_name.bmp +--labels, -l: labels for the model +--tflite_model, -m: model_name.tflite +--profiling, -p: [0|1], profiling or not +--num_results, -r: number of results to show +--threads, -t: number of threads +--verbose, -v: [0|1] print more information +--warmup_runs, -w: number of warmup runs +--xnnpack_delegate, -x [0:1]: xnnpack delegate +``` + See the `label_image.cc` source code for other command line options. diff --git a/tensorflow/lite/examples/label_image/label_image.cc b/tensorflow/lite/examples/label_image/label_image.cc index ec744d70381..364ac325967 100644 --- a/tensorflow/lite/examples/label_image/label_image.cc +++ b/tensorflow/lite/examples/label_image/label_image.cc @@ -362,8 +362,8 @@ void display_usage() { << "--old_accelerated, -d: [0|1], use old Android NNAPI delegate or not\n" << "--allow_fp16, -f: [0|1], allow running fp32 models with fp16 or not\n" << "--count, -c: loop interpreter->Invoke() for certain times\n" - << "--gl_backend, -g: use GL GPU Delegate on Android\n" - << "--hexagon_delegate: use Hexagon Delegate on Android\n" + << "--gl_backend, -g: [0|1]: use GL GPU Delegate on Android\n" + << "--hexagon_delegate, -j: [0|1]: use Hexagon Delegate on Android\n" << "--input_mean, -b: input mean\n" << "--input_std, -s: input standard deviation\n" << "--image, -i: image_name.bmp\n" @@ -374,7 +374,7 @@ void display_usage() { << "--threads, -t: number of threads\n" << "--verbose, -v: [0|1] print more information\n" << "--warmup_runs, -w: number of warmup runs\n" - << "--xnnpack_delegate, -x: xnnpack delegate\n" + << "--xnnpack_delegate, -x [0:1]: xnnpack delegate\n" << "\n"; }