Merge pull request #37890 from freedomtan:add_xnnpack_to_label_image_again
PiperOrigin-RevId: 304431767 Change-Id: Ieb1370560f7551fd0290d6176f11c618e177233e
This commit is contained in:
commit
e4efc51256
@ -33,6 +33,7 @@ cc_binary(
|
|||||||
"//tensorflow/lite:framework",
|
"//tensorflow/lite:framework",
|
||||||
"//tensorflow/lite:string_util",
|
"//tensorflow/lite:string_util",
|
||||||
"//tensorflow/lite/delegates/nnapi:nnapi_delegate",
|
"//tensorflow/lite/delegates/nnapi:nnapi_delegate",
|
||||||
|
"//tensorflow/lite/delegates/xnnpack:xnnpack_delegate",
|
||||||
"//tensorflow/lite/kernels:builtin_ops",
|
"//tensorflow/lite/kernels:builtin_ops",
|
||||||
"//tensorflow/lite/profiling:profiler",
|
"//tensorflow/lite/profiling:profiler",
|
||||||
"//tensorflow/lite/tools/evaluation:utils",
|
"//tensorflow/lite/tools/evaluation:utils",
|
||||||
|
@ -105,7 +105,7 @@ Run the model with NNAPI delegate (`-a 1`), `adb shell
|
|||||||
then you should see something like the followings: `Loaded model
|
then you should see something like the followings: `Loaded model
|
||||||
/data/local/tmp/mobilenet_v1_1.0_224.tflite resolved reporter INFO: Initialized
|
/data/local/tmp/mobilenet_v1_1.0_224.tflite resolved reporter INFO: Initialized
|
||||||
TensorFlow Lite runtime. INFO: Created TensorFlow Lite delegate for NNAPI.
|
TensorFlow Lite runtime. INFO: Created TensorFlow Lite delegate for NNAPI.
|
||||||
Applied NNAPI delegate.invoked average time: 10.348 ms 0.905401: 653 military
|
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:
|
uniform 0.0379589: 907 Windsor tie 0.00735866: 466 bulletproof vest 0.00605307:
|
||||||
458 bow tie 0.00422573: 514 cornet`
|
458 bow tie 0.00422573: 514 cornet`
|
||||||
|
|
||||||
@ -125,4 +125,13 @@ 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
|
0.0313726: 466 bulletproof vest 0.0313726: 458 bow tie 0.0117647: 700 panpipe
|
||||||
```
|
```
|
||||||
|
|
||||||
|
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`
|
||||||
|
|
||||||
See the `label_image.cc` source code for other command line options.
|
See the `label_image.cc` source code for other command line options.
|
||||||
|
@ -37,6 +37,7 @@ limitations under the License.
|
|||||||
|
|
||||||
#include "absl/memory/memory.h"
|
#include "absl/memory/memory.h"
|
||||||
#include "tensorflow/lite/delegates/nnapi/nnapi_delegate.h"
|
#include "tensorflow/lite/delegates/nnapi/nnapi_delegate.h"
|
||||||
|
#include "tensorflow/lite/delegates/xnnpack/xnnpack_delegate.h"
|
||||||
#include "tensorflow/lite/examples/label_image/bitmap_helpers.h"
|
#include "tensorflow/lite/examples/label_image/bitmap_helpers.h"
|
||||||
#include "tensorflow/lite/examples/label_image/get_top_n.h"
|
#include "tensorflow/lite/examples/label_image/get_top_n.h"
|
||||||
#include "tensorflow/lite/kernels/register.h"
|
#include "tensorflow/lite/kernels/register.h"
|
||||||
@ -101,6 +102,15 @@ TfLiteDelegatePtrMap GetDelegates(Settings* s) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (s->xnnpack_delegate) {
|
||||||
|
auto delegate = evaluation::CreateXNNPACKDelegate(s->number_of_threads);
|
||||||
|
if (!delegate) {
|
||||||
|
LOG(INFO) << "XNNPACK acceleration is unsupported on this platform.";
|
||||||
|
} else {
|
||||||
|
delegates.emplace("XNNPACK", std::move(delegate));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return delegates;
|
return delegates;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,6 +370,7 @@ void display_usage() {
|
|||||||
<< "--threads, -t: number of threads\n"
|
<< "--threads, -t: number of threads\n"
|
||||||
<< "--verbose, -v: [0|1] print more information\n"
|
<< "--verbose, -v: [0|1] print more information\n"
|
||||||
<< "--warmup_runs, -w: number of warmup runs\n"
|
<< "--warmup_runs, -w: number of warmup runs\n"
|
||||||
|
<< "--xnnpack_delegate, -x: xnnpack delegate\n"
|
||||||
<< "\n";
|
<< "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,13 +397,14 @@ int Main(int argc, char** argv) {
|
|||||||
{"warmup_runs", required_argument, nullptr, 'w'},
|
{"warmup_runs", required_argument, nullptr, 'w'},
|
||||||
{"gl_backend", required_argument, nullptr, 'g'},
|
{"gl_backend", required_argument, nullptr, 'g'},
|
||||||
{"hexagon_delegate", required_argument, nullptr, 'j'},
|
{"hexagon_delegate", required_argument, nullptr, 'j'},
|
||||||
|
{"xnnpack_delegate", required_argument, nullptr, 'x'},
|
||||||
{nullptr, 0, nullptr, 0}};
|
{nullptr, 0, nullptr, 0}};
|
||||||
|
|
||||||
/* getopt_long stores the option index here. */
|
/* getopt_long stores the option index here. */
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
|
|
||||||
c = getopt_long(argc, argv,
|
c = getopt_long(argc, argv,
|
||||||
"a:b:c:d:e:f:g:i:j:l:m:p:r:s:t:v:w:", long_options,
|
"a:b:c:d:e:f:g:i:j:l:m:p:r:s:t:v:w:x:", long_options,
|
||||||
&option_index);
|
&option_index);
|
||||||
|
|
||||||
/* Detect the end of the options. */
|
/* Detect the end of the options. */
|
||||||
@ -460,6 +472,9 @@ int Main(int argc, char** argv) {
|
|||||||
s.number_of_warmup_runs =
|
s.number_of_warmup_runs =
|
||||||
strtol(optarg, nullptr, 10); // NOLINT(runtime/deprecated_fn)
|
strtol(optarg, nullptr, 10); // NOLINT(runtime/deprecated_fn)
|
||||||
break;
|
break;
|
||||||
|
case 'x':
|
||||||
|
s.xnnpack_delegate = optarg;
|
||||||
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
case '?':
|
case '?':
|
||||||
/* getopt_long already printed an error message. */
|
/* getopt_long already printed an error message. */
|
||||||
|
@ -31,6 +31,7 @@ struct Settings {
|
|||||||
bool allow_fp16 = false;
|
bool allow_fp16 = false;
|
||||||
bool gl_backend = false;
|
bool gl_backend = false;
|
||||||
bool hexagon_delegate = false;
|
bool hexagon_delegate = false;
|
||||||
|
bool xnnpack_delegate = false;
|
||||||
int loop_count = 1;
|
int loop_count = 1;
|
||||||
float input_mean = 127.5f;
|
float input_mean = 127.5f;
|
||||||
float input_std = 127.5f;
|
float input_std = 127.5f;
|
||||||
|
7
third_party/cpuinfo/BUILD.bazel
vendored
7
third_party/cpuinfo/BUILD.bazel
vendored
@ -98,6 +98,7 @@ cc_library(
|
|||||||
srcs = select({
|
srcs = select({
|
||||||
":linux_x86_64": COMMON_SRCS + X86_SRCS + LINUX_SRCS + LINUX_X86_SRCS,
|
":linux_x86_64": COMMON_SRCS + X86_SRCS + LINUX_SRCS + LINUX_X86_SRCS,
|
||||||
":linux_aarch64": COMMON_SRCS + ARM_SRCS + LINUX_SRCS + LINUX_ARM64_SRCS,
|
":linux_aarch64": COMMON_SRCS + ARM_SRCS + LINUX_SRCS + LINUX_ARM64_SRCS,
|
||||||
|
":linux_arm": COMMON_SRCS + ARM_SRCS + LINUX_SRCS + LINUX_ARM32_SRCS,
|
||||||
":macos_x86_64": COMMON_SRCS + X86_SRCS + MACH_SRCS + MACH_X86_SRCS,
|
":macos_x86_64": COMMON_SRCS + X86_SRCS + MACH_SRCS + MACH_X86_SRCS,
|
||||||
":android_armv7": COMMON_SRCS + ARM_SRCS + LINUX_SRCS + LINUX_ARM32_SRCS + ANDROID_ARM_SRCS,
|
":android_armv7": COMMON_SRCS + ARM_SRCS + LINUX_SRCS + LINUX_ARM32_SRCS + ANDROID_ARM_SRCS,
|
||||||
":android_arm64": COMMON_SRCS + ARM_SRCS + LINUX_SRCS + LINUX_ARM64_SRCS + ANDROID_ARM_SRCS,
|
":android_arm64": COMMON_SRCS + ARM_SRCS + LINUX_SRCS + LINUX_ARM64_SRCS + ANDROID_ARM_SRCS,
|
||||||
@ -167,6 +168,12 @@ config_setting(
|
|||||||
values = {"cpu": "aarch64"},
|
values = {"cpu": "aarch64"},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
config_setting(
|
||||||
|
name = "linux_arm",
|
||||||
|
values = {"cpu": "arm"},
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
config_setting(
|
config_setting(
|
||||||
name = "macos_x86_64",
|
name = "macos_x86_64",
|
||||||
values = {
|
values = {
|
||||||
|
Loading…
Reference in New Issue
Block a user