STT-tensorflow/tensorflow/tools/benchmark
Andy Ly 46040c2d00 Update references from android_tensorflow_lib to portable_tensorflow_lib.
android_tensorflow_lib alias was removed.

PiperOrigin-RevId: 335643116
Change-Id: Ifd899ec6307910aaa87ff1110925ae499c338040
2020-10-06 08:26:04 -07:00
..
benchmark_model_main.cc
benchmark_model_test.cc
benchmark_model.cc
benchmark_model.h
BUILD Update references from android_tensorflow_lib to portable_tensorflow_lib. 2020-10-06 08:26:04 -07:00
README.md Add code ticks around pushing model to device example, and spacing for code blocks. 2020-09-29 14:57:47 -07:00

TensorFlow Model Benchmark Tool

Description

A simple C++ binary to benchmark a compute graph and its individual operators, both on desktop machines and on Android.

To build/install/run

On Android:

(0) Refer to https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/android to edit the WORKSPACE to configure the android NDK/SDK.

(1) build for your specific platform, e.g.:

bazel build -c opt \
  --crosstool_top=//external:android/crosstool \
  --cpu=armeabi-v7a \
  --host_crosstool_top=@bazel_tools//tools/cpp:toolchain \
  --config monolithic \
  tensorflow/tools/benchmark:benchmark_model

(2) Connect your phone. Push the binary to your phone with adb push (make the directory if required):

adb push bazel-bin/tensorflow/tools/benchmark/benchmark_model /data/local/tmp

(3) Push the compute graph that you need to test. For example:

adb push tensorflow_inception_graph.pb /data/local/tmp

(4) Run the benchmark. For example:

adb shell /data/local/tmp/benchmark_model \
  --graph=/data/local/tmp/tensorflow_inception_graph.pb \
  --input_layer="input:0" \
  --input_layer_shape="1,224,224,3" \
  --input_layer_type="float" \
  --output_layer="output:0"

On desktop:

(1) build the binary

bazel build -c opt tensorflow/tools/benchmark:benchmark_model

(2) Run on your compute graph, similar to the Android case but without the need of adb shell. For example:

bazel-bin/tensorflow/tools/benchmark/benchmark_model \
  --graph=tensorflow_inception_graph.pb \
  --input_layer="input:0" \
  --input_layer_shape="1,224,224,3" \
  --input_layer_type="float" \
  --output_layer="output:0"

The Inception graph used as an example here may be downloaded from https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip