summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/CMakeLists.txt11
-rw-r--r--tools/cross/arm/sources.list.bionic11
-rwxr-xr-xtools/cross/build_rootfs.sh3
-rw-r--r--tools/modelgen/CONV_2D.template.json102
-rwxr-xr-xtools/modelgen/modelgen.py98
-rwxr-xr-xtools/modelgen/modelgen.sh31
-rw-r--r--tools/nnapi_quickcheck/CMakeLists.txt4
-rw-r--r--tools/nnapi_quickcheck/tests/add_1.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/add_2.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/add_3.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/add_4.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/add_5.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/add_6.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/add_7.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/add_8.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/add_9.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/add_quan_1.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/avg_pool_1.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/avg_pool_quan_1.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/cast_1.cpp6
-rw-r--r--tools/nnapi_quickcheck/tests/cast_2.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/cast_q_to_f_1.cpp6
-rw-r--r--tools/nnapi_quickcheck/tests/concat_1.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/concat_quan_1.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/conv_1.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/conv_quan_1.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/dconv_1.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/dconv_quan_1.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/dequantize_1.cpp6
-rw-r--r--tools/nnapi_quickcheck/tests/div_1.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/div_2.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/fully_connected_1.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/fully_connected_quan_1.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/gather_1.cpp6
-rw-r--r--tools/nnapi_quickcheck/tests/gather_2.cpp6
-rw-r--r--tools/nnapi_quickcheck/tests/logistic_quan_1.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/max_pool_1.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/max_pool_quan_1.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/mul_1.cpp6
-rw-r--r--tools/nnapi_quickcheck/tests/mul_2.cpp6
-rw-r--r--tools/nnapi_quickcheck/tests/mul_quan_1.cpp6
-rw-r--r--tools/nnapi_quickcheck/tests/relu1_1.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/relu6_1.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/relu6_quan_1.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/relu_1.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/relu_2.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/relu_3.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/relu_quan_1.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/reshape_1.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/reshape_quan_1.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/resize_bilinear_1.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/softmax_1.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/softmax_2.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/softmax_quan_1.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/split_1.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/split_2.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/split_3.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/split_4.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/sub_1.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/sub_2.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/sub_3.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/sub_4.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/sub_5.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/sub_6.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/tanh_1.cpp8
-rw-r--r--tools/nnapi_quickcheck/tests/topk_v2_1.cpp8
-rw-r--r--tools/nnapi_test/CMakeLists.txt5
-rw-r--r--tools/nnapi_test/src/nnapi_test.cc55
-rw-r--r--tools/opencl_tool/src/opencl_info.cc81
-rw-r--r--tools/tensorflow_model_freezer/base_freezer.py5
-rw-r--r--tools/tensorflow_model_freezer/readme.md18
-rwxr-xr-xtools/tensorflow_model_freezer/sample/ARGMAX_gen.py100
-rwxr-xr-xtools/tensorflow_model_freezer/sample/ARGMIN_gen.py100
-rwxr-xr-xtools/tensorflow_model_freezer/sample/DIV_gen.py7
-rwxr-xr-xtools/tensorflow_model_freezer/sample/LOGICAL_AND_gen.py105
-rwxr-xr-xtools/tensorflow_model_freezer/sample/LOGICAL_NOT_gen.py100
-rwxr-xr-xtools/tensorflow_model_freezer/sample/LOGICAL_OR_gen.py104
-rwxr-xr-xtools/tensorflow_model_freezer/sample/MUL_gen.py11
-rwxr-xr-xtools/tensorflow_model_freezer/sample/SQUEEZE_gen.py7
-rwxr-xr-xtools/tensorflow_model_freezer/sample/STACK_gen.py101
-rwxr-xr-xtools/tensorflow_model_freezer/sample/TOPK_gen.py14
-rw-r--r--tools/tensorflow_model_freezer/sample/UNSTACK_gen.py100
-rw-r--r--tools/test_driver/README.md63
-rw-r--r--tools/test_driver/benchmark_op_list.txt11
-rwxr-xr-xtools/test_driver/common.sh34
-rw-r--r--tools/test_driver/neurun_frameworktest_list.txt10
-rw-r--r--tools/test_driver/nnfw_kernel_env_list.txt7
-rwxr-xr-xtools/test_driver/print_to_json.sh169
-rwxr-xr-xtools/test_driver/py/common.py39
-rwxr-xr-xtools/test_driver/py/run_frameworktest.py199
-rwxr-xr-xtools/test_driver/py/run_unittest.py187
-rwxr-xr-xtools/test_driver/py/test_driver.py398
-rwxr-xr-xtools/test_driver/run_benchmark.sh146
-rwxr-xr-xtools/test_driver/run_benchmark_acl.sh113
-rwxr-xr-xtools/test_driver/run_benchmark_op.sh209
-rw-r--r--tools/test_driver/run_benchmark_tflite_model.in1
-rwxr-xr-xtools/test_driver/run_benchmark_tflite_model.sh125
-rwxr-xr-xtools/test_driver/run_frameworktest.sh95
-rwxr-xr-xtools/test_driver/run_unittest.sh109
-rwxr-xr-xtools/test_driver/test_driver.sh329
-rw-r--r--tools/tflite_benchmark/CMakeLists.txt5
-rw-r--r--tools/tflite_benchmark/src/tflite_benchmark.cc231
-rw-r--r--tools/tflite_benchmark_model/.FORMATDENY0
-rw-r--r--tools/tflite_benchmark_model/CMakeLists.txt6
-rw-r--r--tools/tflite_benchmark_model/README.md209
-rw-r--r--tools/tflite_benchmark_model/benchmark_main.cc53
-rw-r--r--tools/tflite_benchmark_model/benchmark_model.cc175
-rw-r--r--tools/tflite_benchmark_model/benchmark_model.h177
-rw-r--r--tools/tflite_benchmark_model/benchmark_params.cc73
-rw-r--r--tools/tflite_benchmark_model/benchmark_params.h118
-rw-r--r--tools/tflite_benchmark_model/benchmark_tflite_model.cc360
-rw-r--r--tools/tflite_benchmark_model/benchmark_tflite_model.h95
-rw-r--r--tools/tflite_benchmark_model/command_line_flags.cc214
-rw-r--r--tools/tflite_benchmark_model/command_line_flags.h141
-rw-r--r--tools/tflite_benchmark_model/logging.h92
-rw-r--r--tools/tflite_benchmark_model/profile_summarizer.cc164
-rw-r--r--tools/tflite_benchmark_model/profile_summarizer.h55
-rw-r--r--tools/tflite_examples/CMakeLists.txt2
-rw-r--r--tools/tflite_examples/src/conv.cpp330
-rw-r--r--tools/tflite_run/CMakeLists.txt26
-rw-r--r--tools/tflite_run/README.md91
-rw-r--r--tools/tflite_run/src/args.cc125
-rw-r--r--tools/tflite_run/src/args.h55
-rw-r--r--tools/tflite_run/src/bin_image.cc71
-rw-r--r--tools/tflite_run/src/bin_image.h43
-rw-r--r--tools/tflite_run/src/tensor_dumper.cc54
-rw-r--r--tools/tflite_run/src/tensor_dumper.h38
-rw-r--r--tools/tflite_run/src/tensor_loader.cc67
-rw-r--r--tools/tflite_run/src/tensor_loader.h35
-rw-r--r--tools/tflite_run/src/tflite_run.cc253
-rw-r--r--tools/tflite_run/src/tflite_test.cc19
-rwxr-xr-xtools/tflitefile_tool/model_parser.py69
-rw-r--r--tools/tflitefile_tool/model_printer.py142
-rwxr-xr-xtools/tflitefile_tool/operation.py14
-rwxr-xr-xtools/tflitefile_tool/operator_parser.py68
-rw-r--r--tools/tflitefile_tool/operator_printer.py72
-rwxr-xr-xtools/tflitefile_tool/operator_wrapping.py67
-rw-r--r--tools/tflitefile_tool/option_printer.py69
-rwxr-xr-xtools/tflitefile_tool/perf_predictor.py13
-rw-r--r--[-rwxr-xr-x]tools/tflitefile_tool/select_operator.py474
-rw-r--r--tools/tflitefile_tool/tensor_printer.py80
-rwxr-xr-xtools/tflitefile_tool/tensor_wrapping.py82
-rw-r--r--tools/tflitefile_tool/tflite/BidirectionalSequenceRNNOptions.py5
-rw-r--r--tools/tflitefile_tool/tflite/BuiltinOperator.py14
-rw-r--r--tools/tflitefile_tool/tflite/BuiltinOptions.py10
-rw-r--r--tools/tflitefile_tool/tflite/DepthwiseConv2DOptions.py24
-rw-r--r--tools/tflitefile_tool/tflite/FakeQuantOptions.py5
-rw-r--r--tools/tflitefile_tool/tflite/FillOptions.py28
-rw-r--r--tools/tflitefile_tool/tflite/FloorDivOptions.py28
-rw-r--r--tools/tflitefile_tool/tflite/LogicalAndOptions.py28
-rw-r--r--tools/tflitefile_tool/tflite/LogicalNotOptions.py28
-rw-r--r--tools/tflitefile_tool/tflite/LogicalOrOptions.py28
-rw-r--r--tools/tflitefile_tool/tflite/Model.py2
-rw-r--r--tools/tflitefile_tool/tflite/OneHotOptions.py39
-rw-r--r--tools/tflitefile_tool/tflite/OperatorCode.py2
-rw-r--r--tools/tflitefile_tool/tflite/PackOptions.py50
-rw-r--r--tools/tflitefile_tool/tflite/ReducerOptions.py5
-rw-r--r--tools/tflitefile_tool/tflite/ResizeBilinearOptions.py5
-rw-r--r--tools/tflitefile_tool/tflite/SequenceRNNOptions.py5
-rw-r--r--tools/tflitefile_tool/tflite/SkipGramOptions.py5
-rw-r--r--tools/tflitefile_tool/tflite/SparseToDenseOptions.py5
-rw-r--r--tools/tflitefile_tool/tflite/SquareOptions.py28
-rw-r--r--tools/tflitefile_tool/tflite/SubGraph.py2
-rw-r--r--tools/tflitefile_tool/tflite/Tensor.py7
-rw-r--r--tools/tflitefile_tool/tflite/UnpackOptions.py50
-rw-r--r--tools/tflitefile_tool/tflite/ZerosLikeOptions.py28
-rw-r--r--tools/tflkit/README.md366
-rw-r--r--tools/tflkit/convert.template6
-rw-r--r--tools/tflkit/freeze.template5
-rwxr-xr-xtools/tflkit/freeze_graph.sh98
-rw-r--r--tools/tflkit/optimize.template4
-rwxr-xr-xtools/tflkit/optimize_for_inference.sh90
-rw-r--r--tools/tflkit/summarize_pb.py111
-rwxr-xr-xtools/tflkit/summarize_pb.sh3
-rwxr-xr-xtools/tflkit/summarize_tflite.sh4
-rwxr-xr-xtools/tflkit/tflite_convert.sh136
-rw-r--r--tools/tflkit/transform.template5
-rwxr-xr-xtools/tflkit/transform_graph.sh94
178 files changed, 3318 insertions, 6435 deletions
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
index f57262f29..7181629f3 100644
--- a/tools/CMakeLists.txt
+++ b/tools/CMakeLists.txt
@@ -1,9 +1,6 @@
-add_subdirectory(tflite_run)
-add_subdirectory(tflite_benchmark)
-if (BUILD_TFLITE_BENCHMARK_MODEL)
- add_subdirectory(tflite_benchmark_model)
-endif()
-add_subdirectory(tflite_examples)
-add_subdirectory(nnapi_test)
+if(OBS_BUILD)
+ return()
+endif(OBS_BUILD)
+
add_subdirectory(nnapi_quickcheck)
add_subdirectory(opencl_tool)
diff --git a/tools/cross/arm/sources.list.bionic b/tools/cross/arm/sources.list.bionic
new file mode 100644
index 000000000..210955740
--- /dev/null
+++ b/tools/cross/arm/sources.list.bionic
@@ -0,0 +1,11 @@
+deb http://ports.ubuntu.com/ubuntu-ports/ bionic main restricted universe
+deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic main restricted universe
+
+deb http://ports.ubuntu.com/ubuntu-ports/ bionic-updates main restricted universe
+deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-updates main restricted universe
+
+deb http://ports.ubuntu.com/ubuntu-ports/ bionic-backports main restricted
+deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-backports main restricted
+
+deb http://ports.ubuntu.com/ubuntu-ports/ bionic-security main restricted universe multiverse
+deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-security main restricted universe multiverse
diff --git a/tools/cross/build_rootfs.sh b/tools/cross/build_rootfs.sh
index 11e5eff76..3d0837bb6 100755
--- a/tools/cross/build_rootfs.sh
+++ b/tools/cross/build_rootfs.sh
@@ -73,6 +73,9 @@ for i in "$@" ; do
xenial)
__LinuxCodeName=xenial
;;
+ bionic)
+ __LinuxCodeName=bionic
+ ;;
--setproxy*)
proxyip="${i#*=}"
__Apt="Acquire::http::proxy \"http://$proxyip/\";\n"
diff --git a/tools/modelgen/CONV_2D.template.json b/tools/modelgen/CONV_2D.template.json
deleted file mode 100644
index 34ce09f35..000000000
--- a/tools/modelgen/CONV_2D.template.json
+++ /dev/null
@@ -1,102 +0,0 @@
-{
- "version":3,
- "operator_codes": [
- {
- "builtin_code": "CONV_2D"
- }
- ],
- "subgraphs": [
- {
- "tensors": [
- {
- "shape": [
- 1,
- 3,
- 3,
- 3
- ],
- "buffer": 0,
- "name": "input",
- "quantization": {
- "min": [
- 0.0
- ],
- "max": [
- 255.0
- ]
- }
- },
- {
- "shape": [
- 1,
- 3,
- 3,
- 3
- ],
- "buffer": 1,
- "name": "weights",
- "quantization": {
- }
- },
- {
- "shape": [
- 1
- ],
- "buffer": 2,
- "name": "convolution_bias",
- "quantization": {
- }
- },
- {
- "shape": [
- 1,
- 3,
- 3,
- 1
- ],
- "buffer": 3,
- "name": "output",
- "quantization": {
- }
- }
- ],
- "inputs": [
- 0
- ],
- "outputs": [
- 3
- ],
- "operators": [
- {
- "opcode_index": 0,
- "inputs": [
- 0,
- 1,
- 2
- ],
- "outputs": [
- 3
- ],
- "builtin_options_type": "Conv2DOptions",
- "builtin_options": {
- "padding": "SAME",
- "stride_w": 1,
- "stride_h": 1,
- "fused_activation_function": "RELU"
- }
- }
- ]
- }
- ],
- "description": "TOCO Converted.",
- "buffers": [
- {},
- {
- "data": []
- },
- {
- "data": []
- },
- {}
- ]
-}
diff --git a/tools/modelgen/modelgen.py b/tools/modelgen/modelgen.py
deleted file mode 100755
index 112a1e8a1..000000000
--- a/tools/modelgen/modelgen.py
+++ /dev/null
@@ -1,98 +0,0 @@
-#!/usr/bin/python
-
-# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-import json
-import numpy as np
-import os
-import struct
-
-dir_path = os.path.dirname(os.path.realpath(__file__))
-
-builtin_ops = [
- "CONV_2D",
-]
-
-# N,H,W,C
-input_shape = [1, 6, 6, 3]
-kernel_shape = [1, 3, 3, 3]
-
-# load template file.
-with open(dir_path + "/CONV_2D.template.json", 'r') as f:
- graph = json.loads(f.read())
- f.close()
-
-tensors = graph['subgraphs'][0]['tensors']
-buffers = graph['buffers']
-
-buffer_map = {}
-
-# shape setup
-for t in tensors:
- if t['name'] == 'input':
- t['shape'] = input_shape
- elif t['name'] == 'weights':
- t['shape'] = kernel_shape
- elif t['name'] == 'convolution_bias':
- # bias size = N of weight
- t['shape'] = [kernel_shape[0]]
- elif t['name'] == 'output':
- # just for now, the same padding algorithm.
- # stride = 1
- t['shape'][0] = 1 # N
- t['shape'][1] = input_shape[1] # H
- t['shape'][2] = input_shape[2] # W
- t['shape'][3] = kernel_shape[0] # C
-
- buffer_map[t['buffer']] = {'name': t['name'], 'shape': t['shape']}
-
-# buffer setup
-for i in range(len(buffers)):
- if buffer_map[i]['name'] == 'weights':
- shape = buffer_map[i]['shape']
-
- weight = np.ones(shape)
- n = shape[0]
- h = shape[1]
- w = shape[2]
- c = shape[3]
- for nn in range(n):
- for hh in range(h):
- for ww in range(w):
- for cc in range(c):
- if cc == 0:
- weight[nn][hh][ww][cc] = 1.0
- else:
- weight[nn][hh][ww][cc] = 0.0
-
- weight_list = weight.flatten()
- weight_bytes = struct.pack('%sf' % (len(weight_list)), *weight_list)
- weight_uints = struct.unpack('%sB' % (len(weight_list) * 4), weight_bytes)
-
- buffers[i]['data'] = list(weight_uints)
-
- elif buffer_map[i]['name'] == 'convolution_bias':
- # weight of N
- shape = buffer_map[i]['shape']
-
- bias = np.zeros(shape)
- bias_list = bias.flatten()
- bias_bytes = struct.pack('%sf' % (len(bias_list)), *bias_list)
- bias_uints = struct.unpack('%sB' % (len(bias_list) * 4), bias_bytes)
-
- buffers[i]['data'] = list(bias_uints)
-
-with open('model.json', 'w') as f:
- f.write(json.dumps(graph, indent=2))
diff --git a/tools/modelgen/modelgen.sh b/tools/modelgen/modelgen.sh
deleted file mode 100755
index 563240da9..000000000
--- a/tools/modelgen/modelgen.sh
+++ /dev/null
@@ -1,31 +0,0 @@
-#!/bin/bash
-
-# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-SCRIPT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
-ROOT_PATH=$SCRIPT_PATH/../..
-FLATC=$ROOT_PATH/Product/out/bin/flatc
-
-if [ ! -e "$1" ]; then
- echo "file not exists: $1"
- exit 1
-fi
-
-JSON_FILE=$1
-JSON_FILENAME=${TFLITE_FILE##*\/}
-TFLITE_FILENAME=${TFLITE_FILENAME%\.json}.tflite
-
-$FLATC -b $ROOT_PATH/externals/tensorflow/tensorflow/contrib/lite/schema/schema.fbs $JSON_FILE
-
diff --git a/tools/nnapi_quickcheck/CMakeLists.txt b/tools/nnapi_quickcheck/CMakeLists.txt
index 9dd7f5b3b..c88155aa1 100644
--- a/tools/nnapi_quickcheck/CMakeLists.txt
+++ b/tools/nnapi_quickcheck/CMakeLists.txt
@@ -8,8 +8,8 @@ list(REMOVE_ITEM NNAPI_QUICKCHECK_LIB_SOURCES ${NNAPI_QUICKCHECK_LIB_TESTS})
add_library(nnapi_quickcheck_common ${NNAPI_QUICKCHECK_LIB_SOURCES})
target_include_directories(nnapi_quickcheck_common PUBLIC "inc")
-target_link_libraries(nnapi_quickcheck_common nnfw_util)
-target_link_libraries(nnapi_quickcheck_common nnfw_support_tflite)
+target_link_libraries(nnapi_quickcheck_common nnfw_lib_misc)
+target_link_libraries(nnapi_quickcheck_common nnfw_lib_tflite)
add_executable(nnapi_quickcheck_lib_env_test "lib/env.test.cpp")
target_link_libraries(nnapi_quickcheck_lib_env_test nnapi_quickcheck_common)
diff --git a/tools/nnapi_quickcheck/tests/add_1.cpp b/tools/nnapi_quickcheck/tests/add_1.cpp
index 52aa2afa0..098b8591b 100644
--- a/tools/nnapi_quickcheck/tests/add_1.cpp
+++ b/tools/nnapi_quickcheck/tests/add_1.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/add_2.cpp b/tools/nnapi_quickcheck/tests/add_2.cpp
index 9b5b19c06..12851f1b0 100644
--- a/tools/nnapi_quickcheck/tests/add_2.cpp
+++ b/tools/nnapi_quickcheck/tests/add_2.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/add_3.cpp b/tools/nnapi_quickcheck/tests/add_3.cpp
index e692fe314..a7b2f436e 100644
--- a/tools/nnapi_quickcheck/tests/add_3.cpp
+++ b/tools/nnapi_quickcheck/tests/add_3.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -25,9 +25,9 @@
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/TensorShapeUtils.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/TensorShapeUtils.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/add_4.cpp b/tools/nnapi_quickcheck/tests/add_4.cpp
index e519f1731..217438fb1 100644
--- a/tools/nnapi_quickcheck/tests/add_4.cpp
+++ b/tools/nnapi_quickcheck/tests/add_4.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/add_5.cpp b/tools/nnapi_quickcheck/tests/add_5.cpp
index cacb5e42d..2f02c8292 100644
--- a/tools/nnapi_quickcheck/tests/add_5.cpp
+++ b/tools/nnapi_quickcheck/tests/add_5.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/add_6.cpp b/tools/nnapi_quickcheck/tests/add_6.cpp
index 245b7ad39..3af2c4af3 100644
--- a/tools/nnapi_quickcheck/tests/add_6.cpp
+++ b/tools/nnapi_quickcheck/tests/add_6.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/add_7.cpp b/tools/nnapi_quickcheck/tests/add_7.cpp
index 43d285c72..1ebf18e32 100644
--- a/tools/nnapi_quickcheck/tests/add_7.cpp
+++ b/tools/nnapi_quickcheck/tests/add_7.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/add_8.cpp b/tools/nnapi_quickcheck/tests/add_8.cpp
index ec11c3969..d4a5e4838 100644
--- a/tools/nnapi_quickcheck/tests/add_8.cpp
+++ b/tools/nnapi_quickcheck/tests/add_8.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/add_9.cpp b/tools/nnapi_quickcheck/tests/add_9.cpp
index f3cf02875..6c0cc2240 100644
--- a/tools/nnapi_quickcheck/tests/add_9.cpp
+++ b/tools/nnapi_quickcheck/tests/add_9.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/add_quan_1.cpp b/tools/nnapi_quickcheck/tests/add_quan_1.cpp
index 45f0ba681..daf15e091 100644
--- a/tools/nnapi_quickcheck/tests/add_quan_1.cpp
+++ b/tools/nnapi_quickcheck/tests/add_quan_1.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/avg_pool_1.cpp b/tools/nnapi_quickcheck/tests/avg_pool_1.cpp
index c938ed690..e68cfc5b3 100644
--- a/tools/nnapi_quickcheck/tests/avg_pool_1.cpp
+++ b/tools/nnapi_quickcheck/tests/avg_pool_1.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <chrono>
#include <iostream>
diff --git a/tools/nnapi_quickcheck/tests/avg_pool_quan_1.cpp b/tools/nnapi_quickcheck/tests/avg_pool_quan_1.cpp
index ba41c030c..b24733ab0 100644
--- a/tools/nnapi_quickcheck/tests/avg_pool_quan_1.cpp
+++ b/tools/nnapi_quickcheck/tests/avg_pool_quan_1.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <chrono>
#include <iostream>
diff --git a/tools/nnapi_quickcheck/tests/cast_1.cpp b/tools/nnapi_quickcheck/tests/cast_1.cpp
index 01d49cd59..bf493d091 100644
--- a/tools/nnapi_quickcheck/tests/cast_1.cpp
+++ b/tools/nnapi_quickcheck/tests/cast_1.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,8 +24,8 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/cast_2.cpp b/tools/nnapi_quickcheck/tests/cast_2.cpp
index b0032210d..d85781d0c 100644
--- a/tools/nnapi_quickcheck/tests/cast_2.cpp
+++ b/tools/nnapi_quickcheck/tests/cast_2.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/cast_q_to_f_1.cpp b/tools/nnapi_quickcheck/tests/cast_q_to_f_1.cpp
index 763ca940c..ede763701 100644
--- a/tools/nnapi_quickcheck/tests/cast_q_to_f_1.cpp
+++ b/tools/nnapi_quickcheck/tests/cast_q_to_f_1.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,8 +24,8 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/concat_1.cpp b/tools/nnapi_quickcheck/tests/concat_1.cpp
index 77d670fed..cc14d083a 100644
--- a/tools/nnapi_quickcheck/tests/concat_1.cpp
+++ b/tools/nnapi_quickcheck/tests/concat_1.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/concat_quan_1.cpp b/tools/nnapi_quickcheck/tests/concat_quan_1.cpp
index cd522b049..f804b819b 100644
--- a/tools/nnapi_quickcheck/tests/concat_quan_1.cpp
+++ b/tools/nnapi_quickcheck/tests/concat_quan_1.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/conv_1.cpp b/tools/nnapi_quickcheck/tests/conv_1.cpp
index 10046d1ce..57b6abdfd 100644
--- a/tools/nnapi_quickcheck/tests/conv_1.cpp
+++ b/tools/nnapi_quickcheck/tests/conv_1.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/conv_quan_1.cpp b/tools/nnapi_quickcheck/tests/conv_quan_1.cpp
index aebf2333a..025cccadd 100644
--- a/tools/nnapi_quickcheck/tests/conv_quan_1.cpp
+++ b/tools/nnapi_quickcheck/tests/conv_quan_1.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/dconv_1.cpp b/tools/nnapi_quickcheck/tests/dconv_1.cpp
index bd0cacfd0..21d648331 100644
--- a/tools/nnapi_quickcheck/tests/dconv_1.cpp
+++ b/tools/nnapi_quickcheck/tests/dconv_1.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/dconv_quan_1.cpp b/tools/nnapi_quickcheck/tests/dconv_quan_1.cpp
index 43f305f06..7cb9383e4 100644
--- a/tools/nnapi_quickcheck/tests/dconv_quan_1.cpp
+++ b/tools/nnapi_quickcheck/tests/dconv_quan_1.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/dequantize_1.cpp b/tools/nnapi_quickcheck/tests/dequantize_1.cpp
index fe310a11d..467392dc3 100644
--- a/tools/nnapi_quickcheck/tests/dequantize_1.cpp
+++ b/tools/nnapi_quickcheck/tests/dequantize_1.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,8 +24,8 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/div_1.cpp b/tools/nnapi_quickcheck/tests/div_1.cpp
index ffa0d6cac..1fe0f7a28 100644
--- a/tools/nnapi_quickcheck/tests/div_1.cpp
+++ b/tools/nnapi_quickcheck/tests/div_1.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/div_2.cpp b/tools/nnapi_quickcheck/tests/div_2.cpp
index c836c259a..883167e95 100644
--- a/tools/nnapi_quickcheck/tests/div_2.cpp
+++ b/tools/nnapi_quickcheck/tests/div_2.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/fully_connected_1.cpp b/tools/nnapi_quickcheck/tests/fully_connected_1.cpp
index 57af253f5..ea5df23d2 100644
--- a/tools/nnapi_quickcheck/tests/fully_connected_1.cpp
+++ b/tools/nnapi_quickcheck/tests/fully_connected_1.cpp
@@ -16,16 +16,16 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
#include "env.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/fully_connected_quan_1.cpp b/tools/nnapi_quickcheck/tests/fully_connected_quan_1.cpp
index 1cb75fea0..c434d75f8 100644
--- a/tools/nnapi_quickcheck/tests/fully_connected_quan_1.cpp
+++ b/tools/nnapi_quickcheck/tests/fully_connected_quan_1.cpp
@@ -16,16 +16,16 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
#include "env.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/gather_1.cpp b/tools/nnapi_quickcheck/tests/gather_1.cpp
index 0d5b30eb6..b916676c7 100644
--- a/tools/nnapi_quickcheck/tests/gather_1.cpp
+++ b/tools/nnapi_quickcheck/tests/gather_1.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,8 +24,8 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <chrono>
#include <iostream>
diff --git a/tools/nnapi_quickcheck/tests/gather_2.cpp b/tools/nnapi_quickcheck/tests/gather_2.cpp
index b3cb3c6ef..4b115685d 100644
--- a/tools/nnapi_quickcheck/tests/gather_2.cpp
+++ b/tools/nnapi_quickcheck/tests/gather_2.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,8 +24,8 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <chrono>
#include <iostream>
diff --git a/tools/nnapi_quickcheck/tests/logistic_quan_1.cpp b/tools/nnapi_quickcheck/tests/logistic_quan_1.cpp
index dc6902d66..e9e3bc1f7 100644
--- a/tools/nnapi_quickcheck/tests/logistic_quan_1.cpp
+++ b/tools/nnapi_quickcheck/tests/logistic_quan_1.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/max_pool_1.cpp b/tools/nnapi_quickcheck/tests/max_pool_1.cpp
index bb538141d..07fa9ac5b 100644
--- a/tools/nnapi_quickcheck/tests/max_pool_1.cpp
+++ b/tools/nnapi_quickcheck/tests/max_pool_1.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <chrono>
#include <iostream>
diff --git a/tools/nnapi_quickcheck/tests/max_pool_quan_1.cpp b/tools/nnapi_quickcheck/tests/max_pool_quan_1.cpp
index 5768ddde8..d241c43ba 100644
--- a/tools/nnapi_quickcheck/tests/max_pool_quan_1.cpp
+++ b/tools/nnapi_quickcheck/tests/max_pool_quan_1.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <chrono>
#include <iostream>
diff --git a/tools/nnapi_quickcheck/tests/mul_1.cpp b/tools/nnapi_quickcheck/tests/mul_1.cpp
index 3a4ae5c8e..cf7282bc7 100644
--- a/tools/nnapi_quickcheck/tests/mul_1.cpp
+++ b/tools/nnapi_quickcheck/tests/mul_1.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,8 +24,8 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/mul_2.cpp b/tools/nnapi_quickcheck/tests/mul_2.cpp
index b117cd602..734be8e3f 100644
--- a/tools/nnapi_quickcheck/tests/mul_2.cpp
+++ b/tools/nnapi_quickcheck/tests/mul_2.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,8 +24,8 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/mul_quan_1.cpp b/tools/nnapi_quickcheck/tests/mul_quan_1.cpp
index 7207a90fb..72903fe42 100644
--- a/tools/nnapi_quickcheck/tests/mul_quan_1.cpp
+++ b/tools/nnapi_quickcheck/tests/mul_quan_1.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,8 +24,8 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/relu1_1.cpp b/tools/nnapi_quickcheck/tests/relu1_1.cpp
index aeefe2f06..b729c50c3 100644
--- a/tools/nnapi_quickcheck/tests/relu1_1.cpp
+++ b/tools/nnapi_quickcheck/tests/relu1_1.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -23,9 +23,9 @@
#include "util/environment.h"
#include "util/feature/Shape.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <chrono>
#include <random>
diff --git a/tools/nnapi_quickcheck/tests/relu6_1.cpp b/tools/nnapi_quickcheck/tests/relu6_1.cpp
index 76bbe954c..cafbe8377 100644
--- a/tools/nnapi_quickcheck/tests/relu6_1.cpp
+++ b/tools/nnapi_quickcheck/tests/relu6_1.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -25,9 +25,9 @@
#include "util/environment.h"
#include "util/feature/Shape.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <chrono>
#include <random>
diff --git a/tools/nnapi_quickcheck/tests/relu6_quan_1.cpp b/tools/nnapi_quickcheck/tests/relu6_quan_1.cpp
index fe849f955..3d8ce4f7c 100644
--- a/tools/nnapi_quickcheck/tests/relu6_quan_1.cpp
+++ b/tools/nnapi_quickcheck/tests/relu6_quan_1.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -23,9 +23,9 @@
#include "util/environment.h"
#include "util/feature/Shape.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <chrono>
#include <random>
diff --git a/tools/nnapi_quickcheck/tests/relu_1.cpp b/tools/nnapi_quickcheck/tests/relu_1.cpp
index f754c3d8e..c7141ca6a 100644
--- a/tools/nnapi_quickcheck/tests/relu_1.cpp
+++ b/tools/nnapi_quickcheck/tests/relu_1.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -25,9 +25,9 @@
#include "util/environment.h"
#include "util/feature/Shape.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <chrono>
#include <random>
diff --git a/tools/nnapi_quickcheck/tests/relu_2.cpp b/tools/nnapi_quickcheck/tests/relu_2.cpp
index c08764520..74ab113c2 100644
--- a/tools/nnapi_quickcheck/tests/relu_2.cpp
+++ b/tools/nnapi_quickcheck/tests/relu_2.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -25,9 +25,9 @@
#include "util/environment.h"
#include "util/feature/Shape.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <chrono>
#include <random>
diff --git a/tools/nnapi_quickcheck/tests/relu_3.cpp b/tools/nnapi_quickcheck/tests/relu_3.cpp
index 6c41bc12a..f876e18ee 100644
--- a/tools/nnapi_quickcheck/tests/relu_3.cpp
+++ b/tools/nnapi_quickcheck/tests/relu_3.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -25,9 +25,9 @@
#include "util/environment.h"
#include "util/feature/Shape.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <chrono>
#include <random>
diff --git a/tools/nnapi_quickcheck/tests/relu_quan_1.cpp b/tools/nnapi_quickcheck/tests/relu_quan_1.cpp
index 59fe5d254..7bc6181ad 100644
--- a/tools/nnapi_quickcheck/tests/relu_quan_1.cpp
+++ b/tools/nnapi_quickcheck/tests/relu_quan_1.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -23,9 +23,9 @@
#include "util/environment.h"
#include "util/feature/Shape.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <chrono>
#include <random>
diff --git a/tools/nnapi_quickcheck/tests/reshape_1.cpp b/tools/nnapi_quickcheck/tests/reshape_1.cpp
index 21d35a5ca..a35623ced 100644
--- a/tools/nnapi_quickcheck/tests/reshape_1.cpp
+++ b/tools/nnapi_quickcheck/tests/reshape_1.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <chrono>
#include <iostream>
diff --git a/tools/nnapi_quickcheck/tests/reshape_quan_1.cpp b/tools/nnapi_quickcheck/tests/reshape_quan_1.cpp
index 7f852fd80..fb1db77e7 100644
--- a/tools/nnapi_quickcheck/tests/reshape_quan_1.cpp
+++ b/tools/nnapi_quickcheck/tests/reshape_quan_1.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <chrono>
#include <iostream>
diff --git a/tools/nnapi_quickcheck/tests/resize_bilinear_1.cpp b/tools/nnapi_quickcheck/tests/resize_bilinear_1.cpp
index 37d8ab525..3c7ce28b1 100644
--- a/tools/nnapi_quickcheck/tests/resize_bilinear_1.cpp
+++ b/tools/nnapi_quickcheck/tests/resize_bilinear_1.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <chrono>
#include <iostream>
diff --git a/tools/nnapi_quickcheck/tests/softmax_1.cpp b/tools/nnapi_quickcheck/tests/softmax_1.cpp
index 5e15b6169..b9cc6bf0f 100644
--- a/tools/nnapi_quickcheck/tests/softmax_1.cpp
+++ b/tools/nnapi_quickcheck/tests/softmax_1.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -25,9 +25,9 @@
#include "util/environment.h"
#include "util/feature/Shape.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <chrono>
#include <random>
diff --git a/tools/nnapi_quickcheck/tests/softmax_2.cpp b/tools/nnapi_quickcheck/tests/softmax_2.cpp
index 489016af5..402435718 100644
--- a/tools/nnapi_quickcheck/tests/softmax_2.cpp
+++ b/tools/nnapi_quickcheck/tests/softmax_2.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -25,9 +25,9 @@
#include "util/environment.h"
#include "util/feature/Shape.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <chrono>
#include <random>
diff --git a/tools/nnapi_quickcheck/tests/softmax_quan_1.cpp b/tools/nnapi_quickcheck/tests/softmax_quan_1.cpp
index 347262fa6..2c12e1104 100644
--- a/tools/nnapi_quickcheck/tests/softmax_quan_1.cpp
+++ b/tools/nnapi_quickcheck/tests/softmax_quan_1.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -25,9 +25,9 @@
#include "util/environment.h"
#include "util/feature/Shape.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <chrono>
#include <random>
diff --git a/tools/nnapi_quickcheck/tests/split_1.cpp b/tools/nnapi_quickcheck/tests/split_1.cpp
index 742c5dbed..735a0777f 100644
--- a/tools/nnapi_quickcheck/tests/split_1.cpp
+++ b/tools/nnapi_quickcheck/tests/split_1.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -25,9 +25,9 @@
#include "util/environment.h"
#include "util/feature/Shape.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <chrono>
#include <random>
diff --git a/tools/nnapi_quickcheck/tests/split_2.cpp b/tools/nnapi_quickcheck/tests/split_2.cpp
index d70e35ca7..0d4bf3e13 100644
--- a/tools/nnapi_quickcheck/tests/split_2.cpp
+++ b/tools/nnapi_quickcheck/tests/split_2.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -25,9 +25,9 @@
#include "util/environment.h"
#include "util/feature/Shape.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <chrono>
#include <random>
diff --git a/tools/nnapi_quickcheck/tests/split_3.cpp b/tools/nnapi_quickcheck/tests/split_3.cpp
index 47359642d..eaa65bdc2 100644
--- a/tools/nnapi_quickcheck/tests/split_3.cpp
+++ b/tools/nnapi_quickcheck/tests/split_3.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -25,9 +25,9 @@
#include "util/environment.h"
#include "util/feature/Shape.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <chrono>
#include <random>
diff --git a/tools/nnapi_quickcheck/tests/split_4.cpp b/tools/nnapi_quickcheck/tests/split_4.cpp
index d16e75d5c..394c392b6 100644
--- a/tools/nnapi_quickcheck/tests/split_4.cpp
+++ b/tools/nnapi_quickcheck/tests/split_4.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -25,9 +25,9 @@
#include "util/environment.h"
#include "util/feature/Shape.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <chrono>
#include <random>
diff --git a/tools/nnapi_quickcheck/tests/sub_1.cpp b/tools/nnapi_quickcheck/tests/sub_1.cpp
index 2734f525e..9e4ff4ce7 100644
--- a/tools/nnapi_quickcheck/tests/sub_1.cpp
+++ b/tools/nnapi_quickcheck/tests/sub_1.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/sub_2.cpp b/tools/nnapi_quickcheck/tests/sub_2.cpp
index 88e060847..2702edbf1 100644
--- a/tools/nnapi_quickcheck/tests/sub_2.cpp
+++ b/tools/nnapi_quickcheck/tests/sub_2.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/sub_3.cpp b/tools/nnapi_quickcheck/tests/sub_3.cpp
index fd2d4aaea..6122e2486 100644
--- a/tools/nnapi_quickcheck/tests/sub_3.cpp
+++ b/tools/nnapi_quickcheck/tests/sub_3.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/sub_4.cpp b/tools/nnapi_quickcheck/tests/sub_4.cpp
index 993acddce..28922fe4b 100644
--- a/tools/nnapi_quickcheck/tests/sub_4.cpp
+++ b/tools/nnapi_quickcheck/tests/sub_4.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/sub_5.cpp b/tools/nnapi_quickcheck/tests/sub_5.cpp
index 610be5754..e421a12c2 100644
--- a/tools/nnapi_quickcheck/tests/sub_5.cpp
+++ b/tools/nnapi_quickcheck/tests/sub_5.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/sub_6.cpp b/tools/nnapi_quickcheck/tests/sub_6.cpp
index b9e37c8d7..00bfc5423 100644
--- a/tools/nnapi_quickcheck/tests/sub_6.cpp
+++ b/tools/nnapi_quickcheck/tests/sub_6.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/tanh_1.cpp b/tools/nnapi_quickcheck/tests/tanh_1.cpp
index 67847eceb..6a9a29933 100644
--- a/tools/nnapi_quickcheck/tests/tanh_1.cpp
+++ b/tools/nnapi_quickcheck/tests/tanh_1.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <iostream>
#include <cassert>
diff --git a/tools/nnapi_quickcheck/tests/topk_v2_1.cpp b/tools/nnapi_quickcheck/tests/topk_v2_1.cpp
index bb9d8535e..4b145e5a7 100644
--- a/tools/nnapi_quickcheck/tests/topk_v2_1.cpp
+++ b/tools/nnapi_quickcheck/tests/topk_v2_1.cpp
@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
-#include "support/tflite/kernels/register.h"
+#include "tflite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/builtin_op_data.h"
@@ -24,9 +24,9 @@
#include "memory.h"
#include "util/environment.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Quantization.h"
-#include "support/tflite/interp/FunctionBuilder.h"
+#include "tflite/Diff.h"
+#include "tflite/Quantization.h"
+#include "tflite/interp/FunctionBuilder.h"
#include <chrono>
#include <iostream>
diff --git a/tools/nnapi_test/CMakeLists.txt b/tools/nnapi_test/CMakeLists.txt
deleted file mode 100644
index cd9f2a524..000000000
--- a/tools/nnapi_test/CMakeLists.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-list(APPEND SOURCES "src/nnapi_test.cc")
-
-add_executable(nnapi_test ${SOURCES})
-target_link_libraries(nnapi_test nnfw_support_tflite)
-install(TARGETS nnapi_test DESTINATION bin)
diff --git a/tools/nnapi_test/src/nnapi_test.cc b/tools/nnapi_test/src/nnapi_test.cc
deleted file mode 100644
index 1f98bb07d..000000000
--- a/tools/nnapi_test/src/nnapi_test.cc
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "support/tflite/kernels/register.h"
-#include "tensorflow/contrib/lite/model.h"
-
-#include "support/tflite/interp/FlatBufferBuilder.h"
-#include "support/tflite/Diff.h"
-
-#include <iostream>
-#include <stdexcept>
-
-using namespace tflite;
-using namespace tflite::ops::builtin;
-
-int main(const int argc, char **argv)
-{
- if (argc < 2)
- {
- std::cerr << "nnapi_test\n\n";
- std::cerr << "Usage: " << argv[0] << " <.tflite>\n\n";
- return 1;
- }
-
- const auto filename = argv[1];
-
- StderrReporter error_reporter;
-
- auto model = FlatBufferModel::BuildFromFile(filename, &error_reporter);
-
- const nnfw::support::tflite::interp::FlatBufferBuilder builder(*model);
-
- try
- {
- return RandomTestRunner::make(0).run(builder);
- }
- catch (const std::exception &e)
- {
- std::cerr << e.what() << std::endl;
- return 1;
- }
-}
diff --git a/tools/opencl_tool/src/opencl_info.cc b/tools/opencl_tool/src/opencl_info.cc
index 49673d1de..f8b635d43 100644
--- a/tools/opencl_tool/src/opencl_info.cc
+++ b/tools/opencl_tool/src/opencl_info.cc
@@ -42,11 +42,9 @@
#include <iostream>
#include <vector>
-void printDeviceInfo(int n, cl::Device &device, cl::Device &default_device)
+void printDeviceInfo(int n, cl::Device &device)
{
- bool is_default = (device() == default_device());
- std::cout << "\t\t\t#" << n << " Device: (id: " << device() << ") "
- << (is_default ? " -> default" : "") << "\n";
+ std::cout << "\t\t\t#" << n << " Device: (id: " << device() << ")\n";
const auto name = device.getInfo<CL_DEVICE_NAME>();
std::cout << "\t\t\t\tName: " << name << "\n";
@@ -67,7 +65,7 @@ void printDeviceInfo(int n, cl::Device &device, cl::Device &default_device)
std::cout << "\t\t\t\tMax Clock Frequency: " << max_clock_frequency << "\n";
}
-void printContext(int n, cl::Platform &plat, int device_type, cl::Context &default_context)
+void printContext(int n, cl::Platform &plat, int device_type)
{
if (device_type == CL_DEVICE_TYPE_DEFAULT)
std::cout << "\t #" << n << " context when CL_DEVICE_TYPE_DEFAULT";
@@ -98,9 +96,7 @@ void printContext(int n, cl::Platform &plat, int device_type, cl::Context &defau
return;
}
- bool is_default = (context() == default_context());
-
- std::cout << " (id: " << context() << ") " << (is_default ? " -> default" : "") << "\n";
+ std::cout << " (id: " << context() << ")\n";
const auto device_num = context.getInfo<CL_CONTEXT_NUM_DEVICES>();
std::cout << "\t\t\tDevice num: " << device_num << "\n";
@@ -108,46 +104,63 @@ void printContext(int n, cl::Platform &plat, int device_type, cl::Context &defau
return;
auto devices = context.getInfo<CL_CONTEXT_DEVICES>();
- auto default_device = cl::Device::getDefault();
int d = 0;
for (auto device : devices)
- printDeviceInfo(++d, device, default_device);
+ printDeviceInfo(++d, device);
}
-void printPlatform(int n, cl::Platform &plat, cl::Platform &default_platform)
+void printPlatform(int n, cl::Platform &plat)
{
- bool is_default = (plat() == default_platform());
-
- std::cout << "#" << n << ". Platform: (id: " << plat() << ") "
- << (is_default ? " -> default" : "") << "\n";
+ std::cout << "#" << n << ". Platform: (id: " << plat() << ")\n";
- cl::Context default_context = cl::Context::getDefault();
- std::cout << "\t"
- << "default context: " << default_context() << "\n";
+ cl::Context default_context;
int x = 0;
- printContext(++x, plat, CL_DEVICE_TYPE_DEFAULT, default_context);
- printContext(++x, plat, CL_DEVICE_TYPE_GPU, default_context);
- printContext(++x, plat, CL_DEVICE_TYPE_CPU, default_context);
- printContext(++x, plat, CL_DEVICE_TYPE_ACCELERATOR, default_context);
- printContext(++x, plat, CL_DEVICE_TYPE_CUSTOM, default_context);
- printContext(++x, plat, CL_DEVICE_TYPE_ALL, default_context);
+ printContext(++x, plat, CL_DEVICE_TYPE_DEFAULT);
+ printContext(++x, plat, CL_DEVICE_TYPE_GPU);
+ printContext(++x, plat, CL_DEVICE_TYPE_CPU);
+ printContext(++x, plat, CL_DEVICE_TYPE_ACCELERATOR);
+ printContext(++x, plat, CL_DEVICE_TYPE_CUSTOM);
+ printContext(++x, plat, CL_DEVICE_TYPE_ALL);
}
int main(const int argc, char **argv)
{
- std::cout << "\nOpenCL Platform, Context, Device Info are as follows:\n\n";
-
- std::vector<cl::Platform> platforms;
- cl::Platform::get(&platforms);
-
- cl::Platform defaultPlatform = cl::Platform::getDefault();
-
- int n = 0;
- for (auto &p : platforms)
+ try
+ {
+ std::cout << "\nOpenCL Platform, Context, Device Info are as follows:\n\n";
+ {
+ std::vector<cl::Platform> platforms;
+ cl::Platform::get(&platforms);
+
+ int n = 0;
+ for (auto &p : platforms)
+ {
+ printPlatform(++n, p);
+ }
+ }
+
+ std::cout << "\n\nShowing default platfom, context, and device:\n"
+ << "(Note: this may throw an error depending on system or compiler)\n";
+ {
+ auto platform = cl::Platform::getDefault();
+ std::cout << "* default platform (id: " << platform() << ")\n";
+ auto context = cl::Context::getDefault();
+ std::cout << "* default context (id: " << context() << ")\n";
+ auto device = cl::Device::getDefault();
+ printDeviceInfo(0, device);
+ }
+ }
+ catch (cl::Error &err)
+ {
+ std::cerr << "cl::Error was thrown: Please refer to the info below:\n"
+ << "\terror code: " << err.err() << ", meaning: " << err.what() << std::endl;
+ }
+ catch (std::system_error &err)
{
- printPlatform(++n, p, defaultPlatform);
+ std::cerr << "std::system_error was thrown: Please refer to the info below:\n"
+ << "\terror code: " << err.code() << ", meaning: " << err.what() << std::endl;
}
return 0;
diff --git a/tools/tensorflow_model_freezer/base_freezer.py b/tools/tensorflow_model_freezer/base_freezer.py
index ccfd811cf..96d011718 100644
--- a/tools/tensorflow_model_freezer/base_freezer.py
+++ b/tools/tensorflow_model_freezer/base_freezer.py
@@ -129,8 +129,9 @@ class BaseFreezer(object):
util.importGraphIntoSession(sess, frozen_pb_path, "")
try:
- tflite_model = tf.contrib.lite.toco_convert(sess.graph_def, input_node_list,
- output_node_list)
+ converter = tf.contrib.lite.TFLiteConverter.from_session(
+ sess, input_node_list, output_node_list)
+ tflite_model = converter.convert()
open(tflite_path, "wb").write(tflite_model)
print("# 3. TOCO : Created TFLITE file :\n\t-{}\n".format(tflite_path))
except Exception:
diff --git a/tools/tensorflow_model_freezer/readme.md b/tools/tensorflow_model_freezer/readme.md
index f627f11a5..0aabf1085 100644
--- a/tools/tensorflow_model_freezer/readme.md
+++ b/tools/tensorflow_model_freezer/readme.md
@@ -1,3 +1,13 @@
+## Prerequisites
+
+The scripts here use TensorFlow's tools, so you need an environment to run TensorFlow. Running the scripts within this tutorial requires:
+
+* Install [TensorFlow](https://www.tensorflow.org/install/) v1.12 or later
+ * Use pip
+ ```
+ $ pip install tensorflow==1.12
+ ```
+
## What this tool is about
This tool generaes the following files:
@@ -16,5 +26,13 @@ By define `Test Cases`, you can easily and quickly generate files for various ra
- Run `~/nnfw$ PYTHONPATH=$PYTHONPATH:./tools/tensorflow_model_freezer/ python tools/tensorflow_model_freezer/sample/MUL_gen.py ~/temp`
- Files will be generated under `~/temp`
+## How to run
+```
+$ chmod +x tools/tensorflow_model_freezer/sample/name_of_this_file.py
+$ PYTHONPATH=$PYTHONPATH:./tools/tensorflow_model_freezer/ \
+ tools/tensorflow_model_freezer/sample/name_of_this_file.py \
+ ~/temp # directory where model files are saved
+```
+
## Note
- This tool is tested with Python 2.7 and 3
diff --git a/tools/tensorflow_model_freezer/sample/ARGMAX_gen.py b/tools/tensorflow_model_freezer/sample/ARGMAX_gen.py
new file mode 100755
index 000000000..68e2262c0
--- /dev/null
+++ b/tools/tensorflow_model_freezer/sample/ARGMAX_gen.py
@@ -0,0 +1,100 @@
+#!/usr/bin/python
+
+# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+import sys
+import platform
+import tensorflow as tf
+import argparse
+
+import base_freezer as base
+import model_freezer_util as util
+
+
+class Gen(base.BaseFreezer):
+ '''
+ class to generate tflite files for MUL
+ '''
+
+ def __init__(self, path):
+ super(self.__class__, self).__init__(path)
+
+ def getOutputDirectory(self):
+ return os.path.join(self.root_output_path,
+ 'argmax') # the root path of generated files
+
+ def getTestCases(self):
+ '''
+ this returns a a hash containg test cases.
+ key of return hash is test case name and
+ value of return hash is test is a list of input tensor metadata.
+ test name (key of hash) is used as
+ - prefix of file name to be generated (don't use white space or special characters)
+ - output node name pf graph
+ '''
+ return {"argmax_4d": [base.Tensor([1, 2, 4, 3])]}
+
+ def buildModel(self, sess, test_case_tensor, tc_name):
+ '''
+ This method is called per test case (defined by getTestCases()).
+
+ keyword argument:
+ test_case_tensor -- test case tensor metadata
+ For example, if a test case is { "mul_1d_1d": [base.Tensor([5]), base.Tensor([5])] }
+ test_case_tensor is [base.Tensor([5]), base.Tensor([5])]
+ '''
+
+ input_list = []
+
+ # ------ modify below for your model FROM here -------#
+ x_tensor = self.createTFInput(test_case_tensor[0], input_list)
+
+ output_node = tf.arg_max(x_tensor, 0, output_type=tf.int32, name=tc_name)
+ # ------ modify UNTIL here for your model -------#
+
+ # Note if don't have any CONST value, creating checkpoint file fails.
+ # The next lines insert such (CONST) to prevent such error.
+ # So, Graph.pb/pbtxt contains this garbage info,
+ # but this garbage info will be removed in Graph_frozen.pb/pbtxt
+ garbage = tf.get_variable(
+ "garbage", [1], dtype=tf.float32, initializer=tf.zeros_initializer())
+ init_op = tf.global_variables_initializer()
+ garbage_value = [0]
+ sess.run(tf.assign(garbage, garbage_value))
+
+ sess.run(init_op)
+
+ # ------ modify appropriate return value -------#
+
+ # returning (input_node_list, output_node_list)
+ return (input_list, [output_node])
+
+
+# --------
+if __name__ == "__main__":
+
+ parser = argparse.ArgumentParser(
+ description='Converted Tensorflow model in python to frozen model.')
+ parser.add_argument(
+ "out_dir",
+ help=
+ "directory where generated pb, pbtxt, checkpoint and Tensorboard log files are stored."
+ )
+
+ args = parser.parse_args()
+ root_output_path = args.out_dir
+
+ Gen(root_output_path).createSaveFreezeModel()
diff --git a/tools/tensorflow_model_freezer/sample/ARGMIN_gen.py b/tools/tensorflow_model_freezer/sample/ARGMIN_gen.py
new file mode 100755
index 000000000..68b399234
--- /dev/null
+++ b/tools/tensorflow_model_freezer/sample/ARGMIN_gen.py
@@ -0,0 +1,100 @@
+#!/usr/bin/python
+
+# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+import sys
+import platform
+import tensorflow as tf
+import argparse
+
+import base_freezer as base
+import model_freezer_util as util
+
+
+class Gen(base.BaseFreezer):
+ '''
+ class to generate tflite files for MUL
+ '''
+
+ def __init__(self, path):
+ super(self.__class__, self).__init__(path)
+
+ def getOutputDirectory(self):
+ return os.path.join(self.root_output_path,
+ 'argmin') # the root path of generated files
+
+ def getTestCases(self):
+ '''
+ this returns a a hash containg test cases.
+ key of return hash is test case name and
+ value of return hash is test is a list of input tensor metadata.
+ test name (key of hash) is used as
+ - prefix of file name to be generated (don't use white space or special characters)
+ - output node name pf graph
+ '''
+ return {"argmin_4d": [base.Tensor([1, 2, 4, 3])]}
+
+ def buildModel(self, sess, test_case_tensor, tc_name):
+ '''
+ This method is called per test case (defined by getTestCases()).
+
+ keyword argument:
+ test_case_tensor -- test case tensor metadata
+ For example, if a test case is { "mul_1d_1d": [base.Tensor([5]), base.Tensor([5])] }
+ test_case_tensor is [base.Tensor([5]), base.Tensor([5])]
+ '''
+
+ input_list = []
+
+ # ------ modify below for your model FROM here -------#
+ x_tensor = self.createTFInput(test_case_tensor[0], input_list)
+
+ output_node = tf.arg_min(x_tensor, 0, name=tc_name)
+ # ------ modify UNTIL here for your model -------#
+
+ # Note if don't have any CONST value, creating checkpoint file fails.
+ # The next lines insert such (CONST) to prevent such error.
+ # So, Graph.pb/pbtxt contains this garbage info,
+ # but this garbage info will be removed in Graph_frozen.pb/pbtxt
+ garbage = tf.get_variable(
+ "garbage", [1], dtype=tf.float32, initializer=tf.zeros_initializer())
+ init_op = tf.global_variables_initializer()
+ garbage_value = [0]
+ sess.run(tf.assign(garbage, garbage_value))
+
+ sess.run(init_op)
+
+ # ------ modify appropriate return value -------#
+
+ # returning (input_node_list, output_node_list)
+ return (input_list, [output_node])
+
+
+# --------
+if __name__ == "__main__":
+
+ parser = argparse.ArgumentParser(
+ description='Converted Tensorflow model in python to frozen model.')
+ parser.add_argument(
+ "out_dir",
+ help=
+ "directory where generated pb, pbtxt, checkpoint and Tensorboard log files are stored."
+ )
+
+ args = parser.parse_args()
+ root_output_path = args.out_dir
+
+ Gen(root_output_path).createSaveFreezeModel()
diff --git a/tools/tensorflow_model_freezer/sample/DIV_gen.py b/tools/tensorflow_model_freezer/sample/DIV_gen.py
index c4e9cde07..d1b794cd7 100755
--- a/tools/tensorflow_model_freezer/sample/DIV_gen.py
+++ b/tools/tensorflow_model_freezer/sample/DIV_gen.py
@@ -124,13 +124,6 @@ class Gen(base.BaseFreezer):
return (input_list, [output_node])
-'''
-How to run
-$ chmod +x tools/tensorflow_model_freezer/sample/name_of_this_file.py
-$ PYTHONPATH=$PYTHONPATH:./tools/tensorflow_model_freezer/ \
- tools/tensorflow_model_freezer/sample/name_of_this_file.py \
- ~/temp # directory where model files are saved
-'''
# --------
if __name__ == "__main__":
diff --git a/tools/tensorflow_model_freezer/sample/LOGICAL_AND_gen.py b/tools/tensorflow_model_freezer/sample/LOGICAL_AND_gen.py
new file mode 100755
index 000000000..912af65b2
--- /dev/null
+++ b/tools/tensorflow_model_freezer/sample/LOGICAL_AND_gen.py
@@ -0,0 +1,105 @@
+#!/usr/bin/python
+
+# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+import sys
+import platform
+import tensorflow as tf
+import argparse
+
+import base_freezer as base
+import model_freezer_util as util
+
+
+class Gen(base.BaseFreezer):
+ '''
+ class to generate tflite files for MUL
+ '''
+
+ def __init__(self, path):
+ super(self.__class__, self).__init__(path)
+
+ def getOutputDirectory(self):
+ return os.path.join(self.root_output_path,
+ 'logical_and') # the root path of generated files
+
+ def getTestCases(self):
+ '''
+ this returns a a hash containg test cases.
+ key of return hash is test case name and
+ value of return hash is test is a list of input tensor metadata.
+ test name (key of hash) is used as
+ - prefix of file name to be generated (don't use white space or special characters)
+ - output node name pf graph
+ '''
+ return {"logical_and_4d": [base.Tensor([1, 2, 4, 3]), base.Tensor([1, 2, 4, 3])]}
+
+ def buildModel(self, sess, test_case_tensor, tc_name):
+ '''
+ This method is called per test case (defined by getTestCases()).
+
+ keyword argument:
+ test_case_tensor -- test case tensor metadata
+ For example, if a test case is { "mul_1d_1d": [base.Tensor([5]), base.Tensor([5])] }
+ test_case_tensor is [base.Tensor([5]), base.Tensor([5])]
+ '''
+
+ input_list = []
+
+ # ------ modify below for your model FROM here -------#
+ x_tensor = self.createTFInput(test_case_tensor[0], input_list)
+ y_tensor = self.createTFInput(test_case_tensor[1], input_list)
+
+ output_node = tf.logical_and(
+ tf.greater(x_tensor, tf.constant(0.0)),
+ tf.less(y_tensor, tf.constant(1.0)),
+ name=tc_name)
+
+ # ------ modify UNTIL here for your model -------#
+
+ # Note if don't have any CONST value, creating checkpoint file fails.
+ # The next lines insert such (CONST) to prevent such error.
+ # So, Graph.pb/pbtxt contains this garbage info,
+ # but this garbage info will be removed in Graph_frozen.pb/pbtxt
+ garbage = tf.get_variable(
+ "garbage", [1], dtype=tf.float32, initializer=tf.zeros_initializer())
+ init_op = tf.global_variables_initializer()
+ garbage_value = [0]
+ sess.run(tf.assign(garbage, garbage_value))
+
+ sess.run(init_op)
+
+ # ------ modify appropriate return value -------#
+
+ # returning (input_node_list, output_node_list)
+ return (input_list, [output_node])
+
+
+# --------
+if __name__ == "__main__":
+
+ parser = argparse.ArgumentParser(
+ description='Converted Tensorflow model in python to frozen model.')
+ parser.add_argument(
+ "out_dir",
+ help=
+ "directory where generated pb, pbtxt, checkpoint and Tensorboard log files are stored."
+ )
+
+ args = parser.parse_args()
+ root_output_path = args.out_dir
+
+ Gen(root_output_path).createSaveFreezeModel()
diff --git a/tools/tensorflow_model_freezer/sample/LOGICAL_NOT_gen.py b/tools/tensorflow_model_freezer/sample/LOGICAL_NOT_gen.py
new file mode 100755
index 000000000..34c0994ea
--- /dev/null
+++ b/tools/tensorflow_model_freezer/sample/LOGICAL_NOT_gen.py
@@ -0,0 +1,100 @@
+#!/usr/bin/python
+
+# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+import sys
+import platform
+import tensorflow as tf
+import argparse
+
+import base_freezer as base
+import model_freezer_util as util
+
+
+class Gen(base.BaseFreezer):
+ '''
+ class to generate tflite files for MUL
+ '''
+
+ def __init__(self, path):
+ super(self.__class__, self).__init__(path)
+
+ def getOutputDirectory(self):
+ return os.path.join(self.root_output_path,
+ 'logical_not') # the root path of generated files
+
+ def getTestCases(self):
+ '''
+ this returns a a hash containg test cases.
+ key of return hash is test case name and
+ value of return hash is test is a list of input tensor metadata.
+ test name (key of hash) is used as
+ - prefix of file name to be generated (don't use white space or special characters)
+ - output node name pf graph
+ '''
+ return {"logical_not_4d": [base.Tensor([1, 2, 4, 3])]}
+
+ def buildModel(self, sess, test_case_tensor, tc_name):
+ '''
+ This method is called per test case (defined by getTestCases()).
+
+ keyword argument:
+ test_case_tensor -- test case tensor metadata
+ For example, if a test case is { "mul_1d_1d": [base.Tensor([5]), base.Tensor([5])] }
+ test_case_tensor is [base.Tensor([5]), base.Tensor([5])]
+ '''
+
+ input_list = []
+
+ # ------ modify below for your model FROM here -------#
+ x_tensor = self.createTFInput(test_case_tensor[0], input_list)
+
+ output_node = tf.logical_not(tf.greater(x_tensor, tf.constant(0.0)), name=tc_name)
+ # ------ modify UNTIL here for your model -------#
+
+ # Note if don't have any CONST value, creating checkpoint file fails.
+ # The next lines insert such (CONST) to prevent such error.
+ # So, Graph.pb/pbtxt contains this garbage info,
+ # but this garbage info will be removed in Graph_frozen.pb/pbtxt
+ garbage = tf.get_variable(
+ "garbage", [1], dtype=tf.float32, initializer=tf.zeros_initializer())
+ init_op = tf.global_variables_initializer()
+ garbage_value = [0]
+ sess.run(tf.assign(garbage, garbage_value))
+
+ sess.run(init_op)
+
+ # ------ modify appropriate return value -------#
+
+ # returning (input_node_list, output_node_list)
+ return (input_list, [output_node])
+
+
+# --------
+if __name__ == "__main__":
+
+ parser = argparse.ArgumentParser(
+ description='Converted Tensorflow model in python to frozen model.')
+ parser.add_argument(
+ "out_dir",
+ help=
+ "directory where generated pb, pbtxt, checkpoint and Tensorboard log files are stored."
+ )
+
+ args = parser.parse_args()
+ root_output_path = args.out_dir
+
+ Gen(root_output_path).createSaveFreezeModel()
diff --git a/tools/tensorflow_model_freezer/sample/LOGICAL_OR_gen.py b/tools/tensorflow_model_freezer/sample/LOGICAL_OR_gen.py
new file mode 100755
index 000000000..714a52e8d
--- /dev/null
+++ b/tools/tensorflow_model_freezer/sample/LOGICAL_OR_gen.py
@@ -0,0 +1,104 @@
+#!/usr/bin/python
+
+# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+import sys
+import platform
+import tensorflow as tf
+import argparse
+
+import base_freezer as base
+import model_freezer_util as util
+
+
+class Gen(base.BaseFreezer):
+ '''
+ class to generate tflite files for MUL
+ '''
+
+ def __init__(self, path):
+ super(self.__class__, self).__init__(path)
+
+ def getOutputDirectory(self):
+ return os.path.join(self.root_output_path,
+ 'logical_or') # the root path of generated files
+
+ def getTestCases(self):
+ '''
+ this returns a a hash containg test cases.
+ key of return hash is test case name and
+ value of return hash is test is a list of input tensor metadata.
+ test name (key of hash) is used as
+ - prefix of file name to be generated (don't use white space or special characters)
+ - output node name pf graph
+ '''
+ return {"logical_or_4d": [base.Tensor([1, 2, 4, 3]), base.Tensor([1, 2, 4, 3])]}
+
+ def buildModel(self, sess, test_case_tensor, tc_name):
+ '''
+ This method is called per test case (defined by getTestCases()).
+
+ keyword argument:
+ test_case_tensor -- test case tensor metadata
+ For example, if a test case is { "mul_1d_1d": [base.Tensor([5]), base.Tensor([5])] }
+ test_case_tensor is [base.Tensor([5]), base.Tensor([5])]
+ '''
+
+ input_list = []
+
+ # ------ modify below for your model FROM here -------#
+ x_tensor = self.createTFInput(test_case_tensor[0], input_list)
+ y_tensor = self.createTFInput(test_case_tensor[1], input_list)
+
+ output_node = tf.logical_or(
+ tf.greater(x_tensor, tf.constant(0.0)),
+ tf.less(y_tensor, tf.constant(1.0)),
+ name=tc_name)
+ # ------ modify UNTIL here for your model -------#
+
+ # Note if don't have any CONST value, creating checkpoint file fails.
+ # The next lines insert such (CONST) to prevent such error.
+ # So, Graph.pb/pbtxt contains this garbage info,
+ # but this garbage info will be removed in Graph_frozen.pb/pbtxt
+ garbage = tf.get_variable(
+ "garbage", [1], dtype=tf.float32, initializer=tf.zeros_initializer())
+ init_op = tf.global_variables_initializer()
+ garbage_value = [0]
+ sess.run(tf.assign(garbage, garbage_value))
+
+ sess.run(init_op)
+
+ # ------ modify appropriate return value -------#
+
+ # returning (input_node_list, output_node_list)
+ return (input_list, [output_node])
+
+
+# --------
+if __name__ == "__main__":
+
+ parser = argparse.ArgumentParser(
+ description='Converted Tensorflow model in python to frozen model.')
+ parser.add_argument(
+ "out_dir",
+ help=
+ "directory where generated pb, pbtxt, checkpoint and Tensorboard log files are stored."
+ )
+
+ args = parser.parse_args()
+ root_output_path = args.out_dir
+
+ Gen(root_output_path).createSaveFreezeModel()
diff --git a/tools/tensorflow_model_freezer/sample/MUL_gen.py b/tools/tensorflow_model_freezer/sample/MUL_gen.py
index f2a92547b..596898dbb 100755
--- a/tools/tensorflow_model_freezer/sample/MUL_gen.py
+++ b/tools/tensorflow_model_freezer/sample/MUL_gen.py
@@ -59,8 +59,8 @@ class Gen(base.BaseFreezer):
"mul_1d_scalarConst": [base.Tensor([5]),
base.Tensor([], const_val=1.1)], # mul by scalar
"mul_2d_scalarConst": [base.Tensor([5, 3]),
- base.Tensor([], const_val=1.1)],
- "mul_1d_scalar": [base.Tensor([5, 3]), base.Tensor([])]
+ base.Tensor([], const_val=1.1)]
+ # "mul_2d_scalar": [base.Tensor([5, 3]), base.Tensor([])] # not support scalar input
}
def buildModel(self, sess, test_case_tensor, tc_name):
@@ -104,13 +104,6 @@ class Gen(base.BaseFreezer):
return (input_list, [output_node])
-'''
-How to run
-$ chmod +x tools/tensorflow_model_freezer/sample/name_of_this_file.py
-$ PYTHONPATH=$PYTHONPATH:./tools/tensorflow_model_freezer/ \
- tools/tensorflow_model_freezer/sample/name_of_this_file.py \
- ~/temp # directory where model files are saved
-'''
# --------
if __name__ == "__main__":
diff --git a/tools/tensorflow_model_freezer/sample/SQUEEZE_gen.py b/tools/tensorflow_model_freezer/sample/SQUEEZE_gen.py
index 88b3dfcb2..12fb5122e 100755
--- a/tools/tensorflow_model_freezer/sample/SQUEEZE_gen.py
+++ b/tools/tensorflow_model_freezer/sample/SQUEEZE_gen.py
@@ -103,13 +103,6 @@ class Gen(base.BaseFreezer):
return (input_list, [output_node])
-'''
-How to run
-$ chmod +x tools/tensorflow_model_freezer/sample/name_of_this_file.py
-$ PYTHONPATH=$PYTHONPATH:./tools/tensorflow_model_freezer/ \
- tools/tensorflow_model_freezer/sample/name_of_this_file.py \
- ~/temp # directory where model files are saved
-'''
# --------
if __name__ == "__main__":
diff --git a/tools/tensorflow_model_freezer/sample/STACK_gen.py b/tools/tensorflow_model_freezer/sample/STACK_gen.py
new file mode 100755
index 000000000..2bea40698
--- /dev/null
+++ b/tools/tensorflow_model_freezer/sample/STACK_gen.py
@@ -0,0 +1,101 @@
+#!/usr/bin/python
+
+# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+import sys
+import platform
+import tensorflow as tf
+import argparse
+
+import base_freezer as base
+import model_freezer_util as util
+
+
+class Gen(base.BaseFreezer):
+ '''
+ class to generate tflite files for MUL
+ '''
+
+ def __init__(self, path):
+ super(self.__class__, self).__init__(path)
+
+ def getOutputDirectory(self):
+ return os.path.join(self.root_output_path,
+ 'stack') # the root path of generated files
+
+ def getTestCases(self):
+ '''
+ this returns a a hash containg test cases.
+ key of return hash is test case name and
+ value of return hash is test is a list of input tensor metadata.
+ test name (key of hash) is used as
+ - prefix of file name to be generated (don't use white space or special characters)
+ - output node name pf graph
+ '''
+ return {"stack_4d": [base.Tensor([1, 4, 3]), base.Tensor([1, 4, 3])]}
+
+ def buildModel(self, sess, test_case_tensor, tc_name):
+ '''
+ This method is called per test case (defined by getTestCases()).
+
+ keyword argument:
+ test_case_tensor -- test case tensor metadata
+ For example, if a test case is { "mul_1d_1d": [base.Tensor([5]), base.Tensor([5])] }
+ test_case_tensor is [base.Tensor([5]), base.Tensor([5])]
+ '''
+
+ input_list = []
+
+ # ------ modify below for your model FROM here -------#
+ x_tensor = self.createTFInput(test_case_tensor[0], input_list)
+ y_tensor = self.createTFInput(test_case_tensor[1], input_list)
+
+ output_node = tf.stack([x_tensor, y_tensor], 0, name=tc_name)
+ # ------ modify UNTIL here for your model -------#
+
+ # Note if don't have any CONST value, creating checkpoint file fails.
+ # The next lines insert such (CONST) to prevent such error.
+ # So, Graph.pb/pbtxt contains this garbage info,
+ # but this garbage info will be removed in Graph_frozen.pb/pbtxt
+ garbage = tf.get_variable(
+ "garbage", [1], dtype=tf.float32, initializer=tf.zeros_initializer())
+ init_op = tf.global_variables_initializer()
+ garbage_value = [0]
+ sess.run(tf.assign(garbage, garbage_value))
+
+ sess.run(init_op)
+
+ # ------ modify appropriate return value -------#
+
+ # returning (input_node_list, output_node_list)
+ return (input_list, [output_node])
+
+
+# --------
+if __name__ == "__main__":
+
+ parser = argparse.ArgumentParser(
+ description='Converted Tensorflow model in python to frozen model.')
+ parser.add_argument(
+ "out_dir",
+ help=
+ "directory where generated pb, pbtxt, checkpoint and Tensorboard log files are stored."
+ )
+
+ args = parser.parse_args()
+ root_output_path = args.out_dir
+
+ Gen(root_output_path).createSaveFreezeModel()
diff --git a/tools/tensorflow_model_freezer/sample/TOPK_gen.py b/tools/tensorflow_model_freezer/sample/TOPK_gen.py
index 0c16d5b75..8f1882bd1 100755
--- a/tools/tensorflow_model_freezer/sample/TOPK_gen.py
+++ b/tools/tensorflow_model_freezer/sample/TOPK_gen.py
@@ -63,6 +63,7 @@ class Gen(base.BaseFreezer):
'''
input_list = []
+ output_list = []
# ------ modify below for your model FROM here -------#
@@ -70,11 +71,13 @@ class Gen(base.BaseFreezer):
y_tensor = self.createTFInput(test_case_tensor[1], input_list)
# defining output node and input list
- output_node = tf.nn.top_k(
+ values_op, indices_op = tf.nn.top_k(
x_tensor,
y_tensor, # add your input here
name=tc_name) # do not modify name
+ output_list.append(values_op)
+ output_list.append(indices_op)
# ------ modify UNTIL here for your model -------#
# Note if don't have any CONST value, creating checkpoint file fails.
@@ -92,16 +95,9 @@ class Gen(base.BaseFreezer):
# ------ modify appropriate return value -------#
# returning (input_node_list, output_node_list)
- return (input_list, [output_node])
+ return (input_list, output_list)
-'''
-How to run
-$ chmod +x tools/tensorflow_model_freezer/sample/name_of_this_file.py
-$ PYTHONPATH=$PYTHONPATH:./tools/tensorflow_model_freezer/ \
- tools/tensorflow_model_freezer/sample/name_of_this_file.py \
- ~/temp # directory where model files are saved
-'''
# --------
if __name__ == "__main__":
diff --git a/tools/tensorflow_model_freezer/sample/UNSTACK_gen.py b/tools/tensorflow_model_freezer/sample/UNSTACK_gen.py
new file mode 100644
index 000000000..c5bce0d18
--- /dev/null
+++ b/tools/tensorflow_model_freezer/sample/UNSTACK_gen.py
@@ -0,0 +1,100 @@
+#!/usr/bin/python
+
+# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+import sys
+import platform
+import tensorflow as tf
+import argparse
+
+import base_freezer as base
+import model_freezer_util as util
+
+
+class Gen(base.BaseFreezer):
+ '''
+ class to generate tflite files for MUL
+ '''
+
+ def __init__(self, path):
+ super(self.__class__, self).__init__(path)
+
+ def getOutputDirectory(self):
+ return os.path.join(self.root_output_path,
+ 'unstack') # the root path of generated files
+
+ def getTestCases(self):
+ '''
+ this returns a a hash containg test cases.
+ key of return hash is test case name and
+ value of return hash is test is a list of input tensor metadata.
+ test name (key of hash) is used as
+ - prefix of file name to be generated (don't use white space or special characters)
+ - output node name pf graph
+ '''
+ return {"unstack_4d": [base.Tensor([4, 4, 3])]}
+
+ def buildModel(self, sess, test_case_tensor, tc_name):
+ '''
+ This method is called per test case (defined by getTestCases()).
+
+ keyword argument:
+ test_case_tensor -- test case tensor metadata
+ For example, if a test case is { "mul_1d_1d": [base.Tensor([5]), base.Tensor([5])] }
+ test_case_tensor is [base.Tensor([5]), base.Tensor([5])]
+ '''
+
+ input_list = []
+
+ # ------ modify below for your model FROM here -------#
+ x_tensor = self.createTFInput(test_case_tensor[0], input_list)
+
+ output_node = tf.unstack([x_tensor], 4, 1, name=tc_name)
+ # ------ modify UNTIL here for your model -------#
+
+ # Note if don't have any CONST value, creating checkpoint file fails.
+ # The next lines insert such (CONST) to prevent such error.
+ # So, Graph.pb/pbtxt contains this garbage info,
+ # but this garbage info will be removed in Graph_frozen.pb/pbtxt
+ garbage = tf.get_variable(
+ "garbage", [1], dtype=tf.float32, initializer=tf.zeros_initializer())
+ init_op = tf.global_variables_initializer()
+ garbage_value = [0]
+ sess.run(tf.assign(garbage, garbage_value))
+
+ sess.run(init_op)
+
+ # ------ modify appropriate return value -------#
+
+ # returning (input_node_list, output_node_list)
+ return (input_list, [output_node])
+
+
+# --------
+if __name__ == "__main__":
+
+ parser = argparse.ArgumentParser(
+ description='Converted Tensorflow model in python to frozen model.')
+ parser.add_argument(
+ "out_dir",
+ help=
+ "directory where generated pb, pbtxt, checkpoint and Tensorboard log files are stored."
+ )
+
+ args = parser.parse_args()
+ root_output_path = args.out_dir
+
+ Gen(root_output_path).createSaveFreezeModel()
diff --git a/tools/test_driver/README.md b/tools/test_driver/README.md
deleted file mode 100644
index 2981267a5..000000000
--- a/tools/test_driver/README.md
+++ /dev/null
@@ -1,63 +0,0 @@
-# How the test driver works
-
-## Unittest
-- There are two kinds of unittest:
- - Kernel ACL
- - Runtime
-- Related file : `run_unittest.sh`
-- Usage :
-```
-$ ./tools/test_driver/test_driver.sh \
- --artifactpath=. \
- --unittest
-```
-- The `run_unittest.sh` usage :
-
-```
-$ LD_LIBRARY_PATH=Product/out/lib \
- ./tools/test_driver/run_unittest.sh \
- --reportdir=report \
- --unittestdir=Product/out/unittest
-```
-
-### Kernel ACL Unittest
-- Test whether the various operations are performed successfully and whether the output and the expected value are the same.
-- TC location : `libs/kernel/acl/src/`
-
-### Runtime Unittest
-- Test whether the expected value and the actual output value are the same when the model is configured, compiled and executed.
-- TC location : `runtimes/tests/neural_networks_test/`
-
-## Framework test
-- Execute the **tflite model** using the given **driver**.
-- There is a TC directory for each model, and a `config.sh` file exists in each TC directory.
-- When `run_test.sh`, refer to the **tflite model** information in `config.sh`, download the file, and run the **tflite model** with the given **driver**.
-- Related files : `run_test.sh` and `run_frameworktest.sh`
-- TC location :
- - `tests/framework/tests/` : Config directory for TC
- - `tests/framework/cache/` : TC (Downloaded tflite model files)
-
-### Run tflite_run with various tflite models
-- Driver : `tflite_run`
-- Driver source location : `tools/tflite_run/`
-- Usage :
-```
-$ ./tools/test_driver/test_driver.sh \
- --artifactpath=. \
- --frameworktest
-```
-- Related pages : [tflite_run](https://github.sec.samsung.net/STAR/nnfw/tree/master/tools/tflite_run)
-
-### Run nnapi_test with various tflite models
-- `nnapi_test` runs tflite in two ways and compares the result:
- 1. tflite interpreter
- 2. `libneuralnetworks.so`, which could be PureACL or NNAPI depending on `--ldlibrarypath`(`LD_LIBRARY_PATH`)
-- Driver : `nnapi_test`
-- Driver source location : `tools/nnapi_test/`
-- Usage :
-```
-$ ./tools/test_driver/test_driver.sh \
- --artifactpath=. \
- --verification .
-```
-
diff --git a/tools/test_driver/benchmark_op_list.txt b/tools/test_driver/benchmark_op_list.txt
deleted file mode 100644
index 166ddb7d7..000000000
--- a/tools/test_driver/benchmark_op_list.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-add/4D
-average_pool_2d/avgpool1
-average_pool_2d/avgpool1
-concat/concat1
-conv_2d/convolution1
-conv_2d/convolution2
-div/broadcast
-max_pool_2d/maxpool1
-max_pool_2d/maxpool2
-resize_bilinear
-softmax
diff --git a/tools/test_driver/common.sh b/tools/test_driver/common.sh
deleted file mode 100755
index 12a35fd35..000000000
--- a/tools/test_driver/common.sh
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/bin/bash
-#
-# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-MY_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
-
-function switch_nnfw_kernel_env()
-{
- local switch=$1 # "ON" or "OFF"
- local mode=$2 # "acl" or "neon" or ""
-
- # TODO: Handle whether there is nnfw_kernel_env_list.txt or not
- local NNFW_KERNEL_ENV_FILE=$MY_PATH/nnfw_kernel_env_list.txt
-
- for ENV in $(cat $NNFW_KERNEL_ENV_FILE); do
- if [[ "$switch" == "ON" ]]; then
- export "$ENV=$mode"
- else
- unset "$ENV"
- fi
- done
-}
diff --git a/tools/test_driver/neurun_frameworktest_list.txt b/tools/test_driver/neurun_frameworktest_list.txt
deleted file mode 100644
index b97558b0c..000000000
--- a/tools/test_driver/neurun_frameworktest_list.txt
+++ /dev/null
@@ -1,10 +0,0 @@
-average_pool_2d/avgpool1
-average_pool_2d/avgpool1
-conv_2d/convolution1
-conv_2d/convolution2
-max_pool_2d/maxpool1
-max_pool_2d/maxpool2
-softmax
-reshape/reshape1
-MODELS/inception_nonslim
-MODELS/inception_slim
diff --git a/tools/test_driver/nnfw_kernel_env_list.txt b/tools/test_driver/nnfw_kernel_env_list.txt
deleted file mode 100644
index 9cb3fc46c..000000000
--- a/tools/test_driver/nnfw_kernel_env_list.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-NNFW_KERNEL_convFloat32
-NNFW_KERNEL_averagePoolFloat32
-NNFW_KERNEL_maxPoolFloat32
-NNFW_KERNEL_softmaxFloat32
-NNFW_KERNEL_fullyConnectedFloat32
-NNFW_KERNEL_concatenationFloat32
-NNFW_KERNEL_reshapeGeneric
diff --git a/tools/test_driver/print_to_json.sh b/tools/test_driver/print_to_json.sh
deleted file mode 100755
index a5ea5689b..000000000
--- a/tools/test_driver/print_to_json.sh
+++ /dev/null
@@ -1,169 +0,0 @@
-#!/bin/bash
-#
-# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-JSON_BENCHMARK_REPORT_DIR= # $ARTIFACT/report/benchmark
-JSON_PRINT_TO_DIR= # $ARTIFACT/report
-JSON_RESULT_JSON= # $ARTIFACT/report/benchmark_result.json or benchmark_op_result.json
-JSON_MODELS_FILE_DIR= # $ARTIFACT/report/benchmark
-
-function echo_to_file
-{
- echo -e "$1" >> $JSON_RESULT_JSON
-}
-
-function print_comma() # ,
-{
- echo_to_file ","
-}
-
-function print_brace_start() # {
-{
- echo_to_file "{"
-}
-
-function print_brace_end() # }
-{
- echo_to_file "}"
-}
-
-function print_bracket_start() # "$NAME": [
-{
- local NAME=$1
- echo_to_file "\"$NAME\":["
-}
-
-function print_bracket_end() # ]
-{
- echo_to_file "]"
-}
-
-function print_key_value() # "$KEY": "$VALUE"
-{
- local KEY=$1
- local VALUE=$2
- echo_to_file "\"$KEY\": \"$VALUE\""
-}
-
-function print_key_value_no_quot() # "$KEY": $VALUE
-{
- local KEY=$1
- local VALUE=$2
- echo_to_file "\"$KEY\": $VALUE"
-}
-
-function print_key_value_dbl() # "dblValue": $VALUE
-{
- local VALUE=$1
- echo_to_file "\"dblValue\": $VALUE" # value should not include ""
-}
-
-function print_results()
-{
- local NAME=$1
- local MEAN=$2
-
- print_bracket_start "results"
- print_brace_start
- print_key_value "name" "Mean_of_$NAME"
- print_comma
- print_key_value "unit" "ms"
- print_comma
- print_key_value_dbl "$MEAN"
- print_brace_end
- print_bracket_end
-}
-
-function print_test()
-{
- local NAME=$1
- local RESULT=$2
-
- print_brace_start
- print_key_value "name" "$NAME"
- print_comma
- print_results "$NAME" "$RESULT"
- print_brace_end
-}
-
-function print_tests()
-{
- local MODEL=$1
- local REPORT_MODEL_DIR=$JSON_BENCHMARK_REPORT_DIR/$MODEL
- local TEST_RESULTS=$(find $REPORT_MODEL_DIR -name "*.result" -exec basename {} \;)
- local TEST_NUM=$(find $REPORT_MODEL_DIR -name "*.result" | wc -l)
-
- print_bracket_start "tests"
-
- local i=0
- for TEST in $TEST_RESULTS; do
- local NAME=$(cat $REPORT_MODEL_DIR/$TEST | awk '{print $1}')
- local RESULT=$(cat $REPORT_MODEL_DIR/$TEST | awk '{print $2}')
- print_test $NAME $RESULT
- if [[ $i -ne $TEST_NUM-1 ]]; then
- print_comma
- fi
- i=$((i+1))
- done
-
- print_bracket_end
-}
-
-function print_groups()
-{
- local TOTAL_MODEL_NUM=0
- local TOTAL_MODELS=
-
- for MODELS_FILE in $(find $JSON_MODELS_FILE_DIR -name "benchmark*_models.txt"); do
- # In $MODELS_FILE, there are only unique(not duplicated) model names.
- local MODEL_NUM=$(cat $MODELS_FILE | wc -l)
- TOTAL_MODEL_NUM=$((TOTAL_MODEL_NUM+MODEL_NUM))
- for MODELS in $(cat $MODELS_FILE); do
- TOTAL_MODELS+="$MODELS "
- done
- done
-
- print_bracket_start "groups"
-
- local i=0
- for MODEL in $TOTAL_MODELS; do
- print_brace_start
- print_key_value "name" " $MODEL"
- print_comma
- print_tests $MODEL
- print_brace_end
- if [[ $i -ne $TOTAL_MODEL_NUM-1 ]]; then
- print_comma
- fi
- i=$((i+1))
- done
-
- print_bracket_end
-}
-
-function print_to_json()
-{
- JSON_BENCHMARK_REPORT_DIR=$1
- JSON_PRINT_TO_DIR=$2
- JSON_PRINT_TO_FILENAME=$3
-
- JSON_RESULT_JSON=$JSON_PRINT_TO_DIR/$JSON_PRINT_TO_FILENAME
- rm -f $JSON_RESULT_JSON
- JSON_MODELS_FILE_DIR=$JSON_BENCHMARK_REPORT_DIR
-
- print_brace_start
- print_groups
- print_brace_end
-}
diff --git a/tools/test_driver/py/common.py b/tools/test_driver/py/common.py
deleted file mode 100755
index 37b40e1ce..000000000
--- a/tools/test_driver/py/common.py
+++ /dev/null
@@ -1,39 +0,0 @@
-# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-import os
-import os.path
-
-mypath = os.path.abspath(os.path.dirname(__file__))
-
-
-def switch_nnfw_kernel_env(mode):
- # mode : "acl" or "neon" or ""
-
- # TODO: Handle whether there is nnfw_kernel_env_list.txt or not
- # FIXME: Now nnfw_kernel_env_list.txt is parent dir of current dir
- filename = "nnfw_kernel_env_list.txt"
- envfilename = mypath + "/../{filename}".format(filename=filename)
-
- with open(envfilename) as envfile:
- for env in envfile:
- env = env[:-1] # env has new line at the end
- os.environ[env] = mode
-
-
-if __name__ == "__main__":
- # for test
- switch_nnfw_kernel_env("acl")
- switch_nnfw_kernel_env("neon")
- switch_nnfw_kernel_env("")
diff --git a/tools/test_driver/py/run_frameworktest.py b/tools/test_driver/py/run_frameworktest.py
deleted file mode 100755
index a4fbd075a..000000000
--- a/tools/test_driver/py/run_frameworktest.py
+++ /dev/null
@@ -1,199 +0,0 @@
-#!/usr/bin/env python
-
-# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-import os
-import sys
-import argparse
-
-
-def get_parsed_options():
- parser = argparse.ArgumentParser(
- prog='run_frameworktest.py', usage='%(prog)s [options]')
-
- parser.add_argument(
- "--runtestsh",
- action="store",
- type=str,
- dest="fwtest_runtestsh",
- required=True,
- help="(Usually : tests/framework/run_test.sh) run test shell for framework test")
-
- parser.add_argument(
- "--driverbin",
- action="store",
- type=str,
- dest="fwtest_driverbin",
- required=True,
- help="(Usually in Product/out/bin/) driver bin for framework test")
-
- parser.add_argument(
- "--tapname",
- action="store",
- type=str,
- dest="fwtest_tapname",
- help="tap name for framework test")
-
- parser.add_argument(
- "--logname",
- action="store",
- type=str,
- dest="fwtest_logname",
- help="log name for framework test")
-
- parser.add_argument(
- "--testname",
- action="store",
- type=str,
- dest="fwtest_testname",
- help="test name of framework test")
-
- parser.add_argument(
- "--frameworktest_list_file",
- action="store",
- type=str,
- dest="frameworktest_list_file",
- help="list of files to run framework test")
-
- parser.add_argument(
- "--reportdir",
- action="store",
- type=str,
- dest="fwtest_reportdir",
- default="report",
- help="(default=report) directory that each test result will be stored")
-
- parser.add_argument(
- "--ldlibrarypath",
- action="store",
- type=str,
- dest="ldlibrarypath",
- help=
- "(usually : ARTIFACT_PATH/Product/out/lib) path that you want to include libraries"
- )
-
- options = parser.parse_args()
- return options
-
-
-# Check each parameters if they are valid or not
-def check_params(fwtest_runtestsh, fwtest_driverbin, fwtest_reportdir, fwtest_tapname,
- fwtest_logname, fwtest_testname, frameworktest_list_file,
- ldlibrary_path):
- if fwtest_runtestsh == "" or fwtest_runtestsh == None:
- print("Fail : runtestsh is not given")
- print("(Usually runtestsh for framework test is tests/framework/run_test.sh)")
- sys.exit(1)
-
- if os.path.isfile(fwtest_runtestsh) == False:
- print("Fail : runtestsh is not valid")
- sys.exit(1)
-
- if fwtest_driverbin == "" or fwtest_driverbin == None:
- print("Fail : driverbin is not given")
- print("(Usually driverbin for framework test is in Product/out/bin/)")
- sys.exit(1)
-
- if os.path.isfile(fwtest_driverbin) == False:
- print("Fail : driverbin is not valid")
- sys.exit(1)
-
- if fwtest_testname == "" or fwtest_testname == None:
- print("Fail : testname is not given")
- sys.exit(1)
-
- if fwtest_tapname == "" or fwtest_tapname == None:
- print("Fail : tapname is not given")
- sys.exit(1)
-
- if fwtest_logname == "" or fwtest_logname == None:
- print("Fail : logname is not given")
- sys.exit(1)
-
- if fwtest_reportdir == "" or fwtest_reportdir == None:
- print("Fail : report directory is not given")
- sys.exit(1)
-
- if type(ldlibrary_path) is str and ldlibrary_path != "":
- os.environ["LD_LIBRARY_PATH"] = ldlibrary_path
-
-
-# Just call this function when running framework test in test_driver.py
-def run_frameworktest(fwtest_runtestsh, fwtest_driverbin, fwtest_reportdir,
- fwtest_tapname, fwtest_logname, fwtest_testname,
- frameworktest_list_file, ldlibrary_path):
-
- # Handling exceptions for parameters
- check_params(fwtest_runtestsh, fwtest_driverbin, fwtest_reportdir, fwtest_tapname,
- fwtest_logname, fwtest_testname, frameworktest_list_file, ldlibrary_path)
-
- os.makedirs(fwtest_reportdir, exist_ok=True)
-
- print("")
- print("============================================")
- print("{fwtest_testname} with {fwtest_driverbin_name} ...".format(
- fwtest_testname=fwtest_testname,
- fwtest_driverbin_name=fwtest_driverbin[fwtest_driverbin.rfind('/') + 1:]))
-
- # Run framework test using models in model_list
- model_list = ""
- if frameworktest_list_file != None and frameworktest_list_file != "":
- fwtest_list_file = open(frameworktest_list_file, "r")
- for line in fwtest_list_file:
- model_list += (line[:-1] + " ")
- fwtest_list_file.close()
-
- # If model_list is empty, all possible models will be found automatically by fwtest_runtestsh
- cmd = "{fwtest_runtestsh} --driverbin={fwtest_driverbin} \
- --reportdir={fwtest_reportdir} \
- --tapname={fwtest_tapname} \
- {model_list} \
- > {fwtest_reportdir}/{fwtest_logname} 2>&1".format(
- fwtest_runtestsh=fwtest_runtestsh,
- fwtest_driverbin=fwtest_driverbin,
- fwtest_reportdir=fwtest_reportdir,
- fwtest_tapname=fwtest_tapname,
- model_list=model_list,
- fwtest_logname=fwtest_logname)
- fwtest_result = os.system(cmd)
-
- print("")
- tap_file_path = "{fwtest_reportdir}/{fwtest_tapname}".format(
- fwtest_reportdir=fwtest_reportdir, fwtest_tapname=fwtest_tapname)
- tap_file = open(tap_file_path, "r")
- tap_data = tap_file.read()
- print(tap_data)
- tap_file.close()
-
- if fwtest_result != 0:
- print("")
- print("{fwtest_testname} failed... exit code: {fwtest_result}".format(
- fwtest_testname=fwtest_testname, fwtest_result=fwtest_result))
- print("============================================")
- print("")
- sys.exit(1)
-
- print("============================================")
- print("")
- sys.exit(0)
-
-
-if __name__ == "__main__":
- options = get_parsed_options()
- sys.exit(
- run_frameworktest(options.fwtest_runtestsh, options.fwtest_driverbin,
- options.fwtest_reportdir, options.fwtest_tapname,
- options.fwtest_logname, options.fwtest_testname,
- options.frameworktest_list_file, options.ldlibrarypath))
diff --git a/tools/test_driver/py/run_unittest.py b/tools/test_driver/py/run_unittest.py
deleted file mode 100755
index 2e2ad3434..000000000
--- a/tools/test_driver/py/run_unittest.py
+++ /dev/null
@@ -1,187 +0,0 @@
-#!/usr/bin/env python
-
-# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-import os
-import sys
-import argparse
-import subprocess
-
-
-def get_parsed_options():
- parser = argparse.ArgumentParser(prog='run_unittest.py', usage='%(prog)s [options]')
-
- parser.add_argument(
- "--reportdir",
- action="store",
- type=str,
- dest="reportdir",
- default="report",
- help="(default=report) directory that each test result will be stored")
-
- parser.add_argument(
- "--unittestdir",
- action="store",
- type=str,
- dest="unittestdir",
- required=True,
- help="directory that unittests are included")
-
- parser.add_argument(
- "--ldlibrarypath",
- action="store",
- type=str,
- dest="ldlibrarypath",
- help=
- "(usually : ARTIFACT_PATH/Product/out/lib) path that you want to include libraries"
- )
-
- parser.add_argument(
- "--runall",
- action="store_true",
- dest="runall",
- default=False,
- help="run all unittest and ignore skiplist")
-
- options = parser.parse_args()
- return options
-
-
-def get_gtest_option(report_dir, test_bin, unittest_dir=None):
- # Set path to save test result
- output_option = "--gtest_output=xml:{report_dir}/{test_bin}.xml".format(
- report_dir=report_dir, test_bin=test_bin)
-
- # Set filter to run only one unit test, for runall unittest
- if '.' in test_bin:
- return output_option + " " + "--gtest_filter={test_list_item}".format(
- test_list_item=test_bin)
-
- # Set filter not to run *.skip unit tests
- filter_option = ""
- skiplist_path = "{unittest_dir}/{test_bin}.skip".format(
- unittest_dir=unittest_dir, test_bin=test_bin)
- if os.path.exists(skiplist_path):
- filter_option = "--gtest_filter=-"
- skiplist_file = open(skiplist_path, "r")
- filter_option = filter_option + ':'.join(line[:-1] for line in skiplist_file
- if line[0] != '#')
- skiplist_file.close()
-
- return output_option + " " + filter_option
-
-
-def get_test_list_items(unittest_dir, test_bin):
- cmd_output = subprocess.check_output(
- "{unittestdir}/{testbin} --gtest_list_tests".format(
- unittestdir=unittest_dir, testbin=test_bin),
- shell=True)
- all_test_list = str(cmd_output).replace('\\n', ' ').split()
- all_test_list[0] = all_test_list[0][2:]
-
- category = ""
- item = ""
- test_list_items = []
- for verbose_line in all_test_list:
- if verbose_line[-1] == '.':
- category = verbose_line
- else:
- item = "{category}{verbose_line}".format(
- category=category, verbose_line=verbose_line)
- test_list_items.append(item)
-
- return test_list_items
-
-
-# Just call this function when running unit test in test_driver.py
-def run_unittest(unittest_dir, report_dir, ldlibrary_path, runall):
- if unittest_dir == "" or unittest_dir == None:
- print("Fail : unittestdir is not given")
- print("(Usually unit test directory is Product/out/unittest)")
- sys.exit(1)
-
- if report_dir == "" or report_dir == None:
- print("Info : 'report' folder of current path will be used as report directory")
- report_dir = "report"
-
- if type(ldlibrary_path) is str and ldlibrary_path != "":
- os.environ["LD_LIBRARY_PATH"] = ldlibrary_path
-
- print("")
- print("============================================")
- print("Unittest start")
- print("============================================")
-
- # Run all unit tests in unittest_dir
- unittest_result = 0
- all_test_bin = (t for t in os.listdir(unittest_dir)
- if len(t) < 5 or t[-5:] != ".skip")
-
- for idx, test_bin in enumerate(all_test_bin):
- num_unittest = idx + 1
- print("============================================")
- print("Starting set {num_unittest}: {test_bin}...".format(
- num_unittest=num_unittest, test_bin=test_bin))
- print("============================================")
-
- ret = 0
-
- # Run all unit tests ignoring skip list
- if runall:
- test_list_items = get_test_list_items(unittest_dir, test_bin)
- for test_item in test_list_items:
- cmd = "{unittest_dir}/{test_bin} {gtest_option}".format(
- unittest_dir=unittest_dir,
- test_bin=test_bin,
- gtest_option=get_gtest_option(report_dir, test_item))
- os.system(cmd)
- # Run all unit tests except skip list
- else:
- cmd = "{unittest_dir}/{test_bin} {gtest_option}".format(
- unittest_dir=unittest_dir,
- test_bin=test_bin,
- gtest_option=get_gtest_option(report_dir, test_bin, unittest_dir))
- ret = os.system(cmd)
-
- if ret != 0:
- unittest_result = ret
- print("{test_bin} failed... return code: {unittest_result}".format(
- test_bin=test_bin, unittest_result=unittest_result))
-
- print("============================================")
- print("Finishing set {num_unittest}: {test_bin}...".format(
- num_unittest=num_unittest, test_bin=test_bin))
- print("============================================")
-
- if unittest_result != 0:
- print("============================================")
- print("Failed unit test... exit code: {unittest_result}".format(
- unittest_result=unittest_result))
- print("============================================")
- sys.exit(1)
-
- print("============================================")
- print("Completed total {num_unittest} set of unittest".format(
- num_unittest=num_unittest))
- print("Unittest end")
- print("============================================")
- sys.exit(0)
-
-
-if __name__ == "__main__":
- options = get_parsed_options()
- sys.exit(
- run_unittest(options.unittestdir, options.reportdir, options.ldlibrarypath,
- options.runall))
diff --git a/tools/test_driver/py/test_driver.py b/tools/test_driver/py/test_driver.py
deleted file mode 100755
index 9ed97d202..000000000
--- a/tools/test_driver/py/test_driver.py
+++ /dev/null
@@ -1,398 +0,0 @@
-#!/usr/bin/env python
-
-# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-import os
-import shutil
-import argparse
-import common
-import subprocess
-import sys
-
-mypath = os.path.abspath(os.path.dirname(__file__))
-
-
-def get_parsed_options():
- parser = argparse.ArgumentParser(prog='test_driver.py', usage='%(prog)s [options]')
-
- # artifactpath
- parser.add_argument(
- "--artifactpath",
- action="store",
- type=str,
- dest="artifactpath",
- default=".",
- help="(should be passed) path that has tests/ and Product/")
-
- # test
- parser.add_argument(
- "--unittest",
- action="store_true",
- dest="unittest_on",
- default=False,
- help="(default=on) run unit test")
- parser.add_argument(
- "--unittestall",
- action="store_true",
- dest="unittestall_on",
- default=False,
- help="((default=off) run all unit test without skip, overrite --unittest option")
- parser.add_argument(
- "--verification",
- action="store_true",
- dest="verification_on",
- default=False,
- help="(default=on) run verification")
- parser.add_argument(
- "--frameworktest",
- action="store_true",
- dest="frameworktest_on",
- default=False,
- help="(default=off)run framework test")
-
- # benchmark
- parser.add_argument(
- "--benchmark",
- action="store_true",
- dest="benchmark_on",
- default=False,
- help="(default=off) run benchmark")
- parser.add_argument(
- "--benchmark_acl",
- action="store_true",
- dest="benchmarkacl_on",
- default=False,
- help="(default=off) run benchmark-acl")
- parser.add_argument(
- "--benchmark_op",
- action="store_true",
- dest="benchmarkop_on",
- default=False,
- help="(default=off) run benchmark per operation")
-
- # profile
- parser.add_argument(
- "--profile",
- action="store_true",
- dest="profile_on",
- default=False,
- help="(default=off) run profiling")
-
- # driverbin
- parser.add_argument(
- "--framework_driverbin",
- action="store",
- type=str,
- dest="framework_driverbin",
- help=
- "(default=../../Product/out/bin/tflite_run) runner for runnning framework tests")
- parser.add_argument(
- "--verification_driverbin",
- action="store",
- type=str,
- dest="verification_driverbin",
- help=
- "(default=../../Product/out/bin/nnapi_test) runner for runnning verification tests"
- )
- parser.add_argument(
- "--benchmark_driverbin",
- action="store",
- type=str,
- dest="benchmark_driverbin",
- help=
- "(default=../../Product/out/bin/tflite_benchmark) runner for runnning benchmark")
-
- # etc.
- parser.add_argument(
- "--runtestsh",
- action="store",
- type=str,
- dest="runtestsh",
- help=
- "(default=ARTIFACT_PATH/tests/framework/run_test.sh) run_test.sh with path where it is for framework test and verification"
- )
- parser.add_argument(
- "--unittestdir",
- action="store",
- type=str,
- dest="unittestdir",
- help=
- "(default=ARTIFACT_PATH/Product/out/unittest) directory that has unittest binaries for unit test"
- )
- parser.add_argument(
- "--ldlibrarypath",
- action="store",
- type=str,
- dest="ldlibrarypath",
- help=
- "(default=ARTIFACT_PATH/Product/out/lib) path that you want to include libraries")
- parser.add_argument(
- "--frameworktest_list_file",
- action="store",
- type=str,
- dest="frameworktest_list_file",
- help=
- "(default=ARTIFACT_PATH/tools/test_driver/pureacl_frameworktest_list.txt) filepath of model list for test"
- )
- parser.add_argument(
- "--reportdir",
- action="store",
- type=str,
- dest="reportdir",
- help="(default=ARTIFACT_PATH/report) directory to save report")
-
- # env
- parser.add_argument(
- "--usennapi",
- action="store_true",
- dest="usennapi_on",
- default=True,
- help="(default=on) declare USE_NNAPI=1")
- parser.add_argument(
- "--nousennapi",
- action="store_false",
- dest="usennapi_on",
- help="(default=off) declare nothing about USE_NNAPI")
- parser.add_argument(
- "--acl_envon",
- action="store_true",
- dest="aclenv_on",
- default=False,
- help="(default=off) declare envs for ACL")
-
- options = parser.parse_args()
- return options
-
-
-def run_unittest(options):
- cmd = "{artifactpath}/tools/test_driver/run_unittest.sh \
- --reportdir={reportdir} \
- --unittestdir={unittestdir}".format(
- artifactpath=options.artifactpath,
- reportdir=options.reportdir,
- unittestdir=options.unittestdir)
- if options.unittestall_on:
- cmd += " --runall"
- os.system(cmd)
-
-
-def run_frameworktest(options):
- if type(options.framework_driverbin) is not str:
- options.framework_driverbin = options.artifactpath + "/Product/out/bin/tflite_run"
- if (os.path.exists(options.framework_driverbin) == False):
- print("Cannot find {driverbin}".format(driverbin=options.framework_driverbin))
- sys.exit(1)
-
- cmd = "{artifactpath}/tools/test_driver/run_frameworktest.sh \
- --runtestsh={runtestsh} \
- --driverbin={driverbin} \
- --reportdir={reportdir} \
- --tapname=framework_test.tap \
- --logname=framework_test.log \
- --testname='Frameworktest'".format(
- runtestsh=options.runtestsh,
- driverbin=options.framework_driverbin,
- reportdir=options.reportdir,
- artifactpath=options.artifactpath)
- os.system(cmd)
-
-
-def run_verification(options):
- if type(options.verification_driverbin) is not str:
- options.verification_driverbin = options.artifactpath + "/Product/out/bin/nnapi_test"
- if (os.path.exists(options.verification_driverbin) == False):
- print("Cannot find {driverbin}".format(
- driverbin=options.verification_driverbin))
- sys.exit(1)
-
- cmd = "{artifactpath}/tools/test_driver/run_frameworktest.sh \
- --runtestsh={runtestsh} \
- --driverbin={driverbin} \
- --reportdir={reportdir} \
- --tapname=verification_test.tap \
- --logname=verification_test.log \
- --testname='Verification'".format(
- runtestsh=options.runtestsh,
- driverbin=options.verification_driverbin,
- reportdir=options.reportdir,
- artifactpath=options.artifactpath)
- os.system(cmd)
-
-
-def run_benchmark(options):
- if type(options.benchmark_driverbin) is not str:
- options.benchmark_driverbin = options.artifactpath + "/Product/out/bin/tflite_benchmark"
- if (os.path.exists(options.benchmark_driverbin) == False):
- print("Cannot find {driverbin}".format(driverbin=options.benchmark_driverbin))
- sys.exit(1)
-
- cmd = "{artifactpath}/tools/test_driver/run_benchmark.sh \
- --runtestsh={runtestsh} \
- --driverbin={driverbin} \
- --reportdir={reportdir}/benchmark".format(
- runtestsh=options.runtestsh,
- driverbin=options.benchmark_driverbin,
- reportdir=options.reportdir,
- artifactpath=options.artifactpath)
- os.system(cmd)
-
-
-def run_benchmarkop(options):
- if type(options.benchmark_driverbin) is not str:
- options.benchmark_driverbin = options.artifactpath + "/Product/out/bin/tflite_benchmark"
- if (os.path.exists(options.benchmark_driverbin) == False):
- print("Cannot find {driverbin}".format(driverbin=options.benchmark_driverbin))
- sys.exit(1)
-
- cmd = "{artifactpath}/tools/test_driver/run_benchmark_op.sh \
- --runtestsh={runtestsh} \
- --driverbin={driverbin} \
- --reportdir={reportdir}/benchmark_op \
- --modelfilepath={artifactpath}/tests/framework \
- --frameworktest_list_file={frameworktest_list_file}".format(
- runtestsh=options.runtestsh,
- driverbin=options.benchmark_driverbin,
- artifactpath=options.artifactpath,
- reportdir=options.reportdir,
- frameworktest_list_file=options.frameworktest_list_file)
- os.system(cmd)
-
-
-def run_benchmarkacl(options):
- cmd = "{artifactpath}/tools/test_driver/run_benchmark_acl.sh \
- --reportdir={reportdir}/benchmark \
- --bindir={artifactpath}/Product/out/bin".format(
- reportdir=options.reportdir, artifactpath=options.artifactpath)
- os.system(cmd)
-
-
-def make_json_for_benchmark_result(options):
- cmd = "source {artifactpath}/tools/test_driver/print_to_json.sh && ".format(
- artifactpath=options.artifactpath)
- if options.benchmarkop_on:
- cmd += "print_to_json {artifactpath}/report/benchmark_op \
- {reportdir} \"benchmark_op_result.json\"".format(
- reportdir=options.reportdir, artifactpath=options.artifactpath)
- else:
- cmd += "print_to_json {artifactpath}/report/benchmark \
- {reportdir} \"benchmark_result.json\"".format(
- reportdir=options.reportdir, artifactpath=options.artifactpath)
- sp = subprocess.Popen(["/bin/bash", "-i", "-c", cmd])
- sp.communicate()
-
-
-def run_profile(options):
- # FIXME: These driver and tflite test are set temporarily. Fix these to support flexibility
- driver_bin = options.artifactpath + "/Product/out/bin/tflite_run"
- tflite_test = options.artifactpath + "/tests/framework/cache/inceptionv3/inception_module/inception_test.tflite"
-
- # TODO: Enable operf to set directory where sample data puts on
- shutil.rmtree("oprofile_data", ignore_errors=True)
-
- print("")
- print("============================================")
- cmd = "operf -g {driver_bin} {tflite_test}".format(
- driver_bin=driver_bin, tflite_test=tflite_test)
- os.system(cmd)
- print("============================================")
- print("")
-
-
-def main():
- options = get_parsed_options()
-
- alltest_on = True
- if True in [
- options.unittest_on, options.frameworktest_on, options.verification_on,
- options.benchmark_on, options.benchmarkacl_on, options.benchmarkop_on,
- options.profile_on
- ]:
- alltest_on = False
-
- # artifactpath
- if os.path.isdir(options.artifactpath) and os.path.isdir(
- options.artifactpath + "/tests") and os.path.isdir(options.artifactpath +
- "/Product"):
- options.artifactpath = os.path.abspath(options.artifactpath)
- else:
- print("Pass on with proper arifactpath")
- sys.exit(1)
-
- # run_test.sh
- if type(options.runtestsh) is not str or options.runtestsh == "":
- options.runtestsh = options.artifactpath + "/tests/framework/run_test.sh"
-
- if (os.path.exists(options.runtestsh) == False):
- print("Cannot find {runtestsh}".format(runtestsh=options.runtestsh))
- sys.exit(1)
-
- # unittest dir
- if type(options.unittestdir) is not str or options.unittestdir == "":
- options.unittestdir = options.artifactpath + "/Product/out/unittest"
-
- # LD_LIBRARY_PATH
- if type(options.ldlibrarypath) is not str or options.ldlibrarypath == "":
- options.ldlibrarypath = options.artifactpath + "/Product/out/lib"
-
- # report dir
- if type(options.reportdir) is not str or options.reportdir == "":
- options.reportdir = options.artifactpath + "/report"
-
- # set LD_LIBRARY_PATH
- os.environ["LD_LIBRARY_PATH"] = options.ldlibrarypath
-
- # set USE_NNAPI
- if options.usennapi_on == True:
- os.environ["USE_NNAPI"] = "1"
-
- # set acl
- if options.aclenv_on:
- common.switch_nnfw_kernel_env("acl")
-
- # unittest
- if alltest_on or options.unittest_on:
- run_unittest(options)
-
- # frameworktest
- if options.frameworktest_on:
- run_frameworktest(options)
-
- # verification
- if alltest_on or options.verification_on:
- run_verification(options)
-
- # benchmark
- if options.benchmark_on:
- run_benchmark(options)
-
- # benchmark_acl
- if options.benchmarkacl_on:
- run_benchmarkacl(options)
-
- # benchmark_op
- if options.benchmarkop_on:
- run_benchmarkop(options)
-
- # make json file for benchmark result on ci
- if options.benchmark_on or options.benchmarkacl_on or options.benchmarkop_on:
- make_json_for_benchmark_result(options)
-
- # run profile
- if options.profile_on:
- run_profile(options)
-
-
-if __name__ == "__main__":
- main()
diff --git a/tools/test_driver/run_benchmark.sh b/tools/test_driver/run_benchmark.sh
deleted file mode 100755
index a1a0c2fa2..000000000
--- a/tools/test_driver/run_benchmark.sh
+++ /dev/null
@@ -1,146 +0,0 @@
-#!/bin/bash
-#
-# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-MY_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
-
-source $MY_PATH/common.sh
-
-BENCHMARK_RUN_TEST_SH=
-BENCHMARK_DRIVER_BIN=
-BENCHMARK_REPORT_DIR=
-BENCHMARK_MODELS_FILE=
-BENCHMARK_MODEL_LIST="inceptionv3/inception_nonslim inceptionv3/inception_slim mobilenet"
-
-function Usage()
-{
- # TODO: Fill this
- echo "Usage: LD_LIBRARY_PATH=Product/out/lib ./$0 --reportdir=report"
-}
-
-for i in "$@"
-do
- case $i in
- -h|--help|help)
- Usage
- exit 1
- ;;
- --runtestsh=*)
- BENCHMARK_RUN_TEST_SH=${i#*=}
- ;;
- --driverbin=*)
- BENCHMARK_DRIVER_BIN=${i#*=}
- ;;
- --reportdir=*)
- BENCHMARK_REPORT_DIR=${i#*=}
- BENCHMARK_MODELS_FILE=$BENCHMARK_REPORT_DIR/benchmark_models.txt
- ;;
- esac
- shift
-done
-
-function get_result_of_benchmark_test()
-{
- local RUN_TEST_SH=$1
- local DRIVER_BIN=$2
- local MODEL=$3
- local LOG_FILE=$4
-
- local RET=0
- $RUN_TEST_SH --driverbin=$DRIVER_BIN $MODEL > $LOG_FILE 2>&1
- RET=$?
- if [[ $RET -ne 0 ]]; then
- echo "Testing $MODEL aborted... exit code: $RET"
- exit $RET
- fi
-
- local RESULT=`grep -E '^Mean:' $LOG_FILE | sed -e 's/ms//g' | awk '{print $2}'`
- echo "$RESULT"
-}
-
-function print_result_of_benchmark_test()
-{
- local NAME=$1
- local RESULT=$2
- local RESULT_FILE=$3
-
- echo "$NAME $RESULT" > $RESULT_FILE
-}
-
-function run_benchmark_test()
-{
- local DRIVER_BIN=$BENCHMARK_DRIVER_BIN
- local LOG_FILE=
- local RESULT_FILE=
- local RESULT=
- local REPORT_MODEL_DIR=
-
- export COUNT=5
- echo "============================================"
- local i=0
- for MODEL in $BENCHMARK_MODEL_LIST; do
- echo "Benchmark test with `basename $DRIVER_BIN` & `echo $MODEL`"
- echo $MODEL >> $BENCHMARK_MODELS_FILE
-
- REPORT_MODEL_DIR=$BENCHMARK_REPORT_DIR/$MODEL
- mkdir -p $REPORT_MODEL_DIR
-
- # TFLite+CPU
- LOG_FILE=$REPORT_MODEL_DIR/tflite_cpu.txt
- RESULT_FILE=$REPORT_MODEL_DIR/tflite_cpu.result
- echo -n "TFLite + CPU................... "
- unset USE_NNAPI
- RESULT=$(get_result_of_benchmark_test $BENCHMARK_RUN_TEST_SH $DRIVER_BIN $MODEL $LOG_FILE)
- echo "$RESULT ms"
- print_result_of_benchmark_test "TFLite_CPU" $RESULT $RESULT_FILE
-
- # TFLite+NNAPI(CPU fallback)
- LOG_FILE=$REPORT_MODEL_DIR/tflite_nnapi_cpu.txt
- RESULT_FILE=$REPORT_MODEL_DIR/tflite_nnapi_cpu.result
- echo -n "TFLite + NNAPI(CPU)............ "
- export USE_NNAPI=1
- RESULT=$(get_result_of_benchmark_test $BENCHMARK_RUN_TEST_SH $DRIVER_BIN $MODEL $LOG_FILE)
- echo "$RESULT ms"
- print_result_of_benchmark_test "TFLite_NNAPI_CPU" $RESULT $RESULT_FILE
-
- # TFLite+NNAPI(ACL)
- LOG_FILE=$REPORT_MODEL_DIR/tflite_nnapi_acl.txt
- RESULT_FILE=$REPORT_MODEL_DIR/tflite_nnapi_acl.result
- echo -n "TFLite + NNAPI(ACL)............ "
- switch_nnfw_kernel_env "ON" "acl"
- RESULT=$(get_result_of_benchmark_test $BENCHMARK_RUN_TEST_SH $DRIVER_BIN $MODEL $LOG_FILE)
- echo "$RESULT ms"
- print_result_of_benchmark_test "TFLite_NNAPI_ACL" $RESULT $RESULT_FILE
- unset USE_NNAPI
- switch_nnfw_kernel_env "OFF"
-
- if [[ $i -ne $(echo $BENCHMARK_MODEL_LIST | wc -w)-1 ]]; then
- echo ""
- fi
- i=$((i+1))
- done
- echo "============================================"
- unset COUNT
-}
-
-if [ ! -e "$BENCHMARK_REPORT_DIR" ]; then
- mkdir -p $BENCHMARK_REPORT_DIR
-fi
-
-rm -rf $BENCHMARK_MODELS_FILE
-
-echo ""
-run_benchmark_test
-echo ""
diff --git a/tools/test_driver/run_benchmark_acl.sh b/tools/test_driver/run_benchmark_acl.sh
deleted file mode 100755
index c6a643baa..000000000
--- a/tools/test_driver/run_benchmark_acl.sh
+++ /dev/null
@@ -1,113 +0,0 @@
-#!/bin/bash
-#
-# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-MY_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
-
-source $MY_PATH/common.sh
-
-BENCHMARKACL_BIN_DIR=
-BENCHMARKACL_REPORT_DIR=
-BENCHMARKACL_MODELS_FILE=
-BENCHMARKACL_MODEL_LIST="inceptionv3/inception_nonslim inceptionv3/inception_slim"
-
-function Usage()
-{
- # TODO: Fill this
- echo "Usage: LD_LIBRARY_PATH=Product/out/lib ./$0 --reportdir=report"
-}
-
-for i in "$@"
-do
- case $i in
- -h|--help|help)
- Usage
- exit 1
- ;;
- --reportdir=*)
- BENCHMARKACL_REPORT_DIR=${i#*=}
- BENCHMARKACL_MODELS_FILE=$BENCHMARKACL_REPORT_DIR/benchmarkacl_models.txt
- ;;
- --bindir=*)
- BENCHMARKACL_BIN_DIR=${i#*=}
- ;;
- esac
- shift
-done
-
-function run_benchmark_acl()
-{
- local REPORT_DIR=$BENCHMARKACL_REPORT_DIR
- local DRIVER_DIR=$BENCHMARKACL_BIN_DIR
- local LOG_FILE=""
- local RESULT_FILE=""
- local RESULT=""
- local RET=0
-
- export COUNT=5
- echo "============================================"
- local i=0
- for BENCHMARK_ACL_BIN in $(ls $DRIVER_DIR/benchmark_*); do
- local BENCHMARK_ACL_BIN_BASENAME=$(basename $BENCHMARK_ACL_BIN)
- mkdir -p $REPORT_DIR/$BENCHMARK_ACL_BIN_BASENAME
- echo "Benchmark/acl test by $BENCHMARK_ACL_BIN_BASENAME"
- echo $BENCHMARK_ACL_BIN_BASENAME >> $BENCHMARKACL_MODELS_FILE
-
- # ACL(NEON)
- LOG_FILE=$REPORT_DIR/$BENCHMARK_ACL_BIN_BASENAME/acl_neon.txt
- RESULT_FILE=$REPORT_DIR/$BENCHMARK_ACL_BIN_BASENAME/acl_neon.result
- echo -n "ACL(NEON)...... "
- $BENCHMARK_ACL_BIN 0 > $LOG_FILE 2>&1
- RET=$?
- if [[ $RET -ne 0 ]]; then
- echo "aborted... exit code: $RET"
- exit $RET
- fi
- RESULT=`grep -E '^Mean:' $LOG_FILE | sed -e 's/ms//g' | awk '{print $2}'`
- echo "$RESULT ms"
- echo "ACL(NEON)" $RESULT > $RESULT_FILE
-
- # ACL(OpenCL)
- LOG_FILE=$REPORT_DIR/$BENCHMARK_ACL_BIN_BASENAME/acl_opencl.txt
- RESULT_FILE=$REPORT_DIR/$BENCHMARK_ACL_BIN_BASENAME/acl_opencl.result
- echo -n "ACL(OpenCL).... "
- $BENCHMARK_ACL_BIN 1 > $LOG_FILE 2>&1
- RET=$?
- if [[ $RET -ne 0 ]]; then
- echo "aborted... exit code: $RET"
- exit $RET
- fi
- RESULT=`grep -E '^Mean:' $LOG_FILE | sed -e 's/ms//g' | awk '{print $2}'`
- echo "$RESULT ms"
- echo "ACL(OpenCL)" $RESULT > $RESULT_FILE
-
- if [[ $i -ne $(ls $DRIVER_DIR/benchmark_* | wc -w)-1 ]]; then
- echo ""
- fi
- i=$((i+1))
- done
- echo "============================================"
- unset COUNT
-}
-
-if [ ! -e "$BENCHMARKACL_REPORT_DIR" ]; then
- mkdir -p $BENCHMARKACL_REPORT_DIR
-fi
-
-rm -rf $BENCHMARKACL_MODELS_FILE
-
-echo ""
-run_benchmark_acl
-echo ""
diff --git a/tools/test_driver/run_benchmark_op.sh b/tools/test_driver/run_benchmark_op.sh
deleted file mode 100755
index 8ff80a45b..000000000
--- a/tools/test_driver/run_benchmark_op.sh
+++ /dev/null
@@ -1,209 +0,0 @@
-#!/bin/bash
-#
-# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-MY_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
-NNFW_HOME="$(dirname $(dirname ${MY_PATH}))"
-source $MY_PATH/common.sh
-
-BENCHMARK_RUN_TEST_SH=
-BENCHMARK_DRIVER_BIN=
-BENCHMARK_REPORT_DIR=
-BENCHMARK_MODELS_FILE=
-BENCHMARK_MODEL_LIST=
-MODEL_CACHE_ROOT_PATH=
-MODEL_TEST_ROOT_PATH=
-PURE_ACL_RT_LIB_PATH=
-PURE_LD_LIBRARY_PATH=
-ORIGIN_LD_LIBRARY_PATH=
-PURE_ACL_RT_ENV_FILE=$MY_PATH/benchmark_op_list.txt
-
-function Usage()
-{
- # TODO: Fill this
- echo "Usage: LD_LIBRARY_PATH=Product/out/lib ./$0 --reportdir=report"
-}
-
-for i in "$@"
-do
- case $i in
- -h|--help|help)
- Usage
- exit 1
- ;;
- --runtestsh=*)
- BENCHMARK_RUN_TEST_SH=${i#*=}
- ;;
- --driverbin=*)
- BENCHMARK_DRIVER_BIN=${i#*=}
- ;;
- --reportdir=*)
- BENCHMARK_REPORT_DIR=${i#*=}
- BENCHMARK_MODELS_FILE=$BENCHMARK_REPORT_DIR/benchmark_op_models.txt
- ;;
- --modelfilepath=*)
- TEST_LIST_PATH=${i#*=}
- MODEL_CACHE_ROOT_PATH=$TEST_LIST_PATH/cache
- MODEL_TEST_ROOT_PATH=$TEST_LIST_PATH/tests
- ;;
- --frameworktest_list_file=*)
- FRAMEWORKTEST_LIST_FILE=${i#*=}
- ;;
- esac
- shift
-done
-
-function get_result_of_benchmark_test()
-{
- local RUN_TEST_SH=$1
- local DRIVER_BIN=$2
- local MODEL=$3
- local LOG_FILE=$4
- local PUREACL_LD_LIBRARY_PATH=$5
-
- local RET=0
- $RUN_TEST_SH --driverbin=$DRIVER_BIN --ldlibrarypath=$PUREACL_LD_LIBRARY_PATH $MODEL > $LOG_FILE 2>&1
- RET=$?
- if [[ $RET -ne 0 ]]; then
- echo "Testing $MODEL aborted... exit code: $RET"
- exit $RET
- fi
-
- local RESULT=`grep -E '^Mean:' $LOG_FILE | sed -e 's/ms//g' | awk '{print $2}'`
- echo "$RESULT"
-}
-
-function print_result_of_benchmark_test()
-{
- local NAME=$1
- local RESULT=$2
- local RESULT_FILE=$3
- echo "$NAME $RESULT" > $RESULT_FILE
-}
-
-function get_benchmark_op_list()
-{
- if [ ! -z "$FRAMEWORKTEST_LIST_FILE" ]; then
- BENCHMARK_MODEL_LIST=$(cat "${FRAMEWORKTEST_LIST_FILE}")
- else
- BENCHMARK_MODEL_LIST=$(cat "${PURE_ACL_RT_ENV_FILE}")
- fi
- echo "BENCHMARK_MODEL_LIST=> $BENCHMARK_MODEL_LIST"
-}
-
-function run_benchmark_test()
-{
- local DRIVER_BIN=$BENCHMARK_DRIVER_BIN
- local LOG_FILE=
- local RESULT_FILE=
- local RESULT=
- local REPORT_MODEL_DIR=
-
- export COUNT=5
- echo "============================================"
- local i=0
- for MODEL in $BENCHMARK_MODEL_LIST; do
- STATUS="enabled"
- source $MODEL_TEST_ROOT_PATH/$MODEL/config.sh
-
- LOWER_STATUS="$(echo $STATUS | awk '{print tolower($0)}')"
- if [ "$LOWER_STATUS" == "disabled" ]; then
- echo ""
- echo "Skip $MODEL"
- continue
- fi
-
- echo "Benchmark test with `basename $DRIVER_BIN` & `echo $MODEL`"
- echo $MODEL >> $BENCHMARK_MODELS_FILE
-
- REPORT_MODEL_DIR=$BENCHMARK_REPORT_DIR/$MODEL
- mkdir -p $REPORT_MODEL_DIR
-
- # TFLite(CPU fallback)
- LOG_FILE=$REPORT_MODEL_DIR/tflite_cpu_op.txt
- RESULT_FILE=$REPORT_MODEL_DIR/tflite_cpu_op.result
- echo -n "TFLite(CPU fallback)................... "
- unset USE_NNAPI
- RESULT=$(get_result_of_benchmark_test $BENCHMARK_RUN_TEST_SH $DRIVER_BIN $MODEL $LOG_FILE)
- echo "$RESULT ms"
- print_result_of_benchmark_test "TFLite_CPU" $RESULT $RESULT_FILE
-
- # TFLite+NNRuntime(CPU fallback)
- LOG_FILE=$REPORT_MODEL_DIR/tflite_nnrt_cpu_op.txt
- RESULT_FILE=$REPORT_MODEL_DIR/tflite_nnrt_cpu_op.result
- echo -n "TFLite + NNRuntime(CPU fallback)............ "
- export USE_NNAPI=1
- RESULT=$(get_result_of_benchmark_test $BENCHMARK_RUN_TEST_SH $DRIVER_BIN $MODEL $LOG_FILE)
- echo "$RESULT ms"
- print_result_of_benchmark_test "TFLite_NNRT_CPU" $RESULT $RESULT_FILE
-
- # TFLite+NNRuntime+ACL-Neon
- LOG_FILE=$REPORT_MODEL_DIR/tflite_nnrt_acl_neon_op.txt
- RESULT_FILE=$REPORT_MODEL_DIR/tflite_nnrt_acl_neon_op.result
- echo -n "TFLite + NNRuntime + ACL-Neon............ "
- switch_nnfw_kernel_env "ON" "neon"
- RESULT=$(get_result_of_benchmark_test $BENCHMARK_RUN_TEST_SH $DRIVER_BIN $MODEL $LOG_FILE)
- echo "$RESULT ms"
- print_result_of_benchmark_test "TFLite_NNRT_ACL-NEON" $RESULT $RESULT_FILE
- switch_nnfw_kernel_env "OFF"
-
- # TFLite+NNRuntime+ACL-OpenCL
- LOG_FILE=$REPORT_MODEL_DIR/tflite_nnrt_acl_opencl_op.txt
- RESULT_FILE=$REPORT_MODEL_DIR/tflite_nnrt_acl_opencl_op.result
- echo -n "TFLite + NNRuntime + ACL-OpenCL............ "
- switch_nnfw_kernel_env "ON" "acl"
- RESULT=$(get_result_of_benchmark_test $BENCHMARK_RUN_TEST_SH $DRIVER_BIN $MODEL $LOG_FILE)
- echo "$RESULT ms"
- print_result_of_benchmark_test "TFLite_NNRT_ACL-OPENCL" $RESULT $RESULT_FILE
- switch_nnfw_kernel_env "OFF"
-
- # TFLite+PureACLRuntime+ACL-OpenCL
- if [ ! -d "$PURE_ACL_RT_LIB_PATH" ]; then
- echo "Skip $MODEL in Pure ACL Runtime "
- continue
- fi
- LOG_FILE=$REPORT_MODEL_DIR/tflite_pureaclrt_acl_opencl_op.txt
- RESULT_FILE=$REPORT_MODEL_DIR/tflite_pureaclrt_acl_opencl_op.result
- echo -n "TFLite + PureACLRuntime + ACL-OpenCL............ "
- RESULT=$(get_result_of_benchmark_test $BENCHMARK_RUN_TEST_SH $DRIVER_BIN $MODEL $LOG_FILE $PURE_ACL_RT_LIB_PATH)
- echo "$RESULT ms"
- print_result_of_benchmark_test "TFLite_PUREACLRT_ACL-OPENCL" $RESULT $RESULT_FILE
- unset USE_NNAPI
-
- if [[ $i -ne $(echo $BENCHMARK_MODEL_LIST | wc -w)-1 ]]; then
- echo ""
- fi
- i=$((i+1))
- done
- unset USE_NNAPI
- unset COUNT
- echo "============================================"
-}
-
-if [ ! -e "$BENCHMARK_REPORT_DIR" ]; then
- mkdir -p $BENCHMARK_REPORT_DIR
-fi
-
-if [ -z "$PURE_ACL_RT_LIB_PATH" ]; then
- PURE_ACL_RT_LIB_PATH="$NNFW_HOME/Product/out/lib/pureacl"
-fi
-
-get_benchmark_op_list
-
-rm -rf $BENCHMARK_MODELS_FILE
-
-echo ""
-run_benchmark_test
-echo ""
diff --git a/tools/test_driver/run_benchmark_tflite_model.in b/tools/test_driver/run_benchmark_tflite_model.in
deleted file mode 100644
index 1003ecc13..000000000
--- a/tools/test_driver/run_benchmark_tflite_model.in
+++ /dev/null
@@ -1 +0,0 @@
-MODELS/inception_nonslim --input_layer=Mul --input_layer_shape=1,299,299,3 --num_threads=1 --num_runs=1
diff --git a/tools/test_driver/run_benchmark_tflite_model.sh b/tools/test_driver/run_benchmark_tflite_model.sh
deleted file mode 100755
index 50a2a5fb3..000000000
--- a/tools/test_driver/run_benchmark_tflite_model.sh
+++ /dev/null
@@ -1,125 +0,0 @@
-#!/bin/bash
-#
-# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
-NNFW_DIR="$(dirname "$(dirname "${SCRIPT_DIR}")")"
-REPORT_DIR="$NNFW_DIR/report/tflite_benchmark_model"
-MODEL_ROOT="$NNFW_DIR/tests/framework/tests"
-LD_LIBRARY_PATH="$NNFW_DIR/Product/out/lib"
-
-RUN_TEST=$NNFW_DIR/tests/framework/run_test.sh
-MODEL_IN=${BASH_SOURCE[0]%.sh}.in
-BENCHMARK_BIN=$NNFW_DIR/Product/out/bin/tflite_benchmark_model
-MODEL_NAMES=
-MODEL_PARAMS=
-
-source $SCRIPT_DIR/common.sh
-
-usage()
-{
- echo
- echo "Usage: LD_LIBRARY_PATH=Product/out/lib $(basename ${BASH_SOURCE[0]}) --reportdir=report --modelroot=modelroot"
- echo
-}
-
-parse_args()
-{
- for i in "$@"; do
- case $i in
- -h|--help|help)
- usage
- exit 1
- ;;
- --reportdir=*)
- REPORT_DIR=${i#*=}
- ;;
- --modelroot=*)
- MODEL_ROOT=${i#*=}
- ;;
- esac
- shift
- done
-}
-
-load_input()
-{
- mapfile -t MODEL_NAMES < <(cut -f1 "${MODEL_IN}")
- mapfile -t MODEL_PARAMS < <(cut -f2- "${MODEL_IN}")
- if [ "${#MODEL_NAMES[@]}" -eq 0 ]; then
- echo "No model is found. Please check ${MODEL_IN} is correct."
- exit 1
- fi
-}
-
-download_models()
-{
- $RUN_TEST --download=on $MODEL_NAMES
-}
-
-run_benchmarks()
-{
- echo
- echo "Running benchmarks:"
- echo "======================"
-
- for (( i=0; i< ${#MODEL_NAMES[@]}; i++)); do
- MODEL_NAME=${MODEL_NAMES[i]}
- MODEL_PATH=$(find $NNFW_DIR/tests/framework/cache/$MODEL_NAME/ -name "*.tflite")
- MODEL_PARAM=${MODEL_PARAMS[$i]}
-
- echo "$MODEL_NAME"
-
- local REPORT_MODEL_DIR=$REPORT_DIR/$MODEL_NAME
- mkdir -p $REPORT_MODEL_DIR
-
- local OUT_FILE
-
- # TFLite Interpreter
- OUT_FILE=$REPORT_MODEL_DIR/tflite_interpreter.out
- echo
- echo "{ // TFLite Interpreter"
- LD_LIBRARY_PATH=$LD_LIBRARY_PATH $BENCHMARK_BIN --graph=$MODEL_PATH $MODEL_PARAM --use_nnapi=false 2> >(tee $OUT_FILE)
- echo "} // TFLite Interpreter"
-
- # TFLite PureACL (CL)
- OUT_FILE=$REPORT_MODEL_DIR/tflite_pureacl_cl.out
- echo
- echo "{ // TFLite PureACL(CL)"
- LD_LIBRARY_PATH=$LD_LIBRARY_PATH $BENCHMARK_BIN --graph=$MODEL_PATH $MODEL_PARAM --use_nnapi=true 2> >(tee $OUT_FILE)
- echo "} // TFLite_PureACL(CL)"
- done
-}
-
-# for debug
-print_vars()
-{
- echo SCRIPT_DIR=$SCRIPT_DIR
- echo NNFW_DIR=$NNFW_DIR
- echo RUN_TEST=$RUN_TEST
- echo MODEL_IN=$MODEL_IN
- echo BENCHMARK_BIN=$BENCHMARK_BIN
- echo REPORT_DIR=$REPORT_DIR
- echo MODEL_ROOT=$MODEL_ROOT
-}
-
-if [ ! -e "$REPORT_DIR" ]; then
- mkdir -p $REPORT_DIR
-fi
-
-parse_args $@
-load_input
-download_models
-run_benchmarks
diff --git a/tools/test_driver/run_frameworktest.sh b/tools/test_driver/run_frameworktest.sh
deleted file mode 100755
index 343fd0292..000000000
--- a/tools/test_driver/run_frameworktest.sh
+++ /dev/null
@@ -1,95 +0,0 @@
-#!/bin/bash
-#
-# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-FWTEST_RUN_TEST_SH=
-FWTEST_DRIVER_BIN=
-FWTEST_REPORT_DIR=
-FWTEST_TAP_NAME=
-FWTEST_LOG_NAME=
-FWTEST_TEST_NAME=
-
-function Usage()
-{
- # TODO: Fill this
- echo "Usage: LD_LIBRARY_PATH=Product/out/lib ./$0 --reportdir=report"
-}
-
-for i in "$@"
-do
- case $i in
- -h|--help|help)
- Usage
- exit 1
- ;;
- --runtestsh=*)
- FWTEST_RUN_TEST_SH=${i#*=}
- ;;
- --driverbin=*)
- FWTEST_DRIVER_BIN=${i#*=}
- ;;
- --reportdir=*)
- FWTEST_REPORT_DIR=${i#*=}
- ;;
- --tapname=*)
- FWTEST_TAP_NAME=${i#*=}
- ;;
- --logname=*)
- FWTEST_LOG_NAME=${i#*=}
- ;;
- --testname=*)
- FWTEST_TEST_NAME=${i#*=}
- ;;
- --frameworktest_list_file=*)
- FRAMEWORKTEST_LIST_FILE=${i#*=}
- ;;
- esac
- shift
-done
-
-# TODO: handle exceptions for params
-
-if [ ! -e "$FWTEST_REPORT_DIR" ]; then
- mkdir -p $FWTEST_REPORT_DIR
-fi
-
-echo ""
-echo "============================================"
-echo "$FWTEST_TEST_NAME with $(basename $FWTEST_DRIVER_BIN) ..."
-
-if [ ! -z "$FRAMEWORKTEST_LIST_FILE" ]; then
- MODELLIST=$(cat "${FRAMEWORKTEST_LIST_FILE}")
-fi
-
-$FWTEST_RUN_TEST_SH --driverbin=$FWTEST_DRIVER_BIN \
- --reportdir=$FWTEST_REPORT_DIR \
- --tapname=$FWTEST_TAP_NAME \
- ${MODELLIST:-} \
- > $FWTEST_REPORT_DIR/$FWTEST_LOG_NAME 2>&1
-FWTEST_RESULT=$?
-if [[ $FWTEST_RESULT -ne 0 ]]; then
- echo ""
- cat $FWTEST_REPORT_DIR/$FWTEST_TAP_NAME
- echo ""
- echo "$FWTEST_TEST_NAME failed... exit code: $FWTEST_RESULT"
- echo "============================================"
- echo ""
- exit $FWTEST_RESULT
-fi
-
-echo ""
-cat $FWTEST_REPORT_DIR/$FWTEST_TAP_NAME
-echo "============================================"
-echo ""
diff --git a/tools/test_driver/run_unittest.sh b/tools/test_driver/run_unittest.sh
deleted file mode 100755
index abf3194ad..000000000
--- a/tools/test_driver/run_unittest.sh
+++ /dev/null
@@ -1,109 +0,0 @@
-#!/bin/bash
-#
-# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-UNITTEST_REPORT_DIR=
-UNITTEST_TEST_DIR=
-UNITTEST_RESULT=0
-UNITTEST_RUN_ALL=""
-
-function Usage()
-{
- # TODO: Fill this
- echo "Usage: LD_LIBRARY_PATH=Product/out/lib ./$0 --reportdir=report --unittestdir=Product/out/bin"
-}
-
-get_gtest_option()
-{
- local output_option="--gtest_output=xml:$UNITTEST_REPORT_DIR/$TEST_BIN.xml"
- local filter_option
- if [ -r "$UNITTEST_TEST_DIR/$TEST_BIN.skip" ]; then
- filter_option="--gtest_filter=-$(grep -v '#' "$UNITTEST_TEST_DIR/$TEST_BIN.skip" | tr '\n' ':')"
- fi
- echo "$output_option $filter_option"
-}
-
-for i in "$@"
-do
- case $i in
- -h|--help|help)
- Usage
- exit 1
- ;;
- --reportdir=*)
- UNITTEST_REPORT_DIR=${i#*=}
- ;;
- --unittestdir=*)
- UNITTEST_TEST_DIR=${i#*=}
- ;;
- --runall)
- UNITTEST_RUN_ALL="true"
- esac
- shift
-done
-
-# TODO: handle exceptions for params
-
-if [ ! -e "$UNITTEST_REPORT_DIR" ]; then
- mkdir -p $UNITTEST_REPORT_DIR
-fi
-
-echo ""
-echo "============================================"
-echo "Unittest start"
-echo "============================================"
-
-num_unittest=0
-for TEST_BIN in `ls $UNITTEST_TEST_DIR --hide=*.skip`; do
- num_unittest=$((num_unittest+1))
- echo "============================================"
- echo "Starting set $num_unittest: $TEST_BIN..."
- echo "============================================"
- TEMP_UNITTEST_RESULT=0
-
- if [ "$UNITTEST_RUN_ALL" == "true" ]; then
- for TEST_LIST_VERBOSE_LINE in $($UNITTEST_TEST_DIR/$TEST_BIN --gtest_list_tests); do
- if [[ $TEST_LIST_VERBOSE_LINE == *\. ]]; then
- TEST_LIST_CATEGORY=$TEST_LIST_VERBOSE_LINE
- else
- TEST_LIST_ITEM="$TEST_LIST_CATEGORY""$TEST_LIST_VERBOSE_LINE"
- $UNITTEST_TEST_DIR/$TEST_BIN --gtest_filter=$TEST_LIST_ITEM --gtest_output="xml:$UNITTEST_REPORT_DIR/$TEST_LIST_ITEM.xml"
- fi
- done
- else
- $UNITTEST_TEST_DIR/$TEST_BIN $(get_gtest_option)
- TEMP_UNITTEST_RESULT=$?
- fi
-
- if [[ $TEMP_UNITTEST_RESULT -ne 0 ]]; then
- UNITTEST_RESULT=$TEMP_UNITTEST_RESULT
- echo "$TEST_BIN failed... return code: $TEMP_UNITTEST_RESULT"
- fi
- echo "============================================"
- echo "Finishing set $num_unittest: $TEST_BIN..."
- echo "============================================"
-done
-
-if [[ $UNITTEST_RESULT -ne 0 ]]; then
- echo "============================================"
- echo "Failed unit test... exit code: $UNITTEST_RESULT"
- echo "============================================"
- exit $UNITTEST_RESULT
-fi
-
-echo "============================================"
-echo "Completed total $num_unittest set of unittest"
-echo "Unittest end"
-echo "============================================"
diff --git a/tools/test_driver/test_driver.sh b/tools/test_driver/test_driver.sh
deleted file mode 100755
index 72be65dc1..000000000
--- a/tools/test_driver/test_driver.sh
+++ /dev/null
@@ -1,329 +0,0 @@
-#!/bin/bash
-#
-# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-set -e
-# NOTE: Supposed that this script would be executed with an artifact path.
-# The artifact path has tests/(test suite) and Product/
-# Reference this PR(https://github.sec.samsung.net/STAR/nnfw/pull/375).
-
-function Usage()
-{
- echo "Usage: ./$0 --artifactpath=. # run all tests"
- echo "Usage: ./$0 --artifactpath=/home/dragon/nnfw --frameworktest --verification --benchmark # run fw test & verfication and benchmark"
- echo ""
- echo "--artifactpath - (default={test_driver.sh's path}/../../) it should contain tests/ and Product/"
- echo ""
- echo "Following options are needed when you want to tests of specific types. If you don't pass any one, unittest and verification will be run"
- echo "--unittest - (default=on) run unit test"
- echo "--unittestall - (default=off) run all unit test without skip, overrite --unittest option"
- echo "--frameworktest - (default=off) run framework test"
- echo "--verification - (default=on) run verification"
- echo "--frameworktest_list_file - filepath of model list for test"
- echo ""
- echo "Following option is only needed when you want to test benchmark."
- echo "--benchmark_acl - (default=off) run benchmark-acl"
- echo "--benchmark - (default=off) run benchmark"
- echo "--benchmark_op - (default=off) run benchmark per operation"
- echo "--benchmark_tflite_model - (default=off) run tflite_benchmark_model"
- echo ""
- echo "Following option is used for profiling."
- echo "--profile - (default=off) run operf"
- echo ""
- echo "etc."
- echo "--framework_driverbin - (default=../../Product/out/bin/tflite_run) runner for runnning framework tests"
- echo "--verification_driverbin - (default=../../Product/out/bin/nnapi_test) runner for runnning verification tests"
- echo "--benchmark_driverbin - (default=../../Product/out/bin/tflite_benchmark) runner for runnning benchmark"
- echo "--runtestsh - (default=\$ARTIFACT_PATH/tests/framework/run_test.sh) run_test.sh with path where it is for framework test and verification"
- echo "--unittestdir - (default=\$ARTIFACT_PATH/Product/out/unittest) directory that has unittest binaries for unit test"
- echo ""
- echo "--ldlibrarypath - (default=\$ARTIFACT_PATH/Product/out/lib) path that you want to include libraries"
- echo "--usennapi - (default=on) declare USE_NNAPI=1"
- echo "--nousennapi - (default=off) declare nothing about USE_NNAPI"
- echo "--acl_envon - (default=off) declare envs for ACL"
- echo "--reportdir - (default=\$ARTIFACT_PATH/report) directory to save report"
- echo ""
-}
-
-TEST_DRIVER_DIR="$( cd "$( dirname "${BASH_SOURCE}" )" && pwd )"
-ARTIFACT_PATH="$TEST_DRIVER_DIR/../../"
-FRAMEWORK_DRIVER_BIN=""
-VERIFICATION_DRIVER_BIN=""
-BENCHMARK_DRIVER_BIN=""
-RUN_TEST_SH=""
-UNIT_TEST_DIR=""
-LD_LIBRARY_PATH_IN_SHELL=""
-USE_NNAPI="USE_NNAPI=1"
-ALLTEST_ON="true"
-UNITTEST_ON="false"
-UNITTESTALL_ON="false"
-FRAMEWORKTEST_ON="false"
-VERIFICATION_ON="false"
-BENCHMARK_ON="false"
-BENCHMARK_OP_ON="false"
-BENCHMARK_TFLITE_MODEL_ON="false"
-BENCHMARK_ACL_ON="false"
-ACL_ENV_ON="false"
-PROFILE_ON="false"
-REPORT_DIR=""
-
-for i in "$@"
-do
- case $i in
- -h|--help|help)
- Usage
- exit 1
- ;;
- --artifactpath=*)
- ARTIFACT_PATH=${i#*=}
- ;;
- --framework_driverbin=*)
- FRAMEWORK_DRIVER_BIN=${i#*=}
- ;;
- --verification_driverbin=*)
- VERIFICATION_DRIVER_BIN=${i#*=}
- ;;
- --benchmark_driverbin=*)
- BENCHMARK_DRIVER_BIN=${i#*=}
- ;;
- --runtestsh=*)
- RUN_TEST_SH=${i#*=}
- ;;
- --unittestdir=*)
- UNIT_TEST_DIR=${i#*=}
- ;;
- --ldlibrarypath=*)
- LD_LIBRARY_PATH_IN_SHELL=${i#*=}
- ;;
- --usennapi)
- USE_NNAPI="USE_NNAPI=1"
- ;;
- --nousennapi)
- USE_NNAPI=""
- ;;
- --unittest)
- ALLTEST_ON="false"
- UNITTEST_ON="true"
- ;;
- --unittestall)
- ALLTEST_ON="false"
- UNITTEST_ON="true"
- UNITTESTALL_ON="true"
- ;;
- --frameworktest)
- ALLTEST_ON="false"
- FRAMEWORKTEST_ON="true"
- ;;
- --frameworktest_list_file=*)
- FRAMEWORKTEST_LIST_FILE=$PWD/${i#*=}
- if [ ! -e "$FRAMEWORKTEST_LIST_FILE" ]; then
- echo "Pass on with proper frameworktest_list_file"
- exit 1
- fi
- ;;
- --verification)
- ALLTEST_ON="false"
- VERIFICATION_ON="true"
- ;;
- --benchmark)
- ALLTEST_ON="false"
- BENCHMARK_ON="true"
- ;;
- --benchmark_op)
- ALLTEST_ON="false"
- BENCHMARK_OP_ON="true"
- ;;
- --benchmark_tflite_model)
- ALLTEST_ON="false"
- BENCHMARK_TFLITE_MODEL_ON="true"
- ;;
- --benchmark_acl)
- ALLTEST_ON="false"
- BENCHMARK_ACL_ON="true"
- ;;
- --acl_envon)
- ACL_ENV_ON="true"
- ;;
- --profile)
- ALLTEST_ON="false"
- PROFILE_ON="true"
- ;;
- --reportdir=*)
- REPORT_DIR=${i#*=}
- ;;
- *)
- # Be careful that others params are handled as $ARTIFACT_PATH
- ARTIFACT_PATH="$i"
- ;;
- esac
- shift
-done
-
-ARTIFACT_PATH="$(readlink -f $ARTIFACT_PATH)"
-
-if [ -z "$RUN_TEST_SH" ]; then
- RUN_TEST_SH=$ARTIFACT_PATH/tests/framework/run_test.sh
-fi
-
-if [ ! -e "$RUN_TEST_SH" ]; then
- echo "Cannot find $RUN_TEST_SH"
- exit 1
-fi
-
-if [ -z "$UNIT_TEST_DIR" ]; then
- UNIT_TEST_DIR=$ARTIFACT_PATH/Product/out/unittest
-fi
-
-if [ -z "$REPORT_DIR" ]; then
- REPORT_DIR=$ARTIFACT_PATH/report
-fi
-
-if [ -z "$LD_LIBRARY_PATH_IN_SHELL" ]; then
- LD_LIBRARY_PATH="$ARTIFACT_PATH/Product/out/lib:$LD_LIBRARY_PATH"
-else
- LD_LIBRARY_PATH="$LD_LIBRARY_PATH_IN_SHELL:$LD_LIBRARY_PATH"
-fi
-
-# Set env
-export LD_LIBRARY_PATH=$LD_LIBRARY_PATH
-if [ -n "$USE_NNAPI" ]; then
- export "$USE_NNAPI"
-fi
-
-source $TEST_DRIVER_DIR/common.sh
-
-if [ "$ACL_ENV_ON" == "true" ]; then
- switch_nnfw_kernel_env "ON" "acl"
-fi
-
-# Run unittest in each part such as Runtime, ACL
-if [ "$ALLTEST_ON" == "true" ] || [ "$UNITTEST_ON" == "true" ]; then
- if [ "$UNITTESTALL_ON" == "true" ]; then
- $TEST_DRIVER_DIR/run_unittest.sh \
- --reportdir=$REPORT_DIR \
- --unittestdir=$UNIT_TEST_DIR \
- --runall
- else
- $TEST_DRIVER_DIR/run_unittest.sh \
- --reportdir=$REPORT_DIR \
- --unittestdir=$UNIT_TEST_DIR
- fi
-fi
-
-# Run tflite_run with various tflite models
-if [ "$FRAMEWORKTEST_ON" == "true" ]; then
- if [ -z "$FRAMEWORK_DRIVER_BIN" ]; then
- FRAMEWORK_DRIVER_BIN=$ARTIFACT_PATH/Product/out/bin/tflite_run
- fi
-
- $TEST_DRIVER_DIR/run_frameworktest.sh \
- --runtestsh=$RUN_TEST_SH \
- --driverbin=$FRAMEWORK_DRIVER_BIN \
- --reportdir=$REPORT_DIR \
- --tapname=framework_test.tap \
- --logname=framework_test.log \
- --testname="Frameworktest" \
- --frameworktest_list_file=${FRAMEWORKTEST_LIST_FILE:-}
-fi
-
-# Run nnapi_test with various tflite models
-if [ "$ALLTEST_ON" == "true" ] || [ "$VERIFICATION_ON" == "true" ]; then
- if [ -z "$VERIFICATION_DRIVER_BIN" ]; then
- VERIFICATION_DRIVER_BIN=$ARTIFACT_PATH/Product/out/bin/nnapi_test
- fi
-
- # verification uses the same script as frameworktest does
- $TEST_DRIVER_DIR/run_frameworktest.sh \
- --runtestsh=$RUN_TEST_SH \
- --driverbin=$VERIFICATION_DRIVER_BIN \
- --reportdir=$REPORT_DIR \
- --tapname=verification_test.tap \
- --logname=verification_test.log \
- --testname="Verification" \
- --frameworktest_list_file=${FRAMEWORKTEST_LIST_FILE:-}
-fi
-
-# Run tflite_benchmark with tflite models
-if [ "$BENCHMARK_ON" == "true" ]; then
- if [ -z "$BENCHMARK_DRIVER_BIN" ]; then
- DRIVER_BIN=$ARTIFACT_PATH/Product/out/bin/tflite_benchmark
- else
- DRIVER_BIN=$BENCHMARK_DRIVER_BIN
- fi
-
- $TEST_DRIVER_DIR/run_benchmark.sh \
- --runtestsh=$RUN_TEST_SH \
- --driverbin=$DRIVER_BIN \
- --reportdir=$REPORT_DIR/benchmark
-fi
-
-# Run tflite_benchmark from a list of tflite models.
-# Each model has only one operator.
-if [ "$BENCHMARK_OP_ON" == "true" ]; then
- if [ -z "$BENCHMARK_DRIVER_BIN" ]; then
- DRIVER_BIN=$ARTIFACT_PATH/Product/out/bin/tflite_benchmark
- else
- DRIVER_BIN=$BENCHMARK_DRIVER_BIN
- fi
-
- $TEST_DRIVER_DIR/run_benchmark_op.sh \
- --runtestsh=$RUN_TEST_SH \
- --driverbin=$DRIVER_BIN \
- --reportdir=$REPORT_DIR/benchmark_op \
- --modelfilepath=$ARTIFACT_PATH/tests/framework \
- --frameworktest_list_file=${FRAMEWORKTEST_LIST_FILE:-}
-fi
-
-# Run benchmark/acl/benchmark_googlenet, mobilenet and inception_v3
-if [ "$BENCHMARK_ACL_ON" == "true" ]; then
- $TEST_DRIVER_DIR/run_benchmark_acl.sh \
- --reportdir=$AREPORT_DIR/benchmark \
- --bindir=$ARTIFACT_PATH/Product/out/bin
-fi
-
-# Make json file. Actually, this process is only needed on CI. That's why it is in test_driver.sh.
-if [ "$BENCHMARK_ON" == "true" ] || [ "$BENCHMARK_ACL_ON" == "true" ] || [ "$BENCHMARK_OP_ON" == "true" ]; then
- # functions to fill json with benchmark results
- source $ARTIFACT_PATH/tools/test_driver/print_to_json.sh
- if [ "$BENCHMARK_OP_ON" == "true" ]; then
- print_to_json $REPORT_DIR/benchmark_op $REPORT_DIR "benchmark_op_result.json"
- else
- print_to_json $REPORT_DIR/benchmark $REPORT_DIR "benchmark_result.json"
- fi
-fi
-
-# Run tflite_benchmark_model (= per-operation profiling tool).
-# Each model can contain arbitrary number of operators.
-if [ "$BENCHMARK_TFLITE_MODEL_ON" == "true" ]; then
- $TEST_DRIVER_DIR/run_benchmark_tflite_model.sh \
- --reportdir=$REPORT_DIR/benchmark_tflite_model \
- --modelroot=$ARTIFACT_PATH/tests/framework/tests
-fi
-
-# Run profiling
-if [ "$PROFILE_ON" == "true" ]; then
- # FIXME: These driver and tflite test are set temporarily. Fix these to support flexibility
- DRIVER_BIN=$ARTIFACT_PATH/Product/out/bin/tflite_run
- TFLITE_TEST=$ARTIFACT_PATH/tests/framework/cache/inceptionv3/inception_module/inception_test.tflite
-
- # TODO: Enable operf to set directory where sample data puts on
- rm -rf oprofile_data
-
- echo ""
- echo "============================================"
- operf -g $DRIVER_BIN $TFLITE_TEST
- echo "============================================"
- echo ""
-fi
diff --git a/tools/tflite_benchmark/CMakeLists.txt b/tools/tflite_benchmark/CMakeLists.txt
deleted file mode 100644
index 72ee5d3f9..000000000
--- a/tools/tflite_benchmark/CMakeLists.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-list(APPEND SOURCES "src/tflite_benchmark.cc")
-
-add_executable(tflite_benchmark ${SOURCES})
-target_link_libraries(tflite_benchmark tensorflow-lite ${LIB_PTHREAD} dl nnfw_util nnfw_support_tflite)
-install(TARGETS tflite_benchmark DESTINATION bin)
diff --git a/tools/tflite_benchmark/src/tflite_benchmark.cc b/tools/tflite_benchmark/src/tflite_benchmark.cc
deleted file mode 100644
index ba2e62883..000000000
--- a/tools/tflite_benchmark/src/tflite_benchmark.cc
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "support/tflite/kernels/register.h"
-#include "tensorflow/contrib/lite/model.h"
-
-#include "support/tflite/Assert.h"
-#include "support/tflite/Session.h"
-#include "support/tflite/InterpreterSession.h"
-#include "support/tflite/NNAPISession.h"
-#include "support/tflite/Diff.h"
-#include "util/tensor/IndexIterator.h"
-
-#include <boost/accumulators/accumulators.hpp>
-#include <boost/accumulators/statistics/stats.hpp>
-#include <boost/accumulators/statistics/min.hpp>
-#include <boost/accumulators/statistics/max.hpp>
-#include <boost/accumulators/statistics/mean.hpp>
-
-#include <iostream>
-
-#include "util/environment.h"
-#include "util/benchmark.h"
-
-using namespace tflite;
-using namespace tflite::ops::builtin;
-
-void help(std::ostream &out, const int argc, char **argv)
-{
- std::string cmd = argv[0];
- auto pos = cmd.find_last_of("/");
- if (pos != std::string::npos)
- cmd = cmd.substr(pos + 1);
-
- out << "use:" << std::endl << cmd << " <model file name>" << std::endl;
-}
-
-bool checkParams(const int argc, char **argv)
-{
- if (argc < 2)
- {
- help(std::cerr, argc, argv);
- return false;
- }
- return true;
-}
-
-int main(const int argc, char **argv)
-{
-
- if (!checkParams(argc, argv))
- {
- return -1;
- }
-
- const auto filename = argv[1];
-
- const bool use_nnapi = nnfw::util::get_env_bool("USE_NNAPI");
- const auto thread_count = nnfw::util::get_env_int("THREAD", -1);
-
- std::cout << "Num threads: " << thread_count << std::endl;
- if (use_nnapi)
- {
- std::cout << "Use NNAPI" << std::endl;
- }
-
- StderrReporter error_reporter;
-
- auto model = FlatBufferModel::BuildFromFile(filename, &error_reporter);
- if (model == nullptr)
- {
- std::cerr << "Cannot create model" << std::endl;
- return -1;
- }
-
- BuiltinOpResolver resolver;
-
- InterpreterBuilder builder(*model, resolver);
-
- std::unique_ptr<Interpreter> interpreter;
-
- TFLITE_ENSURE(builder(&interpreter));
-
- // Show inputs
- for (uint32_t n = 0; n < interpreter->inputs().size(); ++n)
- {
- // TODO Print shape
- auto tensor_id = interpreter->inputs().at(n);
- auto tensor_ptr = interpreter->tensor(tensor_id);
-
- std::cout << "Input #" << n << ":" << std::endl;
- std::cout << " Name: " << tensor_ptr->name << std::endl;
- }
-
- // Show outputs
- for (uint32_t n = 0; n < interpreter->outputs().size(); ++n)
- {
- // TODO Print shape
- auto tensor_id = interpreter->outputs().at(n);
- auto tensor_ptr = interpreter->tensor(tensor_id);
-
- std::cout << "Output #" << n << ":" << std::endl;
- std::cout << " Name: " << tensor_ptr->name << std::endl;
- }
-
- interpreter->SetNumThreads(thread_count);
-
- std::shared_ptr<nnfw::support::tflite::Session> sess;
-
- if (use_nnapi)
- {
- sess = std::make_shared<nnfw::support::tflite::NNAPISession>(interpreter.get());
- }
- else
- {
- sess = std::make_shared<nnfw::support::tflite::InterpreterSession>(interpreter.get());
- }
-
- //
- // Warming-up
- //
- for (uint32_t n = 0; n < 3; ++n)
- {
- std::chrono::milliseconds elapsed(0);
-
- sess->prepare();
-
- for (const auto &id : interpreter->inputs())
- {
- TfLiteTensor *tensor = interpreter->tensor(id);
- if (tensor->type == kTfLiteInt32)
- {
- // Generate singed 32-bit integer (s32) input
- auto tensor_view = nnfw::support::tflite::TensorView<int32_t>::make(*interpreter, id);
-
- int32_t value = 0;
-
- nnfw::util::tensor::iterate(tensor_view.shape())
- << [&](const nnfw::util::tensor::Index &ind) {
- // TODO Generate random values
- // Gather operation: index should be within input coverage.
- tensor_view.at(ind) = value;
- value++;
- };
- }
- else if (tensor->type == kTfLiteUInt8)
- {
- // Generate unsigned 8-bit integer input
- auto tensor_view = nnfw::support::tflite::TensorView<uint8_t>::make(*interpreter, id);
-
- uint8_t value = 0;
-
- nnfw::util::tensor::iterate(tensor_view.shape())
- << [&](const nnfw::util::tensor::Index &ind) {
- // TODO Generate random values
- tensor_view.at(ind) = value;
- value = (value + 1) & 0xFF;
- };
- }
- else
- {
- assert(tensor->type == kTfLiteFloat32);
-
- const int seed = 1; /* TODO Add an option for seed value */
- RandomGenerator randgen{seed, 0.0f, 0.2f};
- const float *end = reinterpret_cast<const float *>(tensor->data.raw_const + tensor->bytes);
- for (float *ptr = tensor->data.f; ptr < end; ptr++)
- {
- *ptr = randgen.generate<float>();
- }
- }
- }
-
- nnfw::util::benchmark::measure(elapsed) << [&](void) {
- if (!sess->run())
- {
- assert(0 && "run failed");
- }
- };
- sess->teardown();
-
- std::cout << "Warming-up " << n << ": " << elapsed.count() << "ms" << std::endl;
- }
-
- //
- // Measure
- //
- const auto cnt = nnfw::util::get_env_int("COUNT", 1);
-
- using namespace boost::accumulators;
-
- accumulator_set<double, stats<tag::mean, tag::min, tag::max>> acc;
-
- for (int n = 0; n < cnt; ++n)
- {
- std::chrono::milliseconds elapsed(0);
-
- sess->prepare();
- nnfw::util::benchmark::measure(elapsed) << [&](void) {
- if (!sess->run())
- {
- assert(0 && "run failed");
- }
- };
- sess->teardown();
-
- acc(elapsed.count());
-
- std::cout << "Iteration " << n << ": " << elapsed.count() << "ms" << std::endl;
- }
-
- std::cout << "--------" << std::endl;
- std::cout << "Min: " << min(acc) << "ms" << std::endl;
- std::cout << "Max: " << max(acc) << "ms" << std::endl;
- std::cout << "Mean: " << mean(acc) << "ms" << std::endl;
-
- return 0;
-}
diff --git a/tools/tflite_benchmark_model/.FORMATDENY b/tools/tflite_benchmark_model/.FORMATDENY
deleted file mode 100644
index e69de29bb..000000000
--- a/tools/tflite_benchmark_model/.FORMATDENY
+++ /dev/null
diff --git a/tools/tflite_benchmark_model/CMakeLists.txt b/tools/tflite_benchmark_model/CMakeLists.txt
deleted file mode 100644
index d52690460..000000000
--- a/tools/tflite_benchmark_model/CMakeLists.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-file(GLOB_RECURSE SOURCES "*.cc")
-
-add_executable(tflite_benchmark_model ${SOURCES})
-target_compile_definitions(tflite_benchmark_model PUBLIC "TFLITE_PROFILING_ENABLED")
-target_link_libraries(tflite_benchmark_model tensorflow-lite ${LIB_PTHREAD} dl nnfw_util nnfw_support_tflite)
-install(TARGETS tflite_benchmark_model DESTINATION bin)
diff --git a/tools/tflite_benchmark_model/README.md b/tools/tflite_benchmark_model/README.md
deleted file mode 100644
index 93769305b..000000000
--- a/tools/tflite_benchmark_model/README.md
+++ /dev/null
@@ -1,209 +0,0 @@
-# TFLite Model Benchmark Tool
-
-## Description
-
-A simple C++ binary to benchmark a TFLite model and its individual operators,
-both on desktop machines and on Android. The binary takes a TFLite model,
-generates random inputs and then repeatedly runs the model for specified number
-of runs. Aggregrate latency statistics are reported after running the benchmark.
-
-The instructions below are for running the binary on Desktop and Android,
-for iOS please use the
-[iOS benchmark app] (https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/lite/tools/benchmark/ios).
-
-## Parameters
-
-The binary takes the following required parameters:
-
-* `graph`: `string` \
- The path to the TFLite model file.
-* `input_layer`: `string` \
- The name of the input layer, this is typically the first layer of the model.
-* `input_layer_shape`: `string` \
- The shape of the input layer. This is a comma separated string of the shape
- of tensor of input layer.
-
-and the following optional parameters:
-
-* `num_threads`: `int` (default=1) \
- The number of threads to use for running TFLite interpreter.
-* `warmup_runs`: `int` (default=1) \
- The number of warmup runs to do before starting the benchmark.
-* `run_delay`: `float` (default=-1.0) \
- The delay in seconds between subsequent benchmark runs. Non-positive values
- mean use no delay.
-* `use_nnapi`: `bool` (default=false) \
- Whether to use [Android NNAPI] (https://developer.android.com/ndk/guides/neuralnetworks/).
- This API is available on recent Android devices.
-
-## 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 \
- --config=android_arm \
- --cxxopt='--std=c++11' \
- tensorflow/contrib/lite/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/contrib/lite/tools/benchmark/benchmark_model /data/local/tmp
-```
-
-(3) Make the binary executable.
-
-```
-adb shell chmod +x /data/local/tmp/benchmark_model
-```
-
-(4) Push the compute graph that you need to test. For example:
-
-```
-adb push mobilenet_quant_v1_224.tflite /data/local/tmp
-```
-
-(5) Run the benchmark. For example:
-
-```
-adb shell /data/local/tmp/benchmark_model \
- --graph=/data/local/tmp/mobilenet_quant_v1_224.tflite \
- --input_layer="input" \
- --input_layer_shape="1,224,224,3" \
- --num_threads=4
-```
-
-### On desktop:
-(1) build the binary
-
-```
-bazel build -c opt tensorflow/contrib/lite/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/contrib/lite/tools/benchmark/benchmark_model \
- --graph=mobilenet_quant_v1_224.tflite \
- --input_layer="Placeholder" \
- --input_layer_shape="1,224,224,3" \
- --num_threads=4
-```
-
-The MobileNet graph used as an example here may be downloaded from
-https://storage.googleapis.com/download.tensorflow.org/models/tflite/mobilenet_v1_224_android_quant_2017_11_08.zip
-
-
-## Reducing variance between runs on Android.
-
-Most modern Android phones use [ARM big.LITTLE](https://en.wikipedia.org/wiki/ARM_big.LITTLE)
-architecture where some cores are more power hungry but faster than other cores.
-When running benchmarks on these phones there can be significant variance
-between different runs of the benchmark. One way to reduce variance between runs
-is to set the [CPU affinity](https://en.wikipedia.org/wiki/Processor_affinity)
-before running the benchmark. On Android this can be done using the `taskset`
-command.
-E.g. for running the benchmark on big cores on Pixel 2 with a single thread one
-can use the following command:
-
-```
-adb shell tasket f0 /data/local/tmp/benchmark_model \
- --graph=/data/local/tmp/mobilenet_quant_v1_224.tflite \
- --input_layer="input" \
- --input_layer_shape="1,224,224,3" \
- --num_threads=1
-```
-
-where `f0` is the affinity mask for big cores on Pixel 2.
-Note: The affinity mask varies with the device.
-
-## Profiling model operators
-The benchmark model binary also allows you to profile operators and give execution times of each operator. To do this,
-compile the binary with a compiler flag that enables profiling to be compiled in. Pass **--copt=-DTFLITE_PROFILING_ENABLED**
-to compile benchmark with profiling support.
-For example, to compile with profiling support on Android, add this flag to the previous command:
-
-```
-bazel build -c opt \
- --config=android_arm \
- --cxxopt='--std=c++11' \
- --copt=-DTFLITE_PROFILING_ENABLED \
- tensorflow/contrib/lite/tools/benchmark:benchmark_model
-```
-This compiles TFLite with profiling enabled, now you can run the benchmark binary like before. The binary will produce detailed statistics for each operation similar to those shown below:
-
-```
-
-============================== Run Order ==============================
- [node type] [start] [first] [avg ms] [%] [cdf%] [mem KB] [times called] [Name]
- CONV_2D 0.000 4.269 4.269 0.107% 0.107% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_0/Relu6]
- DEPTHWISE_CONV_2D 4.270 2.150 2.150 0.054% 0.161% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_1_depthwise/Relu6]
- CONV_2D 6.421 6.107 6.107 0.153% 0.314% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_1_pointwise/Relu6]
- DEPTHWISE_CONV_2D 12.528 1.366 1.366 0.034% 0.348% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_2_depthwise/Relu6]
- CONV_2D 13.895 4.195 4.195 0.105% 0.454% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_2_pointwise/Relu6]
- DEPTHWISE_CONV_2D 18.091 1.260 1.260 0.032% 0.485% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_3_depthwise/Relu6]
- CONV_2D 19.352 6.652 6.652 0.167% 0.652% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_3_pointwise/Relu6]
- DEPTHWISE_CONV_2D 26.005 0.698 0.698 0.018% 0.670% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_4_depthwise/Relu6]
- CONV_2D 26.703 3.344 3.344 0.084% 0.754% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_4_pointwise/Relu6]
- DEPTHWISE_CONV_2D 30.047 0.646 0.646 0.016% 0.770% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_5_depthwise/Relu6]
- CONV_2D 30.694 5.800 5.800 0.145% 0.915% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_5_pointwise/Relu6]
- DEPTHWISE_CONV_2D 36.495 0.331 0.331 0.008% 0.924% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_6_depthwise/Relu6]
- CONV_2D 36.826 2.838 2.838 0.071% 0.995% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_6_pointwise/Relu6]
- DEPTHWISE_CONV_2D 39.665 0.439 0.439 0.011% 1.006% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_7_depthwise/Relu6]
- CONV_2D 40.105 5.293 5.293 0.133% 1.139% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_7_pointwise/Relu6]
- DEPTHWISE_CONV_2D 45.399 0.352 0.352 0.009% 1.147% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_8_depthwise/Relu6]
- CONV_2D 45.752 5.322 5.322 0.133% 1.281% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_8_pointwise/Relu6]
- DEPTHWISE_CONV_2D 51.075 0.357 0.357 0.009% 1.290% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_9_depthwise/Relu6]
- CONV_2D 51.432 5.693 5.693 0.143% 1.433% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_9_pointwise/Relu6]
- DEPTHWISE_CONV_2D 57.126 0.366 0.366 0.009% 1.442% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_10_depthwise/Relu6]
- CONV_2D 57.493 5.472 5.472 0.137% 1.579% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_10_pointwise/Relu6]
- DEPTHWISE_CONV_2D 62.966 0.364 0.364 0.009% 1.588% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_11_depthwise/Relu6]
- CONV_2D 63.330 5.404 5.404 0.136% 1.724% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_11_pointwise/Relu6]
- DEPTHWISE_CONV_2D 68.735 0.155 0.155 0.004% 1.728% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_12_depthwise/Relu6]
- CONV_2D 68.891 2.970 2.970 0.074% 1.802% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_12_pointwise/Relu6]
- DEPTHWISE_CONV_2D 71.862 0.206 0.206 0.005% 1.807% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_13_depthwise/Relu6]
- CONV_2D 72.069 5.888 5.888 0.148% 1.955% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_13_pointwise/Relu6]
- AVERAGE_POOL_2D 77.958 0.036 0.036 0.001% 1.956% 0.000 0 [MobilenetV1/Logits/AvgPool_1a/AvgPool]
- CONV_2D 77.994 1.445 1.445 0.036% 1.992% 0.000 0 [MobilenetV1/Logits/Conv2d_1c_1x1/BiasAdd]
- RESHAPE 79.440 0.002 0.002 0.000% 1.992% 0.000 0 [MobilenetV1/Predictions/Reshape]
- SOFTMAX 79.443 0.029 0.029 0.001% 1.993% 0.000 0 [MobilenetV1/Predictions/Softmax]
-
-============================== Top by Computation Time ==============================
- [node type] [start] [first] [avg ms] [%] [cdf%] [mem KB] [times called] [Name]
- CONV_2D 19.352 6.652 6.652 0.167% 0.167% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_3_pointwise/Relu6]
- CONV_2D 6.421 6.107 6.107 0.153% 0.320% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_1_pointwise/Relu6]
- CONV_2D 72.069 5.888 5.888 0.148% 0.468% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_13_pointwise/Relu6]
- CONV_2D 30.694 5.800 5.800 0.145% 0.613% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_5_pointwise/Relu6]
- CONV_2D 51.432 5.693 5.693 0.143% 0.756% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_9_pointwise/Relu6]
- CONV_2D 57.493 5.472 5.472 0.137% 0.893% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_10_pointwise/Relu6]
- CONV_2D 63.330 5.404 5.404 0.136% 1.029% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_11_pointwise/Relu6]
- CONV_2D 45.752 5.322 5.322 0.133% 1.162% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_8_pointwise/Relu6]
- CONV_2D 40.105 5.293 5.293 0.133% 1.295% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_7_pointwise/Relu6]
- CONV_2D 0.000 4.269 4.269 0.107% 1.402% 0.000 0 [MobilenetV1/MobilenetV1/Conv2d_0/Relu6]
-
-Number of nodes executed: 31
-============================== Summary by node type ==============================
- [Node type] [count] [avg ms] [avg %] [cdf %] [mem KB] [times called]
- CONV_2D 15 1.406 89.270% 89.270% 0.000 0
- DEPTHWISE_CONV_2D 13 0.169 10.730% 100.000% 0.000 0
- SOFTMAX 1 0.000 0.000% 100.000% 0.000 0
- RESHAPE 1 0.000 0.000% 100.000% 0.000 0
- AVERAGE_POOL_2D 1 0.000 0.000% 100.000% 0.000 0
-
-Timings (microseconds): count=50 first=79449 curr=81350 min=77385 max=88213 avg=79732 std=1929
-Memory (bytes): count=0
-31 nodes observed
-
-
-Average inference timings in us: Warmup: 83235, Init: 38467, no stats: 79760.9
-```
-
-
diff --git a/tools/tflite_benchmark_model/benchmark_main.cc b/tools/tflite_benchmark_model/benchmark_main.cc
deleted file mode 100644
index 7e4231c48..000000000
--- a/tools/tflite_benchmark_model/benchmark_main.cc
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-==============================================================================*/
-
-#include "benchmark_tflite_model.h"
-#include "logging.h"
-
-namespace nnfw {
-namespace benchmark {
-
-int Main(int argc, char** argv) {
-#ifdef TFLITE_CUSTOM_OPS_HEADER
- TFLITE_LOG(INFO) << "STARTING with custom ops!";
-#else
- TFLITE_LOG(INFO) << "STARTING!";
-#endif
- BenchmarkTfLiteModel benchmark;
- BenchmarkLoggingListener listener;
- benchmark.AddListener(&listener);
- benchmark.Run(argc, argv);
- return 0;
-}
-} // namespace benchmark
-} // namespace nnfw
-
-int main(int argc, char** argv) { return nnfw::benchmark::Main(argc, argv); }
diff --git a/tools/tflite_benchmark_model/benchmark_model.cc b/tools/tflite_benchmark_model/benchmark_model.cc
deleted file mode 100644
index 7869180bf..000000000
--- a/tools/tflite_benchmark_model/benchmark_model.cc
+++ /dev/null
@@ -1,175 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-==============================================================================*/
-
-#include "benchmark_model.h"
-
-#include <time.h>
-
-#include <iostream>
-#include <sstream>
-
-#include "tensorflow/contrib/lite/profiling/time.h"
-#include "logging.h"
-
-namespace {
-void SleepForSeconds(double sleep_seconds) {
- if (sleep_seconds <= 0.0) {
- return;
- }
- // Convert the run_delay string into a timespec.
- timespec req;
- req.tv_sec = static_cast<time_t>(sleep_seconds);
- req.tv_nsec = (sleep_seconds - req.tv_sec) * 1000000000;
- // If requested, sleep between runs for an arbitrary amount of time.
- // This can be helpful to determine the effect of mobile processor
- // scaling and thermal throttling.
-#ifdef PLATFORM_WINDOWS
- Sleep(sleep_seconds * 1000);
-#else
- nanosleep(&req, nullptr);
-#endif
-}
-
-} // namespace
-
-namespace nnfw {
-namespace benchmark {
-using tensorflow::Stat;
-
-BenchmarkParams BenchmarkModel::DefaultParams() {
- BenchmarkParams params;
- params.AddParam("num_runs", BenchmarkParam::Create<int32_t>(50));
- params.AddParam("run_delay", BenchmarkParam::Create<float>(-1.0f));
- params.AddParam("num_threads", BenchmarkParam::Create<int32_t>(1));
- params.AddParam("benchmark_name", BenchmarkParam::Create<std::string>(""));
- params.AddParam("output_prefix", BenchmarkParam::Create<std::string>(""));
- params.AddParam("warmup_runs", BenchmarkParam::Create<int32_t>(1));
- return params;
-}
-
-BenchmarkModel::BenchmarkModel() : params_(DefaultParams()) {}
-
-void BenchmarkLoggingListener::OnBenchmarkEnd(const BenchmarkResults &results) {
- auto inference_us = results.inference_time_us();
- auto init_us = results.startup_latency_us();
- auto warmup_us = results.warmup_time_us();
- TFLITE_LOG(INFO) << "Average inference timings in us: "
- << "Warmup: " << warmup_us.avg() << ", "
- << "Init: " << init_us << ", "
- << "no stats: " << inference_us.avg();
-}
-
-std::vector<Flag> BenchmarkModel::GetFlags() {
- return {
- CreateFlag<int32_t>("num_runs", &params_, "number of runs"),
- CreateFlag<float>("run_delay", &params_, "delay between runs in seconds"),
- CreateFlag<int32_t>("num_threads", &params_, "number of threads"),
- CreateFlag<std::string>("benchmark_name", &params_, "benchmark name"),
- CreateFlag<std::string>("output_prefix", &params_,
- "benchmark output prefix"),
- CreateFlag<int32_t>("warmup_runs", &params_,
- "how many runs to initialize model"),
- };
-}
-
-void BenchmarkModel::LogFlags() {
- TFLITE_LOG(INFO) << "Num runs: [" << params_.Get<int32_t>("num_runs") << "]";
- TFLITE_LOG(INFO) << "Inter-run delay (seconds): ["
- << params_.Get<float>("run_delay") << "]";
- TFLITE_LOG(INFO) << "Num threads: [" << params_.Get<int32_t>("num_threads")
- << "]";
- TFLITE_LOG(INFO) << "Benchmark name: ["
- << params_.Get<std::string>("benchmark_name") << "]";
- TFLITE_LOG(INFO) << "Output prefix: ["
- << params_.Get<std::string>("output_prefix") << "]";
- TFLITE_LOG(INFO) << "Warmup runs: [" << params_.Get<int32_t>("warmup_runs")
- << "]";
-}
-
-Stat<int64_t> BenchmarkModel::Run(int num_times, RunType run_type) {
- Stat<int64_t> run_stats;
- TFLITE_LOG(INFO) << "Running benchmark for " << num_times << " iterations ";
- for (int run = 0; run < num_times; run++) {
- listeners_.OnSingleRunStart(run_type);
- int64_t start_us = tflite::profiling::time::NowMicros();
- RunImpl();
- int64_t end_us = tflite::profiling::time::NowMicros();
- listeners_.OnSingleRunEnd();
-
- run_stats.UpdateStat(end_us - start_us);
- SleepForSeconds(params_.Get<float>("run_delay"));
- }
-
- std::stringstream stream;
- run_stats.OutputToStream(&stream);
- TFLITE_LOG(INFO) << stream.str() << std::endl;
-
- return run_stats;
-}
-
-void BenchmarkModel::Run(int argc, char **argv) {
- if (!ParseFlags(argc, argv)) {
- return;
- }
-
- LogFlags();
-
- listeners_.OnBenchmarkStart(params_);
- int64_t initialization_start_us = tflite::profiling::time::NowMicros();
- Init();
- int64_t initialization_end_us = tflite::profiling::time::NowMicros();
- int64_t startup_latency_us = initialization_end_us - initialization_start_us;
- TFLITE_LOG(INFO) << "Initialized session in " << startup_latency_us / 1e3
- << "ms";
-
- uint64_t input_bytes = ComputeInputBytes();
- Stat<int64_t> warmup_time_us =
- Run(params_.Get<int32_t>("warmup_runs"), WARMUP);
- Stat<int64_t> inference_time_us =
- Run(params_.Get<int32_t>("num_runs"), REGULAR);
- listeners_.OnBenchmarkEnd(
- {startup_latency_us, input_bytes, warmup_time_us, inference_time_us});
-}
-
-bool BenchmarkModel::ParseFlags(int argc, char **argv) {
- auto flag_list = GetFlags();
- const bool parse_result =
- Flags::Parse(&argc, const_cast<const char **>(argv), flag_list);
- if (!parse_result) {
- std::string usage = Flags::Usage(argv[0], flag_list);
- TFLITE_LOG(ERROR) << usage;
- return false;
- }
- return ValidateFlags();
-}
-
-} // namespace benchmark
-} // namespace nnfw
diff --git a/tools/tflite_benchmark_model/benchmark_model.h b/tools/tflite_benchmark_model/benchmark_model.h
deleted file mode 100644
index 5645e2910..000000000
--- a/tools/tflite_benchmark_model/benchmark_model.h
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-==============================================================================*/
-
-#ifndef __TFLITE_BENCHMARK_MODEL_BENCHMARK_MODEL_H__
-#define __TFLITE_BENCHMARK_MODEL_BENCHMARK_MODEL_H__
-
-#include <cmath>
-#include <limits>
-#include <ostream>
-#include <string>
-#include <unordered_set>
-#include <vector>
-
-#include "benchmark_params.h"
-#include "command_line_flags.h"
-#include "tensorflow/core/util/stats_calculator.h"
-
-namespace nnfw {
-namespace benchmark {
-
-enum RunType {
- WARMUP,
- REGULAR,
-};
-
-class BenchmarkResults {
- public:
- BenchmarkResults(int64_t startup_latency_us, uint64_t input_bytes,
- tensorflow::Stat<int64_t> warmup_time_us,
- tensorflow::Stat<int64_t> inference_time_us)
- : startup_latency_us_(startup_latency_us),
- input_bytes_(input_bytes),
- warmup_time_us_(warmup_time_us),
- inference_time_us_(inference_time_us) {}
-
- tensorflow::Stat<int64_t> inference_time_us() const {
- return inference_time_us_;
- }
- tensorflow::Stat<int64_t> warmup_time_us() const { return warmup_time_us_; }
- int64_t startup_latency_us() const { return startup_latency_us_; }
- uint64_t input_bytes() const { return input_bytes_; }
- double throughput_MB_per_second() const {
- double bytes_per_sec = (input_bytes_ * inference_time_us_.count() * 1e6) /
- inference_time_us_.sum();
- return bytes_per_sec / (1024.0 * 1024.0);
- }
-
- private:
- int64_t startup_latency_us_;
- uint64_t input_bytes_;
- tensorflow::Stat<int64_t> warmup_time_us_;
- tensorflow::Stat<int64_t> inference_time_us_;
-};
-
-class BenchmarkListener {
- public:
- virtual void OnBenchmarkStart(const BenchmarkParams& params) {}
- virtual void OnSingleRunStart(RunType runType) {}
- virtual void OnSingleRunEnd() {}
- virtual void OnBenchmarkEnd(const BenchmarkResults& results) {}
- virtual ~BenchmarkListener() {}
-};
-
-// A listener that forwards its method calls to a collection of listeners.
-class BenchmarkListeners : public BenchmarkListener {
- public:
- // Added a listener to the listener collection.
- // |listener| is not owned by the instance of |BenchmarkListeners|.
- // |listener| should not be null and should outlast the instance of
- // |BenchmarkListeners|.
- void AddListener(BenchmarkListener* listener) {
- listeners_.push_back(listener);
- }
-
- void OnBenchmarkStart(const BenchmarkParams& params) override {
- for (auto listener : listeners_) {
- listener->OnBenchmarkStart(params);
- }
- }
-
- void OnSingleRunStart(RunType runType) override {
- for (auto listener : listeners_) {
- listener->OnSingleRunStart(runType);
- }
- }
-
- void OnSingleRunEnd() override {
- for (auto listener : listeners_) {
- listener->OnSingleRunEnd();
- }
- }
-
- void OnBenchmarkEnd(const BenchmarkResults& results) override {
- for (auto listener : listeners_) {
- listener->OnBenchmarkEnd(results);
- }
- }
-
- ~BenchmarkListeners() {}
-
- private:
- // Use vector so listeners are invoked in the order they are added.
- std::vector<BenchmarkListener*> listeners_;
-};
-
-// Benchmark listener that just logs the results of benchmark run.
-class BenchmarkLoggingListener : public BenchmarkListener {
- void OnBenchmarkEnd(const BenchmarkResults& results) override;
-};
-
-template <typename T>
-Flag CreateFlag(const char* name, BenchmarkParams* params,
- const std::string& usage) {
- return Flag(name, [params, name](const T& val) { params->Set<T>(name, val); },
- params->Get<T>(name), usage);
-}
-
-// Benchmarks a model.
-//
-// Subclasses need to implement initialization and running of the model.
-// The results can be collected by adding BenchmarkListener(s).
-class BenchmarkModel {
- public:
- static BenchmarkParams DefaultParams();
- BenchmarkModel();
- BenchmarkModel(BenchmarkParams params) : params_(std::move(params)) {}
- virtual ~BenchmarkModel() {}
- bool ParseFlags(int argc, char** argv);
- virtual void Init() = 0;
- void Run(int argc, char** argv);
- void AddListener(BenchmarkListener* listener) {
- listeners_.AddListener(listener);
- }
-
- protected:
- virtual void LogFlags();
- virtual bool ValidateFlags() { return true; }
- virtual std::vector<Flag> GetFlags();
- virtual uint64_t ComputeInputBytes() = 0;
- virtual tensorflow::Stat<int64_t> Run(int num_times, RunType run_type);
- virtual void RunImpl() = 0;
- BenchmarkParams params_;
- BenchmarkListeners listeners_;
-};
-
-} // namespace benchmark
-} // namespace nnfw
-
-#endif //__TFLITE_BENCHMARK_MODEL_BENCHMARK_MODEL_H__
diff --git a/tools/tflite_benchmark_model/benchmark_params.cc b/tools/tflite_benchmark_model/benchmark_params.cc
deleted file mode 100644
index 7b667a442..000000000
--- a/tools/tflite_benchmark_model/benchmark_params.cc
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-==============================================================================*/
-
-#include "benchmark_params.h"
-
-#include <string>
-#include <unordered_map>
-#include <vector>
-
-#include "logging.h"
-
-namespace nnfw {
-namespace benchmark {
-
-void BenchmarkParam::AssertHasSameType(BenchmarkParam::ParamType a,
- BenchmarkParam::ParamType b) {
- TFLITE_BENCHMARK_CHECK(a == b) << "Type mismatch while accessing parameter.";
-}
-
-template <>
-BenchmarkParam::ParamType BenchmarkParam::GetValueType<int32_t>() {
- return BenchmarkParam::ParamType::TYPE_INT32;
-}
-
-template <>
-BenchmarkParam::ParamType BenchmarkParam::GetValueType<bool>() {
- return BenchmarkParam::ParamType::TYPE_BOOL;
-}
-
-template <>
-BenchmarkParam::ParamType BenchmarkParam::GetValueType<float>() {
- return BenchmarkParam::ParamType::TYPE_FLOAT;
-}
-
-template <>
-BenchmarkParam::ParamType BenchmarkParam::GetValueType<std::string>() {
- return BenchmarkParam::ParamType::TYPE_STRING;
-}
-
-void BenchmarkParams::AssertParamExists(const std::string& name) const {
- TFLITE_BENCHMARK_CHECK(HasParam(name)) << name << " was not found.";
-}
-
-} // namespace benchmark
-} // namespace nnfw
diff --git a/tools/tflite_benchmark_model/benchmark_params.h b/tools/tflite_benchmark_model/benchmark_params.h
deleted file mode 100644
index 1ac3f4af6..000000000
--- a/tools/tflite_benchmark_model/benchmark_params.h
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-==============================================================================*/
-
-#ifndef __TFLITE_BENCHMARK_MODEL_BENCHMARK_PARAMS_H__
-#define __TFLITE_BENCHMARK_MODEL_BENCHMARK_PARAMS_H__
-#include <memory>
-#include <string>
-#include <unordered_map>
-#include <vector>
-
-#include "logging.h"
-
-namespace nnfw {
-namespace benchmark {
-
-template <typename T>
-class TypedBenchmarkParam;
-
-class BenchmarkParam {
- protected:
- enum class ParamType { TYPE_INT32, TYPE_FLOAT, TYPE_BOOL, TYPE_STRING };
-
- public:
- template <typename T>
- static std::unique_ptr<BenchmarkParam> Create(const T& default_value) {
- return std::unique_ptr<BenchmarkParam>(
- new TypedBenchmarkParam<T>(default_value));
- }
-
- template <typename T>
- TypedBenchmarkParam<T>* AsTyped() {
- AssertHasSameType(GetValueType<T>(), type_);
- return static_cast<TypedBenchmarkParam<T>*>(this);
- }
- virtual ~BenchmarkParam() {}
- BenchmarkParam(ParamType type) : type_(type) {}
-
- private:
- static void AssertHasSameType(ParamType a, ParamType b);
- protected:
- template <typename T>
- static ParamType GetValueType();
-
- const ParamType type_;
-};
-
-template <typename T>
-class TypedBenchmarkParam : public BenchmarkParam {
- public:
- TypedBenchmarkParam(const T& value)
- : BenchmarkParam(GetValueType<T>()), value_(value) {}
- void Set(const T& value) { value_ = value; }
-
- T Get() { return value_; }
-
- private:
- T value_;
-};
-
-class BenchmarkParams {
- public:
- void AddParam(const std::string& name,
- std::unique_ptr<BenchmarkParam> value) {
- params_[name] = std::move(value);
- }
-
- bool HasParam(const std::string& name) const {
- return params_.find(name) != params_.end();
- }
-
- template <typename T>
- void Set(const std::string& name, const T& value) {
- AssertParamExists(name);
- params_.at(name)->AsTyped<T>()->Set(value);
- }
-
- template <typename T>
- T Get(const std::string& name) const {
- AssertParamExists(name);
- return params_.at(name)->AsTyped<T>()->Get();
- }
-
- private:
- void AssertParamExists(const std::string& name) const;
- std::unordered_map<std::string, std::unique_ptr<BenchmarkParam>> params_;
-};
-
-} // namespace benchmark
-} // namespace nnfw
-#endif // __TFLITE_BENCHMARK_MODEL_BENCHMARK_PARAMS_H__
diff --git a/tools/tflite_benchmark_model/benchmark_tflite_model.cc b/tools/tflite_benchmark_model/benchmark_tflite_model.cc
deleted file mode 100644
index d277795a3..000000000
--- a/tools/tflite_benchmark_model/benchmark_tflite_model.cc
+++ /dev/null
@@ -1,360 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-==============================================================================*/
-
-#include "benchmark_tflite_model.h"
-
-#include <cstdarg>
-#include <cstdlib>
-#include <iostream>
-#include <memory>
-#include <string>
-#include <unordered_set>
-#include <vector>
-
-#include "support/tflite/kernels/register.h"
-#include "tensorflow/contrib/lite/model.h"
-#include "tensorflow/contrib/lite/op_resolver.h"
-#include "tensorflow/contrib/lite/string_util.h"
-#include "logging.h"
-#include "util/profiling/profiling.h"
-#include "support/tflite/nnapi_delegate.h"
-
-#ifdef TFLITE_CUSTOM_OPS_HEADER
-void RegisterSelectedOps(::tflite::MutableOpResolver* resolver);
-#endif
-
-namespace nnfw {
-namespace benchmark {
-
-void ProfilingListener::SetInterpreter(tflite::Interpreter* interpreter) {
- TFLITE_BENCHMARK_CHECK(interpreter);
- interpreter_ = interpreter;
- interpreter_->SetProfiler(&profiler_);
-}
-
-void ProfilingListener::OnSingleRunStart(RunType run_type) {
- if (run_type == REGULAR) {
- profiler_.Reset();
- profiler_.StartProfiling();
- }
-}
-
-void ProfilingListener::OnBenchmarkEnd(const BenchmarkResults& results) {
- if (has_profiles_) {
- TFLITE_LOG(INFO) << summarizer_.GetOutputString();
- }
-}
-
-void ProfilingListener::OnSingleRunEnd() {
- profiler_.StopProfiling();
- auto profile_events = profiler_.GetProfileEvents();
- has_profiles_ = !profile_events.empty();
- summarizer_.ProcessProfiles(profile_events, *interpreter_);
-}
-
-namespace {
-
-std::vector<std::string> Split(const std::string& str, const char delim) {
- std::istringstream input(str);
- std::vector<std::string> results;
- std::string item;
- while (std::getline(input, item, delim)) {
- results.push_back(item);
- }
- return results;
-}
-
-template <typename T>
-bool SplitAndParse(const std::string& str, char delim, std::vector<T>* values) {
- std::istringstream input(str);
- bool first = true;
- while (!input.eof()) {
- if (!first) {
- char c;
- input >> c;
- if (c != delim) {
- return false;
- }
- } else {
- first = false;
- }
- T val;
- input >> val;
- if (!input.eof() && !input.good()) {
- return false;
- }
- values->push_back(val);
- }
- return true;
-}
-
-template <typename T>
-void FillRandomValue(T* ptr, const std::vector<int>& sizes,
- const std::function<T()>& random_func) {
- int num_elements = 1;
- for (int dim : sizes) {
- num_elements *= dim;
- }
- for (int i = 0; i < num_elements; ++i) {
- *ptr++ = random_func();
- }
-}
-
-void FillRandomString(tflite::DynamicBuffer* buffer,
- const std::vector<int>& sizes,
- const std::function<std::string()>& random_func) {
- int num_elements = 1;
- for (int dim : sizes) {
- num_elements *= dim;
- }
- for (int i = 0; i < num_elements; ++i) {
- auto str = random_func();
- buffer->AddString(str.data(), str.length());
- }
-}
-
-bool PopulateInputLayerInfo(
- const std::string& names_string, const std::string& shapes_string,
- std::vector<BenchmarkTfLiteModel::InputLayerInfo>* info) {
- std::vector<std::string> names = Split(names_string, ',');
- std::vector<std::string> shapes = Split(shapes_string, ':');
-
- if (names.size() != shapes.size()) {
- TFLITE_LOG(ERROR) << "The number of items in"
- << " --input_layer_shape (" << shapes_string << ", with "
- << shapes.size() << " items)"
- << " must match the number of items in"
- << " --input_layer (" << names_string << ", with "
- << names.size() << " items)."
- << " For example --input_layer=input1,input2"
- << " --input_layer_shape=1,224,224,4:1,20";
- return false;
- }
-
- for (int i = 0; i < names.size(); ++i) {
- info->push_back(BenchmarkTfLiteModel::InputLayerInfo());
- BenchmarkTfLiteModel::InputLayerInfo& input = info->back();
-
- input.name = names[i];
-
- TFLITE_BENCHMARK_CHECK(SplitAndParse(shapes[i], ',', &input.shape))
- << "Incorrect size string specified: " << shapes[i];
- for (int dim : input.shape) {
- if (dim == -1) {
- TFLITE_LOG(ERROR)
- << "Any unknown sizes in the shapes (-1's) must be replaced"
- << " with the size you want to benchmark with.";
- return false;
- }
- }
- }
-
- return true;
-}
-
-BenchmarkParams GetDefaultParams() {
- BenchmarkParams default_params = BenchmarkModel::DefaultParams();
- default_params.AddParam("graph", BenchmarkParam::Create<std::string>(""));
- default_params.AddParam("input_layer",
- BenchmarkParam::Create<std::string>(""));
- default_params.AddParam("input_layer_shape",
- BenchmarkParam::Create<std::string>(""));
- default_params.AddParam("use_nnapi", BenchmarkParam::Create<bool>(false));
- return default_params;
-}
-
-} // namespace
-
-BenchmarkTfLiteModel::BenchmarkTfLiteModel()
- : BenchmarkModel(GetDefaultParams()) {
- AddListener(&profiling_listener_);
-}
-
-BenchmarkTfLiteModel::BenchmarkTfLiteModel(BenchmarkParams params)
- : BenchmarkModel(std::move(params)) {
- AddListener(&profiling_listener_);
-}
-
-std::vector<Flag> BenchmarkTfLiteModel::GetFlags() {
- std::vector<Flag> flags = BenchmarkTfLiteModel::BenchmarkModel::GetFlags();
- std::vector<Flag> specific_flags = {
- CreateFlag<std::string>("graph", &params_, "graph file name"),
- CreateFlag<std::string>("input_layer", &params_, "input layer names"),
- CreateFlag<std::string>("input_layer_shape", &params_,
- "input layer shape"),
- CreateFlag<bool>("use_nnapi", &params_, "use nnapi api")};
-
- flags.insert(flags.end(), specific_flags.begin(), specific_flags.end());
- return flags;
-}
-
-void BenchmarkTfLiteModel::LogFlags() {
- BenchmarkModel::LogFlags();
- TFLITE_LOG(INFO) << "Graph: [" << params_.Get<std::string>("graph") << "]";
- TFLITE_LOG(INFO) << "Input layers: ["
- << params_.Get<std::string>("input_layer") << "]";
- TFLITE_LOG(INFO) << "Input shapes: ["
- << params_.Get<std::string>("input_layer_shape") << "]";
- TFLITE_LOG(INFO) << "Use nnapi : [" << params_.Get<bool>("use_nnapi") << "]";
-}
-
-bool BenchmarkTfLiteModel::ValidateFlags() {
- if (params_.Get<std::string>("graph").empty()) {
- TFLITE_LOG(ERROR)
- << "Please specify the name of your TF Lite input file with --graph";
- return false;
- }
- return PopulateInputLayerInfo(params_.Get<std::string>("input_layer"),
- params_.Get<std::string>("input_layer_shape"),
- &inputs);
-}
-
-uint64_t BenchmarkTfLiteModel::ComputeInputBytes() {
- TFLITE_BENCHMARK_CHECK(interpreter);
- uint64_t total_input_bytes = 0;
- for (int input : interpreter->inputs()) {
- auto* t = interpreter->tensor(input);
- total_input_bytes += t->bytes;
- }
- return total_input_bytes;
-}
-
-void BenchmarkTfLiteModel::Init() {
- std::string graph = params_.Get<std::string>("graph");
- model = tflite::FlatBufferModel::BuildFromFile(graph.c_str());
- if (!model) {
- TFLITE_LOG(FATAL) << "Failed to mmap model " << graph;
- }
- TFLITE_LOG(INFO) << "Loaded model " << graph;
- model->error_reporter();
- TFLITE_LOG(INFO) << "resolved reporter";
-
-#ifdef TFLITE_CUSTOM_OPS_HEADER
- tflite::MutableOpResolver resolver;
- RegisterSelectedOps(&resolver);
-#else
- tflite::ops::builtin::BuiltinOpResolver resolver;
-#endif
-
- tflite::InterpreterBuilder(*model, resolver)(&interpreter);
- if (!interpreter) {
- TFLITE_LOG(FATAL) << "Failed to construct interpreter";
- }
- profiling_listener_.SetInterpreter(interpreter.get());
- profiling::Context::get().setProfiler(interpreter->GetProfiler());
-
- const int32_t num_threads = params_.Get<int32_t>("num_threads");
-
- if (num_threads != -1) {
- interpreter->SetNumThreads(num_threads);
- }
-
- bool use_nnapi = params_.Get<bool>("use_nnapi");
-
- interpreter->UseNNAPI(use_nnapi);
- auto interpreter_inputs = interpreter->inputs();
-
- if (!inputs.empty()) {
- TFLITE_BENCHMARK_CHECK_EQ(inputs.size(), interpreter_inputs.size())
- << "Inputs mismatch: Model inputs #:" << interpreter_inputs.size()
- << " expected: " << inputs.size();
- }
-
- // TFLITE_BENCHMARK_CHECK that all names and types match
- for (int j = 0; j < inputs.size(); ++j) {
- const InputLayerInfo& input = inputs[j];
- int i = interpreter_inputs[j];
- TfLiteTensor* t = interpreter->tensor(i);
- TFLITE_BENCHMARK_CHECK_EQ(t->name, input.name)
- << "Tensor # " << i << " is named " << t->name << " but flags call it "
- << input.name;
- }
-
- // Resize all non-string tensors.
- for (int j = 0; j < inputs.size(); ++j) {
- const InputLayerInfo& input = inputs[j];
- int i = interpreter_inputs[j];
- TfLiteTensor* t = interpreter->tensor(i);
- if (t->type != kTfLiteString) {
- interpreter->ResizeInputTensor(i, input.shape);
- }
- }
-
- if (interpreter->AllocateTensors() != kTfLiteOk) {
- TFLITE_LOG(FATAL) << "Failed to allocate tensors!";
- }
-
- // Set the values of the input tensors.
- for (int j = 0; j < inputs.size(); ++j) {
- const InputLayerInfo& input = inputs[j];
- int i = interpreter_inputs[j];
- TfLiteTensor* t = interpreter->tensor(i);
- std::vector<int> sizes = input.shape;
-
- // TODO(ahentz): below we ignore the O-th dimension (number of batches).
- if (t->type == kTfLiteFloat32) {
- FillRandomValue<float>(
- interpreter->typed_tensor<float>(i),
- std::vector<int>(sizes.begin() + 1, sizes.end()),
- []() { return static_cast<float>(rand()) / RAND_MAX - 0.5f; });
- } else if (t->type == kTfLiteUInt8) {
- FillRandomValue<uint8_t>(
- interpreter->typed_tensor<uint8_t>(i),
- std::vector<int>(sizes.begin() + 1, sizes.end()),
- []() { return static_cast<uint8_t>(rand()) % 255; });
- } else if (t->type == kTfLiteString) {
- tflite::DynamicBuffer buffer;
- FillRandomString(&buffer, sizes, []() {
- return "we're have some friends over saturday to hang out in the yard";
- });
- buffer.WriteToTensor(interpreter->tensor(i));
- } else {
- TFLITE_LOG(FATAL) << "Don't know how to populate tensor " << t->name
- << " of type " << t->type;
- }
- }
-}
-
-void BenchmarkTfLiteModel::RunImpl() {
- bool use_nnapi = params_.Get<bool>("use_nnapi");
- if (use_nnapi) {
- if (nnfw::NNAPIDelegate().Invoke(interpreter.get()) != kTfLiteOk) {
- TFLITE_LOG(FATAL) << "Failed to invoke!";
- }
- } else {
- if (interpreter->Invoke() != kTfLiteOk) {
- TFLITE_LOG(FATAL) << "Failed to invoke!";
- }
- }
-}
-
-} // namespace benchmark
-} // namespace nnfw
diff --git a/tools/tflite_benchmark_model/benchmark_tflite_model.h b/tools/tflite_benchmark_model/benchmark_tflite_model.h
deleted file mode 100644
index 7892de1f7..000000000
--- a/tools/tflite_benchmark_model/benchmark_tflite_model.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-==============================================================================*/
-
-#ifndef __TFLITE_BENCHMARK_MODEL_BENCHMARK_TFLITE_MODEL_H__
-#define __TFLITE_BENCHMARK_MODEL_BENCHMARK_TFLITE_MODEL_H__
-
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "tensorflow/contrib/lite/model.h"
-#include "tensorflow/contrib/lite/profiling/profile_summarizer.h"
-#include "benchmark_model.h"
-
-namespace nnfw {
-namespace benchmark {
-
-// Dumps profiling events if profiling is enabled
-class ProfilingListener : public BenchmarkListener {
- public:
- explicit ProfilingListener() : interpreter_(nullptr), has_profiles_(false) {}
-
- void SetInterpreter(tflite::Interpreter* interpreter);
-
- void OnSingleRunStart(RunType run_type) override;
-
- void OnSingleRunEnd() override;
-
- void OnBenchmarkEnd(const BenchmarkResults& results) override;
-
- private:
- tflite::Interpreter* interpreter_;
- tflite::profiling::Profiler profiler_;
- tflite::profiling::ProfileSummarizer summarizer_;
- bool has_profiles_;
-};
-
-// Benchmarks a TFLite model by running tflite interpreter.
-class BenchmarkTfLiteModel : public BenchmarkModel {
- public:
- BenchmarkTfLiteModel();
- BenchmarkTfLiteModel(BenchmarkParams params);
-
- std::vector<Flag> GetFlags() override;
- void LogFlags() override;
- bool ValidateFlags() override;
- uint64_t ComputeInputBytes() override;
- void Init() override;
- void RunImpl() override;
- virtual ~BenchmarkTfLiteModel() {}
-
- struct InputLayerInfo {
- std::string name;
- std::vector<int> shape;
- };
-
- private:
- std::unique_ptr<tflite::FlatBufferModel> model;
- std::unique_ptr<tflite::Interpreter> interpreter;
- std::vector<InputLayerInfo> inputs;
- ProfilingListener profiling_listener_;
-};
-
-} // namespace benchmark
-} // namespace nnfw
-
-#endif //__TFLITE_BENCHMARK_MODEL_BENCHMARK_TFLITE_MODEL_H__
diff --git a/tools/tflite_benchmark_model/command_line_flags.cc b/tools/tflite_benchmark_model/command_line_flags.cc
deleted file mode 100644
index eacca9f73..000000000
--- a/tools/tflite_benchmark_model/command_line_flags.cc
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-==============================================================================*/
-
-#include "command_line_flags.h"
-
-#include <cstring>
-#include <sstream>
-#include <string>
-#include <utility>
-#include <vector>
-
-namespace nnfw {
-namespace {
-
-template <typename T>
-std::string ToString(T val) {
- std::ostringstream stream;
- stream << val;
- return stream.str();
-}
-
-bool ParseFlag(const std::string& arg, const std::string& flag,
- const std::function<bool(const std::string&)>& parse_func,
- bool* value_parsing_ok) {
- *value_parsing_ok = true;
- std::string flag_prefix = "--" + flag + "=";
- if (arg.find(flag_prefix) != 0) {
- return false;
- }
- bool has_value = arg.size() >= flag_prefix.size();
- *value_parsing_ok = has_value;
- if (has_value) {
- *value_parsing_ok = parse_func(arg.substr(flag_prefix.size()));
- }
- return true;
-}
-
-template <typename T>
-bool ParseFlag(const std::string& flag_value,
- const std::function<void(const T&)>& hook) {
- std::istringstream stream(flag_value);
- T read_value;
- stream >> read_value;
- if (!stream.eof() && !stream.good()) {
- return false;
- }
- hook(read_value);
- return true;
-}
-
-bool ParseBoolFlag(const std::string& flag_value,
- const std::function<void(const bool&)>& hook) {
- if (flag_value != "true" && flag_value != "false") {
- return false;
- }
-
- hook(flag_value == "true");
- return true;
-}
-} // namespace
-
-Flag::Flag(const char* name, const std::function<void(const int32_t&)>& hook,
- int32_t default_value, const std::string& usage_text)
- : name_(name),
- type_(TYPE_INT32),
- value_hook_([hook](const std::string& flag_value) {
- return ParseFlag<int32_t>(flag_value, hook);
- }),
- default_for_display_(ToString(default_value)),
- usage_text_(usage_text) {}
-
-Flag::Flag(const char* name, const std::function<void(const int64_t&)>& hook,
- int64_t default_value, const std::string& usage_text)
- : name_(name),
- type_(TYPE_INT64),
- value_hook_([hook](const std::string& flag_value) {
- return ParseFlag<int64_t>(flag_value, hook);
- }),
- default_for_display_(ToString(default_value)),
- usage_text_(usage_text) {}
-
-Flag::Flag(const char* name, const std::function<void(const float&)>& hook,
- float default_value, const std::string& usage_text)
- : name_(name),
- type_(TYPE_FLOAT),
- value_hook_([hook](const std::string& flag_value) {
- return ParseFlag<float>(flag_value, hook);
- }),
- default_for_display_(ToString(default_value)),
- usage_text_(usage_text) {}
-
-Flag::Flag(const char* name, const std::function<void(const bool&)>& hook,
- bool default_value, const std::string& usage_text)
- : name_(name),
- type_(TYPE_BOOL),
- value_hook_([hook](const std::string& flag_value) {
- return ParseBoolFlag(flag_value, hook);
- }),
- default_for_display_(default_value ? "true" : "false"),
- usage_text_(usage_text) {}
-
-Flag::Flag(const char* name,
- const std::function<void(const std::string&)>& hook,
- const std::string& default_value, const std::string& usage_text)
- : name_(name),
- type_(TYPE_STRING),
- value_hook_([hook](const std::string& flag_value) {
- hook(flag_value);
- return true;
- }),
- default_for_display_(default_value),
- usage_text_(usage_text) {}
-
-bool Flag::Parse(const std::string& arg, bool* value_parsing_ok) const {
- return ParseFlag(arg, name_, value_hook_, value_parsing_ok);
-}
-
-std::string Flag::GetTypeName() const {
- switch (type_) {
- case TYPE_INT32:
- return "int32";
- case TYPE_INT64:
- return "int64";
- case TYPE_FLOAT:
- return "float";
- case TYPE_BOOL:
- return "bool";
- case TYPE_STRING:
- return "string";
- }
-
- return "unknown";
-}
-
-/*static*/ bool Flags::Parse(int* argc, const char** argv,
- const std::vector<Flag>& flag_list) {
- bool result = true;
- std::vector<const char*> unknown_flags;
- for (int i = 1; i < *argc; ++i) {
- if (std::string(argv[i]) == "--") {
- while (i < *argc) {
- unknown_flags.push_back(argv[i]);
- ++i;
- }
- break;
- }
-
- bool was_found = false;
- for (const Flag& flag : flag_list) {
- bool value_parsing_ok;
- was_found = flag.Parse(argv[i], &value_parsing_ok);
- if (!value_parsing_ok) {
- result = false;
- }
- if (was_found) {
- break;
- }
- }
- if (!was_found) {
- unknown_flags.push_back(argv[i]);
- }
- }
- int dst = 1; // Skip argv[0]
- for (auto f : unknown_flags) {
- argv[dst++] = f;
- }
- argv[dst++] = nullptr;
- *argc = unknown_flags.size() + 1;
- return result && (*argc < 2 || std::strcmp(argv[1], "--help") != 0);
-}
-
-/*static*/ std::string Flags::Usage(const std::string& cmdline,
- const std::vector<Flag>& flag_list) {
- std::ostringstream usage_text;
- usage_text << "usage: " << cmdline << "\n";
- if (!flag_list.empty()) {
- usage_text << "Flags:\n";
- }
-
- for (const Flag& flag : flag_list) {
- auto type_name = flag.GetTypeName();
- usage_text << "\t";
- usage_text << "--" << flag.name_ << "=" << flag.default_for_display_;
- usage_text << "\t" << type_name << "\t" << flag.usage_text_ << "\n";
- }
- return usage_text.str();
-}
-
-} // namespace nnfw
diff --git a/tools/tflite_benchmark_model/command_line_flags.h b/tools/tflite_benchmark_model/command_line_flags.h
deleted file mode 100644
index 766417d87..000000000
--- a/tools/tflite_benchmark_model/command_line_flags.h
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-==============================================================================*/
-
-#ifndef __TFLITE_BENCHMARK_MODEL_COMMAND_LINE_FLAGS_H__
-#define __TFLITE_BENCHMARK_MODEL_COMMAND_LINE_FLAGS_H__
-
-#include <functional>
-#include <string>
-#include <vector>
-
-namespace nnfw {
-// A simple command-line argument parsing module.
-// Dependency free simplified port of core/util/command_line_flags.
-// This class is written for benchmarks and uses inefficient string
-// concatenation. This was written to avoid dependency on tensorflow/core/util
-// which transitively brings in a lot of other dependencies that are not
-// necessary for tflite benchmarking code.
-// The recommended way of using it is with local variables and an initializer
-// list of Flag objects, for example:
-//
-// int some_int = 10;
-// bool some_switch = false;
-// std::string some_name = "something";
-//
-// std::vector<tensorFlow::Flag> flag_list = {
-// Flag::CreateFlag("some_int", &some_int, "an integer that affects X"),
-// Flag::CreateFlag("some_switch", &some_switch, "a bool that affects Y"),
-// Flag::CreateFlag("some_name", &some_name, "a string that affects Z")
-// };
-// // Get usage message before ParseFlags() to capture default values.
-// std::string usage = Flag::Usage(argv[0], flag_list);
-// bool parsed_values_ok = Flags::Parse(&argc, argv, flag_list);
-//
-// tensorflow::port::InitMain(usage.c_str(), &argc, &argv);
-// if (argc != 1 || !parsed_values_ok) {
-// ...output usage and error message...
-// }
-//
-// The argc and argv values are adjusted by the Parse function so all that
-// remains is the program name (at argv[0]) and any unknown arguments fill the
-// rest of the array. This means you can check for flags that weren't understood
-// by seeing if argv is greater than 1.
-// The result indicates if there were any errors parsing the values that were
-// passed to the command-line switches. For example, --some_int=foo would return
-// false because the argument is expected to be an integer.
-//
-// NOTE: Unlike gflags-style libraries, this library is intended to be
-// used in the `main()` function of your binary. It does not handle
-// flag definitions that are scattered around the source code.
-
-// A description of a single command line flag, holding its name, type, usage
-// text, and a pointer to the corresponding variable.
-class Flag {
- public:
- template <typename T>
- static Flag CreateFlag(const char* name, T* val, const char* usage) {
- return Flag(name, [val](const T& v) { *val = v; }, *val, usage);
- }
-
- Flag(const char* name, const std::function<void(const int32_t&)>& hook,
- int32_t default_value, const std::string& usage_text);
- Flag(const char* name, const std::function<void(const int64_t&)>& hook,
- int64_t default_value, const std::string& usage_text);
- Flag(const char* name, const std::function<void(const float&)>& hook,
- float default_value, const std::string& usage_text);
- Flag(const char* name, const std::function<void(const bool&)>& hook,
- bool default_value, const std::string& usage_text);
- Flag(const char* name, const std::function<void(const std::string&)>& hook,
- const std::string& default_value, const std::string& usage_text);
-
- private:
- friend class Flags;
-
- bool Parse(const std::string& arg, bool* value_parsing_ok) const;
-
- std::string name_;
- enum {
- TYPE_INT32,
- TYPE_INT64,
- TYPE_BOOL,
- TYPE_STRING,
- TYPE_FLOAT,
- } type_;
-
- std::string GetTypeName() const;
-
- std::function<bool(const std::string&)> value_hook_;
- std::string default_for_display_;
-
- std::string usage_text_;
-};
-
-class Flags {
- public:
- // Parse the command line represented by argv[0, ..., (*argc)-1] to find flag
- // instances matching flags in flaglist[]. Update the variables associated
- // with matching flags, and remove the matching arguments from (*argc, argv).
- // Return true iff all recognized flag values were parsed correctly, and the
- // first remaining argument is not "--help".
- static bool Parse(int* argc, const char** argv,
- const std::vector<Flag>& flag_list);
-
- // Return a usage message with command line cmdline, and the
- // usage_text strings in flag_list[].
- static std::string Usage(const std::string& cmdline,
- const std::vector<Flag>& flag_list);
-};
-
-} // namespace nnfw
-
-#endif // __TFLITE_BENCHMARK_MODEL_COMMAND_LINE_FLAGS_H__
-
-
diff --git a/tools/tflite_benchmark_model/logging.h b/tools/tflite_benchmark_model/logging.h
deleted file mode 100644
index e694a0926..000000000
--- a/tools/tflite_benchmark_model/logging.h
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-==============================================================================*/
-
-#ifndef __TFLITE_BENCHMARK_MODEL_LOGGING_H_
-#define __TFLITE_BENCHMARK_MODEL_LOGGING_H_
-
-// LOG and CHECK macros for benchmarks.
-
-#include <cstdlib>
-#include <iostream>
-#include <sstream>
-
-namespace nnfw {
-namespace logging {
-// A wrapper that logs to stderr.
-//
-// Used for TFLITE_LOG and TFLITE_BENCHMARK_CHECK macros.
-class LoggingWrapper {
- public:
- enum class LogSeverity : int {
- INFO = 0,
- WARN = 1,
- ERROR = 2,
- FATAL = 3,
- };
- LoggingWrapper(LogSeverity severity)
- : severity_(severity), should_log_(true) {}
- LoggingWrapper(LogSeverity severity, bool log)
- : severity_(severity), should_log_(log) {}
- std::stringstream& Stream() { return stream_; }
- ~LoggingWrapper() {
- if (should_log_) {
- std::cerr << stream_.str() << std::endl;
- if (severity_ == LogSeverity::FATAL) {
- std::flush(std::cerr);
- std::abort();
- }
- }
- }
-
- private:
- std::stringstream stream_;
- LogSeverity severity_;
- bool should_log_;
-};
-
-} // namespace logging
-
-} // namespace nnfw
-
-#define TFLITE_LOG(severity) \
- nnfw::logging::LoggingWrapper( \
- nnfw::logging::LoggingWrapper::LogSeverity::severity) \
- .Stream()
-
-#define TFLITE_BENCHMARK_CHECK(condition) \
- nnfw::logging::LoggingWrapper( \
- nnfw::logging::LoggingWrapper::LogSeverity::FATAL, \
- (condition) ? false : true) \
- .Stream()
-
-#define TFLITE_BENCHMARK_CHECK_EQ(a, b) TFLITE_BENCHMARK_CHECK(a == b)
-
-#endif // __TFLITE_BENCHMARK_MODEL_BENCHMARK_LOGGING_H_
diff --git a/tools/tflite_benchmark_model/profile_summarizer.cc b/tools/tflite_benchmark_model/profile_summarizer.cc
deleted file mode 100644
index 4d12b50af..000000000
--- a/tools/tflite_benchmark_model/profile_summarizer.cc
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-==============================================================================*/
-
-#include "tensorflow/contrib/lite/profiling/profile_summarizer.h"
-
-#include <sstream>
-
-#include "tensorflow/contrib/lite/schema/schema_generated.h"
-
-namespace tflite {
-namespace profiling {
-namespace {
-
-using Detail = tensorflow::StatsCalculator::Detail;
-
-struct OperatorDetails {
- std::string name;
- std::vector<std::string> inputs;
- std::vector<std::string> outputs;
-};
-
-std::string GetTensorName(const tflite::Interpreter& interpreter,
- int tensor_index) {
- const auto tensor = interpreter.tensor(tensor_index);
- if (tensor == nullptr || tensor->name == nullptr) {
- return "Unknown";
- }
- return tensor->name;
-}
-std::vector<std::string> GetTensorNames(const tflite::Interpreter& interpreter,
- const TfLiteIntArray* tensor_indices) {
- std::vector<std::string> tensors;
- tensors.reserve(tensor_indices->size);
- for (int i = 0; i < tensor_indices->size; i++) {
- tensors.push_back(GetTensorName(interpreter, tensor_indices->data[i]));
- }
- return tensors;
-}
-
-std::string ToString(const std::vector<std::string>& str_vector) {
- std::stringstream stream;
- stream << "[";
- bool first = true;
- for (const auto& s : str_vector) {
- if (!first) {
- stream << ", ";
- } else {
- first = false;
- }
- stream << s;
- }
- stream << "]";
- return stream.str();
-}
-
-OperatorDetails GetOperatorDetails(const tflite::Interpreter& interpreter,
- int node_index) {
- auto node_reg = interpreter.node_and_registration(node_index);
- auto inputs = node_reg->first.inputs;
- auto outputs = node_reg->first.outputs;
- int code = node_reg->second.builtin_code;
- const char* op_name = nullptr;
- if (code == tflite::BuiltinOperator_CUSTOM) {
- const char* custom_name = node_reg->second.custom_name;
- op_name = custom_name ? custom_name : "UnknownCustomOp";
- } else {
- op_name = tflite::EnumNamesBuiltinOperator()[code];
- }
- OperatorDetails details;
- details.name = op_name;
- details.inputs = GetTensorNames(interpreter, inputs);
- details.outputs = GetTensorNames(interpreter, outputs);
- return details;
-}
-
-} // namespace
-
-ProfileSummarizer::ProfileSummarizer()
- : stats_calculator_(new ::tensorflow::StatsCalculator(
- tensorflow::StatSummarizerOptions())) {}
-
-void ProfileSummarizer::ProcessProfiles(
- const std::vector<const ProfileEvent*>& profile_stats,
- const tflite::Interpreter& interpreter) {
- std::vector<const ProfileEvent*> events;
- std::copy_if(profile_stats.begin(), profile_stats.end(),
- std::back_inserter(events), [](const ProfileEvent* e) {
- return e->event_type ==
- ProfileEvent::EventType::OPERATOR_INVOKE_EVENT &&
- e->end_timestamp_us >= e->begin_timestamp_us;
- });
- // Sort with begin_time.
- std::sort(events.begin(), events.end(),
- [](const ProfileEvent* const& a, const ProfileEvent* const& b) {
- return a->begin_timestamp_us < b->begin_timestamp_us;
- });
- if (events.empty()) {
- return;
- }
-
- int64_t base_start_us = events[0]->begin_timestamp_us;
- int node_num = 0;
- int64_t curr_total_us = 0;
- std::map<std::string, Detail> details;
- int prev_op_idx = -1;
- int seq_no = 1;
- for (auto event : events) {
- auto op_details = GetOperatorDetails(interpreter, event->event_metadata);
- bool is_continued = (prev_op_idx == event->event_metadata);
- seq_no = is_continued ? seq_no + 1 : 1;
- auto node_name = ToString(op_details.outputs) + "#" + std::to_string(seq_no);
- auto result = details.emplace(node_name, Detail());
- Detail* detail = &(result.first->second);
- detail->start_us.UpdateStat(event->begin_timestamp_us - base_start_us);
- int64_t node_exec_time =
- event->end_timestamp_us - event->begin_timestamp_us;
- detail->rel_end_us.UpdateStat(node_exec_time);
- curr_total_us += node_exec_time;
- ++node_num;
-
- if (result.second) {
- detail->name = node_name;
- detail->type = op_details.name;
- detail->run_order = node_num;
- detail->times_called = 0;
- }
- if (!is_continued) {
- ++detail->times_called;
- }
- prev_op_idx = event->event_metadata;
- }
- stats_calculator_->UpdateDetails(details);
- stats_calculator_->UpdateRunTotalUs(curr_total_us);
-}
-} // namespace profiling
-} // namespace tflite
diff --git a/tools/tflite_benchmark_model/profile_summarizer.h b/tools/tflite_benchmark_model/profile_summarizer.h
deleted file mode 100644
index a529ff874..000000000
--- a/tools/tflite_benchmark_model/profile_summarizer.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-==============================================================================*/
-
-#ifndef TENSORFLOW_CONTRIB_LITE_PROFILING_PROFILE_SUMMARIZER_H_
-#define TENSORFLOW_CONTRIB_LITE_PROFILING_PROFILE_SUMMARIZER_H_
-
-#include <vector>
-
-#include "tensorflow/contrib/lite/interpreter.h"
-#include "tensorflow/contrib/lite/profiling/profiler.h"
-#include "tensorflow/core/util/stats_calculator.h"
-
-namespace tflite {
-namespace profiling {
-
-// Creates a summary of operator invocations in the interpreter.
-class ProfileSummarizer {
- public:
- ProfileSummarizer();
- virtual ~ProfileSummarizer() {}
-
- // Process profile events to update statistics for operator invocations.
- void ProcessProfiles(const std::vector<const ProfileEvent*>& profile_stats,
- const tflite::Interpreter& interpreter);
-
- // Returns a string detailing the accumulated runtime stats in a tab-separated
- // format which can be pasted into a spreadsheet for further analysis.
- std::string GetOutputString() const {
- return stats_calculator_->GetOutputString();
- }
-
- std::string GetShortSummary() const {
- return stats_calculator_->GetShortSummary();
- }
-
- private:
- std::unique_ptr<tensorflow::StatsCalculator> stats_calculator_;
-};
-
-} // namespace profiling
-} // namespace tflite
-
-#endif // TENSORFLOW_CONTRIB_LITE_PROFILING_PROFILE_SUMMARIZER_H_
diff --git a/tools/tflite_examples/CMakeLists.txt b/tools/tflite_examples/CMakeLists.txt
deleted file mode 100644
index 5fe33302a..000000000
--- a/tools/tflite_examples/CMakeLists.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-add_executable(tflite_conv_example "src/conv.cpp")
-target_link_libraries(tflite_conv_example tensorflow-lite ${LIB_PTHREAD} dl nnfw_support_tflite)
diff --git a/tools/tflite_examples/src/conv.cpp b/tools/tflite_examples/src/conv.cpp
deleted file mode 100644
index a647346ee..000000000
--- a/tools/tflite_examples/src/conv.cpp
+++ /dev/null
@@ -1,330 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "support/tflite/kernels/register.h"
-#include "tensorflow/contrib/lite/model.h"
-#include "tensorflow/contrib/lite/builtin_op_data.h"
-
-#include <iostream>
-
-using namespace tflite;
-using namespace tflite::ops::builtin;
-
-namespace vector
-{
-
-template <typename T> struct View
-{
- virtual ~View() = default;
-
- virtual int32_t size(void) const = 0;
- virtual T at(uint32_t off) const = 0;
-};
-}
-
-namespace feature
-{
-
-struct Shape
-{
- int32_t C;
- int32_t H;
- int32_t W;
-};
-
-template <typename T> struct View
-{
- virtual ~View() = default;
-
- virtual const Shape &shape(void) const = 0;
- virtual T at(uint32_t ch, uint32_t row, uint32_t col) const = 0;
-};
-}
-
-namespace kernel
-{
-
-struct Shape
-{
- int32_t N;
- int32_t C;
- int32_t H;
- int32_t W;
-};
-
-template <typename T> struct View
-{
- virtual ~View() = default;
-
- virtual const Shape &shape(void) const = 0;
- virtual T at(uint32_t nth, uint32_t ch, uint32_t row, uint32_t col) const = 0;
-};
-}
-
-const int32_t N = 1;
-const int32_t C = 2;
-
-class SampleBiasObject final : public vector::View<float>
-{
-public:
- SampleBiasObject() : _size(N)
- {
- // DO NOTHING
- }
-
-public:
- int32_t size(void) const override { return _size; }
-
- float at(uint32_t off) const override { return 0.0f; }
-
-private:
- int32_t _size;
-};
-
-class SampleFeatureObject final : public feature::View<float>
-{
-public:
- SampleFeatureObject()
- {
- _shape.C = C;
- _shape.H = 3;
- _shape.W = 4;
-
- const uint32_t size = _shape.C * _shape.H * _shape.W;
-
- for (uint32_t off = 0; off < size; ++off)
- {
- _value.emplace_back(off);
- }
-
- assert(_value.size() == size);
- }
-
-public:
- const feature::Shape &shape(void) const override { return _shape; };
-
- float at(uint32_t ch, uint32_t row, uint32_t col) const override
- {
- return _value.at(ch * _shape.H * _shape.W + row * _shape.W + col);
- }
-
-public:
- float &at(uint32_t ch, uint32_t row, uint32_t col)
- {
- return _value.at(ch * _shape.H * _shape.W + row * _shape.W + col);
- }
-
-private:
- feature::Shape _shape;
- std::vector<float> _value;
-};
-
-class SampleKernelObject final : public kernel::View<float>
-{
-public:
- SampleKernelObject()
- {
- _shape.N = N;
- _shape.C = C;
- _shape.H = 3;
- _shape.W = 4;
-
- const uint32_t size = _shape.N * _shape.C * _shape.H * _shape.W;
-
- for (uint32_t off = 0; off < size; ++off)
- {
- _value.emplace_back(off);
- }
-
- assert(_value.size() == size);
- }
-
-public:
- const kernel::Shape &shape(void) const override { return _shape; };
-
- float at(uint32_t nth, uint32_t ch, uint32_t row, uint32_t col) const override
- {
- return _value.at(nth * _shape.C * _shape.H * _shape.W + ch * _shape.H * _shape.W +
- row * _shape.W + col);
- }
-
-private:
- kernel::Shape _shape;
- std::vector<float> _value;
-};
-
-int main(int argc, char **argv)
-{
- const SampleFeatureObject ifm;
- const SampleKernelObject kernel;
- const SampleBiasObject bias;
-
- const int32_t IFM_C = ifm.shape().C;
- const int32_t IFM_H = ifm.shape().H;
- const int32_t IFM_W = ifm.shape().W;
-
- const int32_t KER_N = kernel.shape().N;
- const int32_t KER_C = kernel.shape().C;
- const int32_t KER_H = kernel.shape().H;
- const int32_t KER_W = kernel.shape().W;
-
- const int32_t OFM_C = kernel.shape().N;
- const int32_t OFM_H = (IFM_H - KER_H) + 1;
- const int32_t OFM_W = (IFM_W - KER_W) + 1;
-
- // Assumption on this example
- assert(IFM_C == KER_C);
- assert(KER_N == bias.size());
-
- // Comment from 'context.h'
- //
- // Parameters for asymmetric quantization. Quantized values can be converted
- // back to float using:
- // real_value = scale * (quantized_value - zero_point);
- //
- // Q: Is this necessary?
- TfLiteQuantizationParams quantization;
-
- quantization.scale = 1;
- quantization.zero_point = 0;
-
- Interpreter interp;
-
- // On AddTensors(N) call, T/F Lite interpreter creates N tensors whose index is [0 ~ N)
- interp.AddTensors(5);
-
- // Configure OFM
- interp.SetTensorParametersReadWrite(0, kTfLiteFloat32 /* type */, "output" /* name */,
- {1 /*N*/, OFM_H, OFM_W, OFM_C} /* dims */, quantization);
-
- // Configure IFM
- interp.SetTensorParametersReadWrite(1, kTfLiteFloat32 /* type */, "input" /* name */,
- {1 /*N*/, IFM_H, IFM_W, IFM_C} /* dims */, quantization);
-
- // Configure Filter
- const uint32_t kernel_size = KER_N * KER_C * KER_H * KER_W;
- float kernel_data[kernel_size] = {
- 0.0f,
- };
-
- // Fill kernel data in NHWC order
- {
- uint32_t off = 0;
-
- for (uint32_t nth = 0; nth < KER_N; ++nth)
- {
- for (uint32_t row = 0; row < KER_H; ++row)
- {
- for (uint32_t col = 0; col < KER_W; ++col)
- {
- for (uint32_t ch = 0; ch < KER_C; ++ch)
- {
- const auto value = kernel.at(nth, ch, row, col);
- kernel_data[off++] = value;
- }
- }
- }
- }
-
- assert(kernel_size == off);
- }
-
- interp.SetTensorParametersReadOnly(
- 2, kTfLiteFloat32 /* type */, "filter" /* name */, {KER_N, KER_H, KER_W, KER_C} /* dims */,
- quantization, reinterpret_cast<const char *>(kernel_data), sizeof(kernel_data));
-
- // Configure Bias
- const uint32_t bias_size = bias.size();
- float bias_data[bias_size] = {
- 0.0f,
- };
-
- // Fill bias data
- for (uint32_t off = 0; off < bias.size(); ++off)
- {
- bias_data[off] = bias.at(off);
- }
-
- interp.SetTensorParametersReadOnly(3, kTfLiteFloat32 /* type */, "bias" /* name */,
- {bias.size()} /* dims */, quantization,
- reinterpret_cast<const char *>(bias_data), sizeof(bias_data));
-
- // Add Convolution Node
- //
- // NOTE AddNodeWithParameters take the ownership of param, and deallocate it with free
- // So, param should be allocated with malloc
- TfLiteConvParams *param = reinterpret_cast<TfLiteConvParams *>(malloc(sizeof(TfLiteConvParams)));
-
- param->padding = kTfLitePaddingValid;
- param->stride_width = 1;
- param->stride_height = 1;
- param->activation = kTfLiteActRelu;
-
- // Run Convolution and store its result into Tensor #0
- // - Read IFM from Tensor #1
- // - Read Filter from Tensor #2,
- // - Read Bias from Tensor #3
- interp.AddNodeWithParameters({1, 2, 3}, {0}, nullptr, 0, reinterpret_cast<void *>(param),
- BuiltinOpResolver().FindOp(BuiltinOperator_CONV_2D, 1));
-
- // Set Tensor #1 as Input #0, and Tensor #0 as Output #0
- interp.SetInputs({1});
- interp.SetOutputs({0});
-
- // Let's use NNAPI (if possible)
- interp.UseNNAPI(true);
-
- // Allocate Tensor
- interp.AllocateTensors();
-
- // Fill IFM data in HWC order
- {
- uint32_t off = 0;
-
- for (uint32_t row = 0; row < ifm.shape().H; ++row)
- {
- for (uint32_t col = 0; col < ifm.shape().W; ++col)
- {
- for (uint32_t ch = 0; ch < ifm.shape().C; ++ch)
- {
- const auto value = ifm.at(ch, row, col);
- interp.typed_input_tensor<float>(0)[off++] = value;
- }
- }
- }
- }
-
- // Let's Rock-n-Roll!
- interp.Invoke();
-
- // Print OFM
- {
- uint32_t off = 0;
-
- for (uint32_t row = 0; row < OFM_H; ++row)
- {
- for (uint32_t col = 0; col < OFM_W; ++col)
- {
- for (uint32_t ch = 0; ch < kernel.shape().N; ++ch)
- {
- std::cout << interp.typed_output_tensor<float>(0)[off++] << std::endl;
- }
- }
- }
- }
-
- return 0;
-}
diff --git a/tools/tflite_run/CMakeLists.txt b/tools/tflite_run/CMakeLists.txt
deleted file mode 100644
index c9f72acee..000000000
--- a/tools/tflite_run/CMakeLists.txt
+++ /dev/null
@@ -1,26 +0,0 @@
-list(APPEND TFLITE_RUN_SRCS "src/tflite_run.cc")
-list(APPEND TFLITE_RUN_SRCS "src/bin_image.cc")
-list(APPEND TFLITE_RUN_SRCS "src/args.cc")
-list(APPEND TFLITE_RUN_SRCS "src/tensor_dumper.cc")
-list(APPEND TFLITE_RUN_SRCS "src/tensor_loader.cc")
-
-add_executable(tflite_run ${TFLITE_RUN_SRCS})
-target_include_directories(tflite_run PRIVATE src)
-target_link_libraries(tflite_run tensorflow-lite ${LIB_PTHREAD} dl nnfw_support_tflite)
-target_link_libraries(tflite_run boost_program_options boost_system boost_filesystem)
-
-install(TARGETS tflite_run DESTINATION bin)
-
-# TEST BUILD
-nnfw_find_package(GTest)
-
-if(NOT GTest_FOUND)
- return()
-endif(NOT GTest_FOUND)
-
-## Add test cpp file
-add_executable(tflite_test src/tflite_test.cc)
-## Link test executable against gtest & gtest_main
-target_link_libraries(tflite_test gtest gtest_main ${LIB_PTHREAD})
-## install test binary for packaging
-install(TARGETS tflite_test DESTINATION unittest)
diff --git a/tools/tflite_run/README.md b/tools/tflite_run/README.md
deleted file mode 100644
index 35d2b6497..000000000
--- a/tools/tflite_run/README.md
+++ /dev/null
@@ -1,91 +0,0 @@
-# tflite_run
-
-A simple Tensorflow Lite runner. It measures the elapsed time and optionally dump the input/output tensors or verify them.
-
-## Usage
-
-### Simple run
-
-This will run with random input data
-
-```
-$ ./tflite_run model.tflite
-```
-
-Output would look like:
-
-```
-input tensor indices = [0,]
-Input image size is smaller than the size required by the model. Input will not be set.
-output tensor indices = [308(max:984),]
-Prepare takes 0.00126718 seconds
-Invoke takes 7.09527 seconds
-```
-
-### Specifying input feature map
-
-We can specify input feature map, but it only accepts preprocessed data which means that the image files must be converted.
-
-TODO : Add input image preprocessing instruction
-
-```
-$ ./tflite_run model.tflite -i binary_input_file
-```
-
-### Dump the input and output tensors
-
-Dump the input and output tensors to a file.
-```
-$ ./tflite_run model.tflite --dump golden
-```
-
-Why we do this is usually for later verification. The tensors are written to name "golden".
-
-### Compare with the saved outputs
-
-The result from `tflite_run` and binary file are compared with `--compare` option.
-
-```
-$ ls golden
-golden
-$ ./tflite_run model.tflite --compare golden
-```
-
-The output would look like:
-
-```
-input tensor indices = [0,]
-Input image size is smaller than the size required by the model. Input will not be set.
-output tensor indices = [308(max:984),]
-Prepare takes 0.00126718 seconds
-Invoke takes 7.09527 seconds
-========================================
-Comparing the results with "golden2".
-========================================
- Tensor #308: UNMATCHED
- 1 diffs are detected
- Max absolute diff at [0, 0]
- expected: 99
- obtained: 0.000139008
- absolute diff: 98.9999
- Max relative diff at [0, 1007]
- expected: 7.01825e-33
- obtained: 0.000139011
- relative diff: 1
- (tolerance level = 8.38861e+06)
-```
-
-If `--compare` option is on, the exit code will be depend on its compare result. 0 for matched, other number for unmatched.
-
-## How Verification Works
-
-For verification, we may follow these steps:
-
-1. Generate and store the verfication data (run with option `--dump`)
- 1. Input Tensor does not matter as we will keep inputs along with outputs
- 1. Interpreter.Invoke()
- 1. Dump input tensors and output tensors to a file
-1. Give the dumped file for other runtime that we want to verify (run with option `--compare`)
- 1. Set interpreter's input to input tensor data from the file
- 1. Interpreter.Invoke()
- 1. Compare the results with output tensor data from the file
diff --git a/tools/tflite_run/src/args.cc b/tools/tflite_run/src/args.cc
deleted file mode 100644
index 6aebbbbd7..000000000
--- a/tools/tflite_run/src/args.cc
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "args.h"
-
-#include <iostream>
-
-#include <boost/filesystem.hpp>
-
-namespace TFLiteRun
-{
-
-Args::Args(const int argc, char **argv)
-{
- Initialize();
- Parse(argc, argv);
-}
-
-void Args::Initialize(void)
-{
-
- // General options
- po::options_description general("General options");
-
- // clang-format off
- general.add_options()
- ("help,h", "Display available options")
- ("input,i", po::value<std::string>(&_input_filename)->default_value(""), "Input filename")
- ("dump,d", po::value<std::string>()->default_value(""), "Output filename")
- ("compare,c", po::value<std::string>()->default_value(""), "filename to be compared with")
- ("tflite", po::value<std::string>()->required());
- // clang-format on
-
- _options.add(general);
- _positional.add("tflite", 1);
-}
-
-void Args::Parse(const int argc, char **argv)
-{
- po::variables_map vm;
- po::store(po::command_line_parser(argc, argv).options(_options).positional(_positional).run(),
- vm);
- po::notify(vm);
-
- {
- auto conflicting_options = [&](const std::string &o1, const std::string &o2) {
- if ((vm.count(o1) && !vm[o1].defaulted()) && (vm.count(o2) && !vm[o2].defaulted()))
- {
- throw boost::program_options::error(std::string("Two options '") + o1 + "' and '" + o2 +
- "' cannot be given at once.");
- }
- };
-
- conflicting_options("input", "compare");
- }
-
- if (vm.count("help"))
- {
- std::cout << "tflite_run\n\n";
- std::cout << "Usage: " << argv[0] << " <.tflite> [<options>]\n\n";
- std::cout << _options;
- std::cout << "\n";
-
- exit(0);
- }
-
- if (vm.count("input"))
- {
- _input_filename = vm["input"].as<std::string>();
-
- if (!_input_filename.empty())
- {
- if (!boost::filesystem::exists(_input_filename))
- {
- std::cerr << "input image file not found: " << _input_filename << "\n";
- }
- }
- }
-
- if (vm.count("dump"))
- {
- _dump_filename = vm["dump"].as<std::string>();
- }
-
- if (vm.count("compare"))
- {
- _compare_filename = vm["compare"].as<std::string>();
- }
-
- if (vm.count("tflite"))
- {
- _tflite_filename = vm["tflite"].as<std::string>();
-
- if (_tflite_filename.empty())
- {
- // TODO Print usage instead of the below message
- std::cerr << "Please specify tflite file. Run with `--help` for usage."
- << "\n";
-
- exit(1);
- }
- else
- {
- if (!boost::filesystem::exists(_tflite_filename))
- {
- std::cerr << "tflite file not found: " << _tflite_filename << "\n";
- }
- }
- }
-}
-
-} // end of namespace TFLiteRun
diff --git a/tools/tflite_run/src/args.h b/tools/tflite_run/src/args.h
deleted file mode 100644
index 7b270d4ee..000000000
--- a/tools/tflite_run/src/args.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __TFLITE_RUN_ARGS_H__
-#define __TFLITE_RUN_ARGS_H__
-
-#include <string>
-#include <boost/program_options.hpp>
-
-namespace po = boost::program_options;
-
-namespace TFLiteRun
-{
-
-class Args
-{
-public:
- Args(const int argc, char **argv);
- void print(void);
-
- const std::string &getTFLiteFilename(void) const { return _tflite_filename; }
- const std::string &getInputFilename(void) const { return _input_filename; }
- const std::string &getDumpFilename(void) const { return _dump_filename; }
- const std::string &getCompareFilename(void) const { return _compare_filename; }
-
-private:
- void Initialize();
- void Parse(const int argc, char **argv);
-
-private:
- po::positional_options_description _positional;
- po::options_description _options;
-
- std::string _tflite_filename;
- std::string _input_filename;
- std::string _dump_filename;
- std::string _compare_filename;
-};
-
-} // end of namespace TFLiteRun
-
-#endif // __TFLITE_RUN_ARGS_H__
diff --git a/tools/tflite_run/src/bin_image.cc b/tools/tflite_run/src/bin_image.cc
deleted file mode 100644
index 16d4c94f7..000000000
--- a/tools/tflite_run/src/bin_image.cc
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <iostream>
-#include <fstream>
-
-#include "bin_image.h"
-
-BinImage::BinImage(unsigned int width, unsigned int height, unsigned int channels)
- : _width(width), _height(height), _channels(channels)
-{
-}
-
-BinImage::~BinImage() {}
-
-void BinImage::loadImage(const std::string &filename)
-{
- std::ifstream fin(filename);
-
- if (!fin)
- {
- std::cerr << "image filename is not specified. "
- << "Input image will not be set." << std::endl;
- return;
- }
-
- _image.reserve(_width * _height * _channels);
-
- // Assuption: binary image is stored in the order of [H,W,C]
- for (unsigned int i = 0; i < _width * _height * _channels; ++i)
- _image.push_back(fin.get());
-}
-
-void BinImage::AssignTensor(TfLiteTensor *t)
-{
- float *p = t->data.f;
- const int IMAGE_MEAN = 128;
- const float IMAGE_STD = 128.0f;
-
- // to prevent runtime exception
- if (_image.size() < _width * _height * _channels)
- {
- std::cerr << "Input image size is smaller than the size required by the model."
- << " Input will not be set." << std::endl;
- return;
- }
-
- for (int x = 0; x < _width; ++x)
- {
- for (int y = 0; y < _height; ++y)
- {
- for (int c = 0; c < _channels; ++c)
- {
- *p++ = (_image[y * _width * _channels + x * _channels + c] - IMAGE_MEAN) / IMAGE_STD;
- }
- }
- }
-}
diff --git a/tools/tflite_run/src/bin_image.h b/tools/tflite_run/src/bin_image.h
deleted file mode 100644
index 845011be6..000000000
--- a/tools/tflite_run/src/bin_image.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __TFLITE_RUN_LIBJPEG_H__
-#define __TFLITE_RUN_LIBJPEG_H__
-
-#include <string>
-#include <vector>
-
-#include "tensorflow/contrib/lite/context.h"
-
-class BinImage
-{
-public:
- BinImage(unsigned int width, unsigned int height, unsigned int channel);
- ~BinImage();
-
- void loadImage(const std::string &filename);
-
- void AssignTensor(TfLiteTensor *t);
-
-private:
- unsigned int _width;
- unsigned int _height;
- unsigned int _channels;
-
- std::vector<unsigned char> _image;
-};
-
-#endif // __TFLITE_RUN_LIBJPEG_H__
diff --git a/tools/tflite_run/src/tensor_dumper.cc b/tools/tflite_run/src/tensor_dumper.cc
deleted file mode 100644
index 8568c9b67..000000000
--- a/tools/tflite_run/src/tensor_dumper.cc
+++ /dev/null
@@ -1,54 +0,0 @@
-#include "tensor_dumper.h"
-
-#include <fstream>
-#include <iostream>
-#include <cstring>
-
-#include "tensorflow/contrib/lite/interpreter.h"
-
-namespace TFLiteRun
-{
-
-TensorDumper::TensorDumper()
-{
- // DO NOTHING
-}
-
-void TensorDumper::addTensors(tflite::Interpreter &interpreter, const std::vector<int> &indices)
-{
- for (const auto &o : indices)
- {
- const TfLiteTensor *tensor = interpreter.tensor(o);
- int size = tensor->bytes;
- std::vector<char> buffer;
- buffer.resize(size);
- memcpy(buffer.data(), tensor->data.raw, size);
- _tensors.emplace_back(o, std::move(buffer));
- }
-}
-
-void TensorDumper::dump(const std::string &filename) const
-{
- // TODO Handle file open/write error
- std::ofstream file(filename, std::ios::out | std::ios::binary);
-
- // Write number of tensors
- uint32_t num_tensors = static_cast<uint32_t>(_tensors.size());
- file.write(reinterpret_cast<const char *>(&num_tensors), sizeof(num_tensors));
-
- // Write tensor indices
- for (const auto &t : _tensors)
- {
- file.write(reinterpret_cast<const char *>(&t._index), sizeof(int));
- }
-
- // Write data
- for (const auto &t : _tensors)
- {
- file.write(t._data.data(), t._data.size());
- }
-
- file.close();
-}
-
-} // end of namespace TFLiteRun
diff --git a/tools/tflite_run/src/tensor_dumper.h b/tools/tflite_run/src/tensor_dumper.h
deleted file mode 100644
index 2805f1076..000000000
--- a/tools/tflite_run/src/tensor_dumper.h
+++ /dev/null
@@ -1,38 +0,0 @@
-#ifndef __TFLITE_RUN_TENSOR_DUMPER_H__
-#define __TFLITE_RUN_TENSOR_DUMPER_H__
-
-#include <memory>
-#include <string>
-#include <vector>
-
-namespace tflite
-{
-class Interpreter;
-}
-
-namespace TFLiteRun
-{
-
-class TensorDumper
-{
-private:
- struct Tensor
- {
- int _index;
- std::vector<char> _data;
-
- Tensor(int index, std::vector<char> &&data) : _index(index), _data(std::move(data)) {}
- };
-
-public:
- TensorDumper();
- void addTensors(tflite::Interpreter &interpreter, const std::vector<int> &indices);
- void dump(const std::string &filename) const;
-
-private:
- std::vector<Tensor> _tensors;
-};
-
-} // end of namespace TFLiteRun
-
-#endif // __TFLITE_RUN_TENSOR_DUMPER_H__
diff --git a/tools/tflite_run/src/tensor_loader.cc b/tools/tflite_run/src/tensor_loader.cc
deleted file mode 100644
index 678ff083e..000000000
--- a/tools/tflite_run/src/tensor_loader.cc
+++ /dev/null
@@ -1,67 +0,0 @@
-#include "tensor_loader.h"
-
-#include <assert.h>
-
-#include <fstream>
-
-#include "util/tensor/Shape.h"
-
-namespace TFLiteRun
-{
-
-TensorLoader::TensorLoader(tflite::Interpreter &interpreter)
- : _interpreter(interpreter), _raw_data(nullptr)
-{
-}
-
-void TensorLoader::load(const std::string &filename)
-{
- // TODO Handle file open/read error
- std::ifstream file(filename, std::ios::ate | std::ios::binary);
- size_t file_size = file.tellg();
- file.seekg(0, std::ios::beg);
-
- uint32_t num_tensors = 0;
- file.read(reinterpret_cast<char *>(&num_tensors), sizeof(num_tensors));
-
- int tensor_indices_raw[num_tensors];
- file.read(reinterpret_cast<char *>(tensor_indices_raw), sizeof(tensor_indices_raw));
- std::vector<int> tensor_indices(tensor_indices_raw, tensor_indices_raw + num_tensors);
-
- _raw_data = std::unique_ptr<float>(new float[file_size]);
- file.read(reinterpret_cast<char *>(_raw_data.get()), file_size);
-
- size_t offset = 0;
- for (const auto &o : tensor_indices)
- {
- const TfLiteTensor *tensor = _interpreter.tensor(o);
-
- // Convert tensor shape to `Shape` from `tensor->dims`
- nnfw::util::tensor::Shape shape(static_cast<size_t>(tensor->dims->size));
- for (int d = 0; d < tensor->dims->size; d++)
- {
- shape.dim(d) = tensor->dims->data[d];
- }
-
- float *base = _raw_data.get() + offset;
-
- assert(tensor->bytes % sizeof(float) == 0);
- offset += (tensor->bytes / sizeof(float));
-
- _tensor_map.insert(std::make_pair(o, nnfw::support::tflite::TensorView<float>(shape, base)));
- }
-
- // The file size and total output tensor size must match
- assert(file_size == sizeof(num_tensors) + sizeof(tensor_indices_raw) + offset * sizeof(float));
-
- file.close();
-}
-
-const nnfw::support::tflite::TensorView<float> &TensorLoader::get(int tensor_idx) const
-{
- auto found = _tensor_map.find(tensor_idx);
- assert(found != _tensor_map.end());
- return found->second;
-}
-
-} // end of namespace TFLiteRun
diff --git a/tools/tflite_run/src/tensor_loader.h b/tools/tflite_run/src/tensor_loader.h
deleted file mode 100644
index f2a699185..000000000
--- a/tools/tflite_run/src/tensor_loader.h
+++ /dev/null
@@ -1,35 +0,0 @@
-#ifndef __TFLITE_RUN_TENSOR_LOADER_H__
-#define __TFLITE_RUN_TENSOR_LOADER_H__
-
-#include <sys/mman.h>
-
-#include <string>
-#include <unordered_map>
-
-#include "support/tflite/TensorView.h"
-
-namespace tflite
-{
-class Interpreter;
-}
-
-namespace TFLiteRun
-{
-
-class TensorLoader
-{
-public:
- TensorLoader(tflite::Interpreter &interpreter);
- void load(const std::string &filename);
- const nnfw::support::tflite::TensorView<float> &get(int tensor_idx) const;
- size_t getNums() const { return _tensor_map.size(); }
-
-private:
- tflite::Interpreter &_interpreter;
- std::unique_ptr<float> _raw_data;
- std::unordered_map<int, nnfw::support::tflite::TensorView<float>> _tensor_map;
-};
-
-} // end of namespace TFLiteRun
-
-#endif // __TFLITE_RUN_TENSOR_LOADER_H__
diff --git a/tools/tflite_run/src/tflite_run.cc b/tools/tflite_run/src/tflite_run.cc
deleted file mode 100644
index 23a23809b..000000000
--- a/tools/tflite_run/src/tflite_run.cc
+++ /dev/null
@@ -1,253 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "support/tflite/kernels/register.h"
-#include "tensorflow/contrib/lite/model.h"
-
-#include "bin_image.h"
-#include "args.h"
-#include "tensor_dumper.h"
-#include "tensor_loader.h"
-#include "util/benchmark.h"
-#include "util/environment.h"
-#include "util/fp32.h"
-#include "support/tflite/Diff.h"
-#include "support/tflite/Assert.h"
-#include "support/tflite/Session.h"
-#include "support/tflite/InterpreterSession.h"
-#include "support/tflite/NNAPISession.h"
-#include "util/tensor/IndexIterator.h"
-
-#include <iostream>
-#include <chrono>
-#include <algorithm>
-
-using namespace tflite;
-using namespace tflite::ops::builtin;
-
-void print_max_idx(float *f, int size)
-{
- float *p = std::max_element(f, f + size);
- std::cout << "max:" << p - f;
-}
-
-int main(const int argc, char **argv)
-{
- bool use_nnapi = false;
-
- if (std::getenv("USE_NNAPI") != nullptr)
- {
- use_nnapi = true;
- }
-
- StderrReporter error_reporter;
-
- TFLiteRun::Args args(argc, argv);
-
- auto model = FlatBufferModel::BuildFromFile(args.getTFLiteFilename().c_str(), &error_reporter);
- std::unique_ptr<Interpreter> interpreter;
-
- std::chrono::milliseconds t_prepare(0);
- std::chrono::milliseconds t_invoke(0);
-
- nnfw::util::benchmark::measure(t_prepare) << [&](void) {
- BuiltinOpResolver resolver;
-
- InterpreterBuilder builder(*model, resolver);
-
- TFLITE_ENSURE(builder(&interpreter))
-
- interpreter->SetNumThreads(1);
- };
-
- std::shared_ptr<nnfw::support::tflite::Session> sess;
-
- if (use_nnapi)
- {
- sess = std::make_shared<nnfw::support::tflite::NNAPISession>(interpreter.get());
- }
- else
- {
- sess = std::make_shared<nnfw::support::tflite::InterpreterSession>(interpreter.get());
- }
-
- sess->prepare();
-
- TFLiteRun::TensorLoader tensor_loader(*interpreter);
-
- // Load input from image or dumped tensor file. Two options are exclusive and will be checked
- // from Args.
- if (args.getInputFilename().size() > 0)
- {
- BinImage image(299, 299, 3);
- image.loadImage(args.getInputFilename());
-
- for (const auto &o : interpreter->inputs())
- {
- image.AssignTensor(interpreter->tensor(o));
- }
- }
- else if (!args.getCompareFilename().empty())
- {
- tensor_loader.load(args.getCompareFilename());
-
- for (const auto &o : interpreter->inputs())
- {
- const auto &tensor_view = tensor_loader.get(o);
- TfLiteTensor *tensor = interpreter->tensor(o);
-
- memcpy(reinterpret_cast<void *>(tensor->data.f),
- reinterpret_cast<const void *>(tensor_view._base), tensor->bytes);
- }
- }
- else
- {
- // No input specified. So we fill the input tensors with random values.
- for (const auto &o : interpreter->inputs())
- {
- TfLiteTensor *tensor = interpreter->tensor(o);
- if (tensor->type == kTfLiteInt32)
- {
- // Generate singed 32-bit integer (s32) input
- auto tensor_view = nnfw::support::tflite::TensorView<int32_t>::make(*interpreter, o);
-
- int32_t value = 0;
-
- nnfw::util::tensor::iterate(tensor_view.shape())
- << [&](const nnfw::util::tensor::Index &ind) {
- // TODO Generate random values
- // Gather operation: index should be within input coverage.
- tensor_view.at(ind) = value;
- value++;
- };
- }
- else if (tensor->type == kTfLiteUInt8)
- {
- // Generate unsigned 8-bit integer input
- auto tensor_view = nnfw::support::tflite::TensorView<uint8_t>::make(*interpreter, o);
-
- uint8_t value = 0;
-
- nnfw::util::tensor::iterate(tensor_view.shape())
- << [&](const nnfw::util::tensor::Index &ind) {
- // TODO Generate random values
- tensor_view.at(ind) = value;
- value = (value + 1) & 0xFF;
- };
- }
- else
- {
- assert(tensor->type == kTfLiteFloat32);
-
- const int seed = 1; /* TODO Add an option for seed value */
- RandomGenerator randgen{seed, 0.0f, 0.2f};
- const float *end = reinterpret_cast<const float *>(tensor->data.raw_const + tensor->bytes);
- for (float *ptr = tensor->data.f; ptr < end; ptr++)
- {
- *ptr = randgen.generate<float>();
- }
- }
- }
- }
-
- TFLiteRun::TensorDumper tensor_dumper;
- // Must be called before `interpreter->Invoke()`
- tensor_dumper.addTensors(*interpreter, interpreter->inputs());
-
- std::cout << "input tensor indices = [";
- for (const auto &o : interpreter->inputs())
- {
- std::cout << o << ",";
- }
- std::cout << "]" << std::endl;
-
- nnfw::util::benchmark::measure(t_invoke) << [&sess](void) {
- if (!sess->run())
- {
- assert(0 && "run failed!");
- }
- };
-
- sess->teardown();
-
- // Must be called after `interpreter->Invoke()`
- tensor_dumper.addTensors(*interpreter, interpreter->outputs());
-
- std::cout << "output tensor indices = [";
- for (const auto &o : interpreter->outputs())
- {
- std::cout << o << "(";
-
- print_max_idx(interpreter->tensor(o)->data.f, interpreter->tensor(o)->bytes / sizeof(float));
-
- std::cout << "),";
- }
- std::cout << "]" << std::endl;
-
- std::cout << "Prepare takes " << t_prepare.count() / 1000.0 << " seconds" << std::endl;
- std::cout << "Invoke takes " << t_invoke.count() / 1000.0 << " seconds" << std::endl;
-
- if (!args.getDumpFilename().empty())
- {
- const std::string &dump_filename = args.getDumpFilename();
- tensor_dumper.dump(dump_filename);
- std::cout << "Input/output tensors have been dumped to file \"" << dump_filename << "\"."
- << std::endl;
- }
-
- if (!args.getCompareFilename().empty())
- {
- const std::string &compare_filename = args.getCompareFilename();
- std::cout << "========================================" << std::endl;
- std::cout << "Comparing the results with \"" << compare_filename << "\"." << std::endl;
- std::cout << "========================================" << std::endl;
-
- // TODO Code duplication (copied from RandomTestRunner)
-
- int tolerance = 1;
- nnfw::util::env::IntAccessor("TOLERANCE").access(tolerance);
-
- auto equals = [tolerance](float lhs, float rhs) {
- // NOTE Hybrid approach
- // TODO Allow users to set tolerance for absolute_epsilon_equal
- if (nnfw::util::fp32::absolute_epsilon_equal(lhs, rhs))
- {
- return true;
- }
-
- return nnfw::util::fp32::epsilon_equal(lhs, rhs, tolerance);
- };
-
- nnfw::util::tensor::Comparator comparator(equals);
- TfLiteInterpMatchApp app(comparator);
- bool res = true;
-
- for (const auto &o : interpreter->outputs())
- {
- auto expected = tensor_loader.get(o);
- auto obtained = nnfw::support::tflite::TensorView<float>::make(*interpreter, o);
-
- res = res && app.compareSingleTensorView(expected, obtained, o);
- }
-
- if (!res)
- {
- return 255;
- }
- }
-
- return 0;
-}
diff --git a/tools/tflite_run/src/tflite_test.cc b/tools/tflite_run/src/tflite_test.cc
deleted file mode 100644
index d0d36c229..000000000
--- a/tools/tflite_run/src/tflite_test.cc
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "gtest/gtest.h"
-
-TEST(TFLite_test_case, simple_test) { EXPECT_EQ(1, 1); }
diff --git a/tools/tflitefile_tool/model_parser.py b/tools/tflitefile_tool/model_parser.py
index b8967d33f..0edabbba1 100755
--- a/tools/tflitefile_tool/model_parser.py
+++ b/tools/tflitefile_tool/model_parser.py
@@ -1,4 +1,19 @@
#!/usr/bin/python
+
+# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
import os
import sys
import numpy
@@ -13,6 +28,7 @@ import tflite.Model
import tflite.SubGraph
import argparse
from operator_parser import OperatorParser
+from model_printer import ModelPrinter
from perf_predictor import PerfPredictor
@@ -22,7 +38,6 @@ class TFLiteModelFileParser(object):
self.tflite_file = args.input_file
# Set print level (0 ~ 2)
- # TODO: print information based on level
self.print_level = args.verbose
if (args.verbose > 2):
self.print_level = 2
@@ -30,33 +45,34 @@ class TFLiteModelFileParser(object):
self.print_level = 0
# Set tensor index list to print information
- # TODO:
- # Print tensors in list only
- # Print all tensors if argument used and not specified index number
+ self.print_all_tensor = True
if (args.tensor != None):
- if (len(args.tensor) == 0):
- self.print_all_tensor = True
- else:
+ if (len(args.tensor) != 0):
self.print_all_tensor = False
self.print_tensor_index = []
-
for tensor_index in args.tensor:
self.print_tensor_index.append(int(tensor_index))
# Set operator index list to print information
- # TODO:
- # Print operators in list only
- # Print all operators if argument used and not specified index number
+ self.print_all_operator = True
if (args.operator != None):
- if (len(args.operator) == 0):
- self.print_all_oeprator = True
- else:
- self.print_all_oeprator = False
+ if (len(args.operator) != 0):
+ self.print_all_operator = False
self.print_operator_index = []
-
for operator_index in args.operator:
self.print_operator_index.append(int(operator_index))
+ def PrintModel(self, model_name, op_parser):
+ printer = ModelPrinter(self.print_level, op_parser, model_name)
+
+ if self.print_all_tensor == False:
+ printer.SetPrintSpecificTensors(self.print_tensor_index)
+
+ if self.print_all_operator == False:
+ printer.SetPrintSpecificOperators(self.print_operator_index)
+
+ printer.PrintInfo()
+
def main(self):
# Generate Model: top structure of tflite model file
buf = self.tflite_file.read()
@@ -71,19 +87,12 @@ class TFLiteModelFileParser(object):
if (subgraph_index != 0):
model_name = "Model #" + str(subgraph_index)
- print("[" + model_name + "]\n")
-
- # Model inputs & outputs
- model_inputs = tf_subgraph.InputsAsNumpy()
- model_outputs = tf_subgraph.OutputsAsNumpy()
-
- print(model_name + " input tensors: " + str(model_inputs))
- print(model_name + " output tensors: " + str(model_outputs))
-
- # Parse Operators and print all of operators
+ # Parse Operators
op_parser = OperatorParser(tf_model, tf_subgraph, PerfPredictor())
op_parser.Parse()
- op_parser.PrintAll()
+
+ # print all of operators or requested objects
+ self.PrintModel(model_name, op_parser)
if __name__ == '__main__':
@@ -92,11 +101,7 @@ if __name__ == '__main__':
arg_parser.add_argument(
"input_file", type=argparse.FileType('rb'), help="tflite file to read")
arg_parser.add_argument(
- '-v',
- '--verbose',
- action='count',
- default=0,
- help="set print level (0~2, default: 0)")
+ '-v', '--verbose', type=int, default=1, help="set print level (0~2, default: 1)")
arg_parser.add_argument(
'-t', '--tensor', nargs='*', help="tensor ID to print information (default: all)")
arg_parser.add_argument(
diff --git a/tools/tflitefile_tool/model_printer.py b/tools/tflitefile_tool/model_printer.py
new file mode 100644
index 000000000..ad06fa7a7
--- /dev/null
+++ b/tools/tflitefile_tool/model_printer.py
@@ -0,0 +1,142 @@
+#!/usr/bin/python
+
+# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from operator_printer import OperatorPrinter
+from tensor_printer import TensorPrinter
+
+
+class ModelPrinter(object):
+ def __init__(self, verbose, op_parser, model_name):
+ self.verbose = verbose
+ self.op_parser = op_parser
+ self.model_name = model_name
+ self.print_all_tensor = True
+ self.print_tensor_index_list = None
+ self.print_all_operator = True
+ self.print_operator_index_list = None
+
+ def SetPrintSpecificTensors(self, tensor_indices):
+ if len(tensor_indices) != 0:
+ self.print_all_tensor = False
+ self.print_tensor_index_list = tensor_indices
+
+ def SetPrintSpecificOperators(self, operator_indices):
+ if len(operator_indices) != 0:
+ self.print_all_operator = False
+ self.print_operator_index_list = operator_indices
+
+ def PrintInfo(self):
+ if self.print_all_tensor == True and self.print_all_operator == True:
+ self.PrintModelInfo()
+ self.PrintAllOperatorsInList()
+ self.PrintAllTypesInfo()
+ self.PrintTotalMemory()
+
+ if self.print_all_tensor == False:
+ print('')
+ self.PrintSpecificTensors()
+
+ if self.print_all_operator == False:
+ print('')
+ self.PrintSpecificOperators()
+
+ def PrintModelInfo(self):
+ print("[" + self.model_name + "]\n")
+ if self.verbose > 0:
+ model_inputs = self.op_parser.tf_subgraph.InputsAsNumpy()
+ model_outputs = self.op_parser.tf_subgraph.OutputsAsNumpy()
+ print(self.model_name + " input tensors: " + str(model_inputs))
+ print(self.model_name + " output tensors: " + str(model_outputs))
+ print('')
+
+ def PrintAllOperatorsInList(self):
+ if (self.verbose < 1):
+ return
+
+ for operator in self.op_parser.operators_in_list:
+ printer = OperatorPrinter(self.verbose, operator)
+ printer.PrintInfo(self.op_parser.perf_predictor)
+ print('')
+
+ print('')
+
+ def PrintAllTypesInfo(self):
+ print("Number of all operator types: {0}".format(
+ len(self.op_parser.operators_per_type)))
+
+ # number of instructions of all operator types to print if verbose level is 2
+ total_instrs = 0
+
+ # (a string of the operator type, a list of operators which are the same operator type)
+ for type_str, oper_list in self.op_parser.operators_per_type.items():
+ # number of occurrence of this operator type
+ occur = len(oper_list)
+
+ optype_info_str = "\t{type_str:38}: {occur:4}".format(
+ type_str=type_str, occur=occur)
+
+ if self.verbose == 2:
+ # this operator type can be computed?
+ can_compute = oper_list[0].operation.can_compute
+
+ # total number of instructions of the same operator types
+ if can_compute:
+ instrs = sum(
+ operator.operation.TotalInstrNum() for operator in oper_list)
+ total_instrs = total_instrs + instrs
+ instrs = "{:,}".format(instrs)
+ else:
+ instrs = "???"
+
+ optype_info_str = optype_info_str + " \t (instrs: {instrs})".format(
+ instrs=instrs)
+
+ print(optype_info_str)
+
+ summary_str = "{0:46}: {1:4}".format("Number of all operators",
+ len(self.op_parser.operators_in_list))
+ if self.verbose == 2:
+ total_instrs = "{:,}".format(total_instrs)
+ summary_str = summary_str + " \t (total instrs: {0})".format(total_instrs)
+
+ print(summary_str)
+ print('')
+
+ def PrintSpecificTensors(self):
+ for tensor in self.op_parser.GetAllTensors():
+ if tensor.tensor_idx in self.print_tensor_index_list:
+ printer = TensorPrinter(self.verbose, tensor)
+ printer.PrintInfo()
+ print('')
+ print('')
+
+ def PrintSpecificOperators(self):
+ for operator in self.op_parser.operators_in_list:
+ if operator.operator_idx in self.print_operator_index_list:
+ printer = OperatorPrinter(self.verbose, operator)
+ printer.PrintInfo(self.op_parser.perf_predictor)
+ print('')
+
+ print('')
+
+ def PrintTotalMemory(self):
+ total_memory = 0
+ for tensor in self.op_parser.GetAllTensors():
+ total_memory += tensor.memory_size
+
+ from tensor_printer import ConvertBytesToHuman
+ print("Expected total memory for allocating all tensors: {0}".format(
+ ConvertBytesToHuman(total_memory)))
diff --git a/tools/tflitefile_tool/operation.py b/tools/tflitefile_tool/operation.py
index 77fc5db9a..127d6c566 100755
--- a/tools/tflitefile_tool/operation.py
+++ b/tools/tflitefile_tool/operation.py
@@ -1,5 +1,19 @@
#!/usr/bin/python
+# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
import tflite.Conv2DOptions
import tflite.Pool2DOptions
import tflite.BuiltinOptions
diff --git a/tools/tflitefile_tool/operator_parser.py b/tools/tflitefile_tool/operator_parser.py
index 9728d53b7..71b1a6d93 100755
--- a/tools/tflitefile_tool/operator_parser.py
+++ b/tools/tflitefile_tool/operator_parser.py
@@ -1,5 +1,19 @@
#!/usr/bin/python
+# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
import tflite.Model
import tflite.SubGraph
import tflite.Operator
@@ -62,6 +76,18 @@ class OperatorParser(object):
return_list.append(Tensor(tensor_idx, tf_tensor, tf_buffer))
return return_list
+ def GetAllTensors(self):
+ return_list = list()
+ for tensor_idx in range(self.tf_subgraph.TensorsLength()):
+ if (tensor_idx < 0):
+ return_list.append(Tensor(tensor_idx, 0, 0))
+ continue
+ tf_tensor = self.tf_subgraph.Tensors(tensor_idx)
+ buffer_idx = tf_tensor.Buffer()
+ tf_buffer = self.tf_model.Buffers(buffer_idx)
+ return_list.append(Tensor(tensor_idx, tf_tensor, tf_buffer))
+ return return_list
+
def AppendOperator(self, operator):
self.operators_in_list.append(operator)
@@ -69,45 +95,3 @@ class OperatorParser(object):
if opcode_str not in self.operators_per_type:
self.operators_per_type[opcode_str] = list()
self.operators_per_type[opcode_str].append(operator)
-
- def PrintAll(self):
- print('')
- self.PrintAllOperatorsInList()
- print('')
- self.PrintAllTypesInfo()
- print('')
-
- def PrintAllOperatorsInList(self):
- for operator in self.operators_in_list:
- operator.PrintInfo(self.perf_predictor)
- print('')
-
- def PrintAllTypesInfo(self):
- print("Number of all operator types: {0}".format(len(self.operators_per_type)))
-
- # number of instructions of all operator types
- total_instrs = 0
-
- # (a string of the operator type, a list of operators which are the same operator type)
- for type_str, oper_list in self.operators_per_type.items():
- # this operator type can be computed?
- can_compute = oper_list[0].operation.can_compute
-
- # number of occurrence of this operator type
- occur = len(oper_list)
-
- # total number of instructions of the same operator types
- if can_compute:
- instrs = sum(operator.operation.TotalInstrNum() for operator in oper_list)
- total_instrs = total_instrs + instrs
- instrs = "{:,}".format(instrs)
- else:
- instrs = "???"
-
- print("\t{type_str:38}: {occur:4} \t (instrs: {instrs})".format(
- type_str=type_str, occur=occur, instrs=instrs))
-
- total_instrs = "{:,}".format(total_instrs)
- print("{0:46}: {1:4} \t (total instrs: {2})".format("Number of all operators",
- len(self.operators_in_list),
- total_instrs))
diff --git a/tools/tflitefile_tool/operator_printer.py b/tools/tflitefile_tool/operator_printer.py
new file mode 100644
index 000000000..9b6f97d24
--- /dev/null
+++ b/tools/tflitefile_tool/operator_printer.py
@@ -0,0 +1,72 @@
+#!/usr/bin/python
+
+# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from operator_wrapping import Operator
+from tensor_printer import TensorPrinter
+from option_printer import OptionPrinter
+from perf_predictor import PerfPredictor
+
+
+def GetStrTensorIndex(tensors):
+ return_string = "["
+ for idx in range(len(tensors)):
+ if idx != 0:
+ return_string += ", "
+ return_string += str(tensors[idx].tensor_idx)
+ return_string += "]"
+ return return_string
+
+
+class OperatorPrinter(object):
+ def __init__(self, verbose, operator):
+ self.verbose = verbose
+ self.operator = operator
+
+ def PrintInfo(self, perf_predictor=None):
+ if (self.verbose < 1):
+ return
+
+ op_str = "Operator {0}: {1}".format(self.operator.operator_idx,
+ self.operator.opcode_str)
+
+ if self.verbose == 2:
+ # total instruction num
+ instrs = "{:,}".format(self.operator.operation.TotalInstrNum()
+ ) if self.operator.operation.can_compute else "???"
+
+ # total operation cycles
+ cycles = "{:,}".format(
+ (perf_predictor.PredictCycles(self.operator.operation))
+ ) if self.operator.operation.can_compute and perf_predictor != None else "???"
+
+ op_str = op_str + "(instrs: {0}, cycls: {1})".format(instrs, cycles)
+
+ print(op_str)
+ print("\tFused Activation: " + self.operator.fused_activation)
+ self.PrintTensors()
+
+ def PrintTensors(self):
+ print("\tInput Tensors" + GetStrTensorIndex(self.operator.inputs))
+ for tensor in self.operator.inputs:
+ TensorPrinter(self.verbose, tensor).PrintInfo("\t\t")
+ print("\tOutput Tensors" + GetStrTensorIndex(self.operator.outputs))
+ for tensor in self.operator.outputs:
+ TensorPrinter(self.verbose, tensor).PrintInfo("\t\t")
+
+ # operator option
+ # Some operations does not have option. In such case no option is printed
+ OptionPrinter(self.verbose, self.operator.opcode_str,
+ self.operator.options).PrintInfo("\t")
diff --git a/tools/tflitefile_tool/operator_wrapping.py b/tools/tflitefile_tool/operator_wrapping.py
index 1b7f55a4c..64bad1f08 100755
--- a/tools/tflitefile_tool/operator_wrapping.py
+++ b/tools/tflitefile_tool/operator_wrapping.py
@@ -1,12 +1,24 @@
#!/usr/bin/python
+# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
import tflite.Operator
import tflite.OperatorCode
import tflite.BuiltinOperator
import tflite.ActivationFunctionType
-from tensor_wrapping import Tensor
from operation import Operation
-from perf_predictor import PerfPredictor
# Match enum value integer to name string
@@ -30,16 +42,6 @@ class EnumStrMaps():
BuiltinOptions = BuildEnumClassStrMap(tflite.BuiltinOptions.BuiltinOptions())
-def GetStrTensorIndex(tensors):
- return_string = "["
- for idx in range(len(tensors)):
- if idx != 0:
- return_string += ", "
- return_string += str(tensors[idx].tensor_idx)
- return_string += "]"
- return return_string
-
-
def GetAttribute(o, *args):
import functools
return functools.reduce(getattr, args, o)
@@ -64,6 +66,11 @@ class OptionLoader:
@staticmethod
def GetBuiltinOptions(options_type, options_table):
+ if (options_table == None) and (options_type != 0):
+ print(
+ "Bad flatbuffer file: undefined builtin option table with defined option type"
+ )
+ exit(1)
options = OptionLoader.builtinOptionGen[options_type]()
options.Init(options_table.Bytes, options_table.Pos)
return options
@@ -79,30 +86,19 @@ class Operator(object):
self.opcode_str = opcode_str
self.operation = Operation(self.tf_operator, self.opcode_str, self.inputs,
self.outputs)
+ self.fused_activation = "NONE"
+ self.SetupBuiltinOption()
+ self.SetupFusedActivation()
- def PrintInfo(self, perf_predictor=None):
- # total instruction num
- instrs = "{:,}".format(
- self.operation.TotalInstrNum()) if self.operation.can_compute else "???"
-
- # total operation cycles
- cycles = "{:,}".format(
- (perf_predictor.PredictCycles(self.operation)
- )) if self.operation.can_compute and perf_predictor != None else "???"
-
- print("Operator {0}: {1} (instrs: {2}, cycls: {3})".format(
- self.operator_idx, self.opcode_str, instrs, cycles))
-
- self.PrintOptionInfo()
-
- print("\tInput Tensors" + GetStrTensorIndex(self.inputs))
- for tensor in self.inputs:
- tensor.PrintInfo("\t\t")
- print("\tOutput Tensors" + GetStrTensorIndex(self.outputs))
- for tensor in self.outputs:
- tensor.PrintInfo("\t\t")
+ def SetupBuiltinOption(self):
+ try:
+ self.options = OptionLoader.GetBuiltinOptions(
+ self.tf_operator.BuiltinOptionsType(), self.tf_operator.BuiltinOptions())
+ except KeyError:
+ self.options = 0
+ return
- def PrintOptionInfo(self):
+ def SetupFusedActivation(self):
# FIXME: workaround for ops such as custom
try:
options = OptionLoader.GetBuiltinOptions(
@@ -113,8 +109,7 @@ class Operator(object):
# fused activation function
try:
activation_code = options.FusedActivationFunction()
- fused_activation = EnumStrMaps.ActivationFunctionType[activation_code]
- print("\tFused Activation: " + fused_activation)
+ self.fused_activation = EnumStrMaps.ActivationFunctionType[activation_code]
except AttributeError:
# This operator does not support FusedActivationFunction
pass
diff --git a/tools/tflitefile_tool/option_printer.py b/tools/tflitefile_tool/option_printer.py
new file mode 100644
index 000000000..08754f1ce
--- /dev/null
+++ b/tools/tflitefile_tool/option_printer.py
@@ -0,0 +1,69 @@
+#!/usr/bin/python
+
+# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+class OptionPrinter(object):
+ def __init__(self, verbose, op_name, options):
+ self.verbose = verbose
+ self.op_name = op_name
+ self.options = options
+
+ def GetPadding(self):
+ if self.options.Padding() == 0:
+ return "SAME"
+ elif self.options.Padding() == 1:
+ return "VALID"
+ else:
+ return "** wrong padding value **"
+
+ def PrintInfo(self, tab=""):
+ if (self.verbose < 1):
+ pass
+ if (self.options == 0):
+ return
+
+ if (self.op_name == "AVERAGE_POOL_2D" or self.op_name == "MAX_POOL_2D"):
+ print("{}Options".format(tab))
+
+ print("{}\t{}, {}, {}".format(
+ tab, "Filter W:H = {}:{}".format(self.options.FilterWidth(),
+ self.options.FilterHeight()),
+ "Stride W:H = {}:{}".format(self.options.StrideW(),
+ self.options.StrideH()),
+ "Padding = {}".format(self.GetPadding())))
+
+ elif (self.op_name == "CONV_2D"):
+ print("{}Options".format(tab))
+
+ print("{}\t{}, {}, {}".format(
+ tab, "Stride W:H = {}:{}".format(self.options.StrideW(),
+ self.options.StrideH()),
+ "Dilation W:H = {}:{}".format(self.options.DilationWFactor(),
+ self.options.DilationHFactor()),
+ "Padding = {}".format(self.GetPadding())))
+
+ elif (self.op_name == "DEPTHWISE_CONV_2D"):
+ print("{}Options".format(tab))
+
+ # yapf: disable
+ print("{}\t{}, {}, {}, {}".format(
+ tab, "Stride W:H = {}:{}".format(self.options.StrideW(),
+ self.options.StrideH()),
+ "Dilation W:H = {}:{}".format(self.options.DilationWFactor(),
+ self.options.DilationHFactor()),
+ "Padding = {}".format(self.GetPadding()),
+ "DepthMultiplier = {}".format(self.options.DepthMultiplier())))
+ # yapf: enable
diff --git a/tools/tflitefile_tool/perf_predictor.py b/tools/tflitefile_tool/perf_predictor.py
index 8880c8e71..ea5c15a33 100755
--- a/tools/tflitefile_tool/perf_predictor.py
+++ b/tools/tflitefile_tool/perf_predictor.py
@@ -1,5 +1,18 @@
#!/usr/bin/python
+# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
from operation import Operation
diff --git a/tools/tflitefile_tool/select_operator.py b/tools/tflitefile_tool/select_operator.py
index 55ca1acd9..c5d311d59 100755..100644
--- a/tools/tflitefile_tool/select_operator.py
+++ b/tools/tflitefile_tool/select_operator.py
@@ -1,4 +1,19 @@
#!/usr/bin/python
+
+# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
import os
import sys
import numpy
@@ -61,8 +76,8 @@ def GenerateOperatorCodes(new_builder, sample_model, used_operators_dic):
if operator_code_idx in used_operators_dic:
operator_code = sample_model.OperatorCodes(operator_code_idx)
operator_code_string = operator_code.CustomCode()
- if (operator_code_string !=
- "") and (not operator_code_string in new_operator_code_string_list):
+ if operator_code_string and (operator_code_string != "") and (
+ not operator_code_string in new_operator_code_string_list):
new_operator_code_string_list[
operator_code_string] = new_builder.CreateString(operator_code_string)
@@ -209,26 +224,10 @@ def GenerateTensors(new_builder, selected_subgraph, used_tensors_dic, used_buffe
return new_builder.EndVector(new_tensor_num)
-import tflite.Conv2DOptions
-import tflite.DepthwiseConv2DOptions
-import tflite.Pool2DOptions
-import tflite.FullyConnectedOptions
-import tflite.SoftmaxOptions
-import tflite.ConcatenationOptions
-import tflite.ReshapeOptions
-import tflite.AddOptions
-import tflite.SubOptions
-import tflite.MulOptions
-import tflite.DivOptions
-import tflite.ResizeBilinearOptions
-import tflite.StridedSliceOptions
-import tflite.CastOptions
-import tflite.TopKV2Options
-import tflite.GatherOptions
-
-
def GenerateBuiltinOption(new_builder, selected_builtin_option, builtin_option_type):
+ # Conv2D option
+ import tflite.Conv2DOptions
if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().Conv2DOptions:
conv2d_options = tflite.Conv2DOptions.Conv2DOptions()
@@ -245,6 +244,8 @@ def GenerateBuiltinOption(new_builder, selected_builtin_option, builtin_option_t
new_builder, conv2d_options.FusedActivationFunction())
return tflite.Conv2DOptions.Conv2DOptionsEnd(new_builder)
+ # DepthwiseConv2D option
+ import tflite.DepthwiseConv2DOptions
if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions(
).DepthwiseConv2DOptions:
@@ -263,8 +264,17 @@ def GenerateBuiltinOption(new_builder, selected_builtin_option, builtin_option_t
new_builder, depthconv2d_option.DepthMultiplier())
tflite.DepthwiseConv2DOptions.DepthwiseConv2DOptionsAddFusedActivationFunction(
new_builder, depthconv2d_option.FusedActivationFunction())
+ tflite.DepthwiseConv2DOptions.DepthwiseConv2DOptionsAddDilationWFactor(
+ new_builder, depthconv2d_option.DilationWFactor())
+ tflite.DepthwiseConv2DOptions.DepthwiseConv2DOptionsAddDilationHFactor(
+ new_builder, depthconv2d_option.DilationHFactor())
return tflite.DepthwiseConv2DOptions.DepthwiseConv2DOptionsEnd(new_builder)
+ # ConcatEmbeddingsOptions: not supported
+ # LSHProjectionOptions: not supported
+
+ # Pool2DPOption
+ import tflite.Pool2DOptions
if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().Pool2DOptions:
pool2d_option = tflite.Pool2DOptions.Pool2DOptions()
@@ -282,6 +292,22 @@ def GenerateBuiltinOption(new_builder, selected_builtin_option, builtin_option_t
new_builder, pool2d_option.FusedActivationFunction())
return tflite.Pool2DOptions.Pool2DOptionsEnd(new_builder)
+ # SVDFOptions: not supported
+
+ # RNNOptions
+ import tflite.RNNOptions
+ if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().RNNOptions:
+
+ rnn_option = tflite.RNNOptions.RNNOptions()
+ rnn_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos)
+
+ tflite.RNNOptions.RNNOptionsStart(new_builder)
+ tflite.RNNOptions.RNNOptionsAddFusedActivationFunction(
+ new_builder, rnn_option.FusedActivationFunction())
+ return tflite.RNNOptions.RNNOptionsEnd(new_builder)
+
+ # FullyConnectedOptions
+ import tflite.FullyConnectedOptions
if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions(
).FullyConnectedOptions:
@@ -293,6 +319,8 @@ def GenerateBuiltinOption(new_builder, selected_builtin_option, builtin_option_t
new_builder, fc_option.FusedActivationFunction())
return tflite.FullyConnectedOptions.FullyConnectedOptionsEnd(new_builder)
+ # SoftmaxOptions
+ import tflite.SoftmaxOptions
if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().SoftmaxOptions:
softmax_option = tflite.SoftmaxOptions.SoftmaxOptions()
@@ -302,6 +330,8 @@ def GenerateBuiltinOption(new_builder, selected_builtin_option, builtin_option_t
tflite.SoftmaxOptions.SoftmaxOptionsAddBeta(new_builder, softmax_option.Beta())
return tflite.SoftmaxOptions.SoftmaxOptionsEnd(new_builder)
+ # ConcatenationOptions
+ import tflite.ConcatenationOptions
if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().ConcatenationOptions:
concat_option = tflite.ConcatenationOptions.ConcatenationOptions()
@@ -314,6 +344,72 @@ def GenerateBuiltinOption(new_builder, selected_builtin_option, builtin_option_t
new_builder, concat_option.FusedActivationFunction())
return tflite.ConcatenationOptions.ConcatenationOptionsEnd(new_builder)
+ # AddOptions
+ import tflite.AddOptions
+ if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().AddOptions:
+
+ add_option = tflite.AddOptions.AddOptions()
+ add_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos)
+
+ tflite.AddOptions.AddOptionsStart(new_builder)
+ tflite.AddOptions.AddOptionsAddFusedActivationFunction(
+ new_builder, add_option.FusedActivationFunction())
+ return tflite.AddOptions.AddOptionsEnd(new_builder)
+
+ # L2NormOptions
+ import tflite.L2NormOptions
+ if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().L2NormOptions:
+
+ l2norm_option = tflite.L2NormOptions.L2NormOptions()
+ l2norm_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos)
+
+ tflite.L2NormOptions.L2NormOptionsStart(new_builder)
+ tflite.L2NormOptions.L2NormOptionsAddFusedActivationFunction(
+ new_builder, l2norm_option.FusedActivationFunction())
+ return tflite.L2NormOptions.L2NormOptionsEnd(new_builder)
+
+ # LocalResponseNormalizationOptions
+ import tflite.LocalResponseNormalizationOptions
+ if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions(
+ ).LocalResponseNormalizationOptions:
+
+ lrn_option = tflite.LocalResponseNormalizationOptions.LocalResponseNormalizationOptions(
+ )
+ lrn_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos)
+
+ tflite.LocalResponseNormalizationOptions.LocalResponseNormalizationOptionsStart(
+ new_builder)
+ tflite.LocalResponseNormalizationOptions.LocalResponseNormalizationOptionsAddRadius(
+ new_builder, lrn_option.Radius())
+ tflite.LocalResponseNormalizationOptions.LocalResponseNormalizationOptionsAddBias(
+ new_builder, lrn_option.Bias())
+ tflite.LocalResponseNormalizationOptions.LocalResponseNormalizationOptionsAddAlpha(
+ new_builder, lrn_option.Alpha())
+ tflite.LocalResponseNormalizationOptions.LocalResponseNormalizationOptionsAddBeta(
+ new_builder, lrn_option.Beta())
+ return tflite.LocalResponseNormalizationOptions.LocalResponseNormalizationOptionsEnd(
+ new_builder)
+
+ # LSTMOptions: not supported
+
+ # ResizeBilinearOptions
+ import tflite.ResizeBilinearOptions
+ if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions(
+ ).ResizeBilinearOptions:
+
+ resize_bilinear_option = tflite.ResizeBilinearOptions.ResizeBilinearOptions()
+ resize_bilinear_option.Init(selected_builtin_option.Bytes,
+ selected_builtin_option.Pos)
+
+ tflite.ResizeBilinearOptions.ResizeBilinearOptionsStart(new_builder)
+ tflite.ResizeBilinearOptions.ResizeBilinearOptionsAddAlignCorners(
+ new_builder, resize_bilinear_option.AlignCorners())
+ return tflite.ResizeBilinearOptions.ResizeBilinearOptionsEnd(new_builder)
+
+ # CallOptions: not supported
+
+ # ReshapeOptions
+ import tflite.ReshapeOptions
if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().ReshapeOptions:
reshape_option = tflite.ReshapeOptions.ReshapeOptions()
@@ -333,26 +429,25 @@ def GenerateBuiltinOption(new_builder, selected_builtin_option, builtin_option_t
tflite.ReshapeOptions.ReshapeOptionsAddNewShape(new_builder, new_shape)
return tflite.ReshapeOptions.ReshapeOptionsEnd(new_builder)
- if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().AddOptions:
-
- add_option = tflite.AddOptions.AddOptions()
- add_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos)
+ # SkipGramOptions: not supported
- tflite.AddOptions.AddOptionsStart(new_builder)
- tflite.AddOptions.AddOptionsAddFusedActivationFunction(
- new_builder, add_option.FusedActivationFunction())
- return tflite.AddOptions.AddOptionsEnd(new_builder)
+ # SpaceToDepthOptions
+ import tflite.SpaceToDepthOptions
+ if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().SpaceToDepthOptions:
- if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().SubOptions:
+ space_to_depth_option = tflite.SpaceToDepthOptions.SpaceToDepthOptions()
+ space_to_depth_option.Init(selected_builtin_option.Bytes,
+ selected_builtin_option.Pos)
- sub_option = tflite.SubOptions.SubOptions()
- sub_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos)
+ tflite.SpaceToDepthOptions.SpaceToDepthOptionsStart(new_builder)
+ tflite.SpaceToDepthOptions.SpaceToDepthOptionsAddBlockSize(
+ new_builder, space_to_depth_option.BlockSize())
+ return tflite.SpaceToDepthOptions.SpaceToDepthOptionsEnd(new_builder)
- tflite.SubOptions.SubOptionsStart(new_builder)
- tflite.SubOptions.SubOptionsAddFusedActivationFunction(
- new_builder, sub_option.FusedActivationFunction())
- return tflite.SubOptions.SubOptionsEnd(new_builder)
+ # EmbeddingLookupSparseOptions: not supported
+ # MulOptions
+ import tflite.MulOptions
if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().MulOptions:
mul_option = tflite.MulOptions.MulOptions()
@@ -363,6 +458,85 @@ def GenerateBuiltinOption(new_builder, selected_builtin_option, builtin_option_t
new_builder, mul_option.FusedActivationFunction())
return tflite.MulOptions.MulOptionsEnd(new_builder)
+ # PadOptions
+ import tflite.PadOptions
+ if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().PadOptions:
+
+ pad_option = tflite.PadOptions.PadOptions()
+ pad_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos)
+
+ tflite.PadOptions.PadOptionsStart(new_builder)
+ return tflite.PadOptions.PadOptionsEnd(new_builder)
+
+ # GatherOptions
+ import tflite.GatherOptions
+ if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().GatherOptions:
+
+ gather_option = tflite.GatherOptions.GatherOptions()
+ gather_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos)
+
+ tflite.GatherOptions.GatherOptionsStart(new_builder)
+ tflite.GatherOptions.GatherOptionsAddAxis(new_builder, gather_option.Axis())
+ return tflite.GatherOptions.GatherOptionsEnd(new_builder)
+
+ # BatchToSpaceNDOptions
+ import tflite.BatchToSpaceNDOptions
+ if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions(
+ ).BatchToSpaceNDOptions:
+
+ btsnd_option = tflite.BatchToSpaceNDOptions.BatchToSpaceNDOptions()
+ btsnd_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos)
+
+ tflite.BatchToSpaceNDOptions.BatchToSpaceNDOptionsStart(new_builder)
+ return tflite.BatchToSpaceNDOptions.BatchToSpaceNDOptionsEnd(new_builder)
+
+ # SpaceToBatchNDOptions
+ import tflite.SpaceToBatchNDOptions
+ if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions(
+ ).SpaceToBatchNDOptions:
+
+ stbnd_option = tflite.SpaceToBatchNDOptions.SpaceToBatchNDOptions()
+ stbnd_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos)
+
+ tflite.SpaceToBatchNDOptions.SpaceToBatchNDOptionsStart(new_builder)
+ return tflite.SpaceToBatchNDOptions.SpaceToBatchNDOptionsEnd(new_builder)
+
+ # TransposeOptions:
+ import tflite.TransposeOptions
+ if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().TransposeOptions:
+
+ transpose_option = tflite.TransposeOptions.TransposeOptions()
+ transpose_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos)
+
+ tflite.TransposeOptions.TransposeOptionsStart(new_builder)
+ return tflite.TransposeOptions.TransposeOptionsEnd(new_builder)
+
+ # ReducerOptions
+ import tflite.ReducerOptions
+ if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().ReducerOptions:
+
+ reducer_option = tflite.ReducerOptions.ReducerOptions()
+ reducer_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos)
+
+ tflite.ReducerOptions.ReducerOptionsStart(new_builder)
+ tflite.ReducerOptions.ReducerOptionsAddKeepDims(new_builder,
+ reducer_option.KeepDims())
+ return tflite.ReducerOptions.ReducerOptionsEnd(new_builder)
+
+ # SubOptions
+ import tflite.SubOptions
+ if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().SubOptions:
+
+ sub_option = tflite.SubOptions.SubOptions()
+ sub_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos)
+
+ tflite.SubOptions.SubOptionsStart(new_builder)
+ tflite.SubOptions.SubOptionsAddFusedActivationFunction(
+ new_builder, sub_option.FusedActivationFunction())
+ return tflite.SubOptions.SubOptionsEnd(new_builder)
+
+ # DivOptions
+ import tflite.DivOptions
if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().DivOptions:
div_option = tflite.DivOptions.DivOptions()
@@ -373,18 +547,32 @@ def GenerateBuiltinOption(new_builder, selected_builtin_option, builtin_option_t
new_builder, div_option.FusedActivationFunction())
return tflite.DivOptions.DivOptionsEnd(new_builder)
- if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions(
- ).ResizeBilinearOptions:
+ # SqueezeOptions
+ import tflite.SqueezeOptions
+ if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().SqueezeOptions:
- resize_bilinear_option = tflite.ResizeBilinearOptions.ResizeBilinearOptions()
- resize_bilinear_option.Init(selected_builtin_option.Bytes,
- selected_builtin_option.Pos)
+ squeeze_option = tflite.SqueezeOptions.SqueezeOptions()
+ squeeze_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos)
- tflite.ResizeBilinearOptions.ResizeBilinearOptionsStart(new_builder)
- tflite.ResizeBilinearOptions.ResizeBilinearOptionsAddAlignCorners(
- new_builder, resize_bilinear_option.AlignCorners())
- return tflite.ResizeBilinearOptions.ResizeBilinearOptionsEnd(new_builder)
+ squeeze_dims_num = squeeze_option.SqueezeDimsLength()
+ if squeeze_dims_num != 0:
+ tflite.SqueezeOptions.SqueezeOptionsStartSqueezeDimsVector(
+ new_builder, squeeze_dims_num)
+ for squeeze_dims_idx in reversed(range(squeeze_dims_num)):
+ squeeze_dims_val = squeeze_option.SqueezeDims(squeeze_dims_idx)
+ new_builder.PrependInt32(squeeze_dims_val)
+ new_squeeze_dims = new_builder.EndVector(squeeze_dims_num)
+
+ tflite.SqueezeOptions.SqueezeOptionsStart(new_builder)
+ if squeeze_dims_num != 0:
+ tflite.SqueezeOptions.SqueezeOptionsAddSqueezeDims(new_builder,
+ new_squeeze_dims)
+ return tflite.SqueezeOptions.SqueezeOptionsEnd(new_builder)
+
+ # SequenceRNNOptions: not supported
+ # StridedSliceOptions
+ import tflite.StridedSliceOptions
if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().StridedSliceOptions:
stride_slice_option = tflite.StridedSliceOptions.StridedSliceOptions()
@@ -405,14 +593,18 @@ def GenerateBuiltinOption(new_builder, selected_builtin_option, builtin_option_t
return tflite.StridedSliceOptions.StridedSliceOptionsEnd(new_builder)
- if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().CastOptions:
+ # ExpOptions
+ import tflite.ExpOptions
+ if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().ExpOptions:
- cast_option = tflite.CastOptions.CastOptions()
- cast_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos)
+ exp_option = tflite.ExpOptions.ExpOptions()
+ exp_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos)
- tflite.CastOptions.CastOptionsStart(new_builder)
- return tflite.CastOptions.CastOptionsEnd(new_builder)
+ tflite.ExpOptions.ExpOptionsStart(new_builder)
+ return tflite.ExpOptions.ExpOptionsEnd(new_builder)
+ # TopKV2Options
+ import tflite.TopKV2Options
if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().TopKV2Options:
topkv2_option = tflite.TopKV2Options.TopKV2Options()
@@ -421,17 +613,185 @@ def GenerateBuiltinOption(new_builder, selected_builtin_option, builtin_option_t
tflite.TopKV2Options.TopKV2OptionsStart(new_builder)
return tflite.TopKV2Options.TopKV2OptionsEnd(new_builder)
- if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().GatherOptions:
+ # SplitOptions
+ import tflite.SplitOptions
+ if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().SplitOptions:
- gather_option = tflite.GatherOptions.GatherOptions()
- gather_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos)
+ split_option = tflite.SplitOptions.SplitOptions()
+ split_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos)
- tflite.GatherOptions.GatherOptionsStart(new_builder)
- tflite.GatherOptions.GatherOptionsAddAxis(new_builder, gather_option.Axis())
- return tflite.GatherOptions.GatherOptionsEnd(new_builder)
+ tflite.SplitOptions.SplitOptionsStart(new_builder)
+ tflite.SplitOptions.SplitOptionsAddNumSplits(new_builder,
+ split_option.NumSplits())
+ return tflite.SplitOptions.SplitOptionsEnd(new_builder)
+
+ # LogSoftmaxOptions: not supported
+
+ # CastOptions: not supported
+ import tflite.CastOptions
+ if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().CastOptions:
+
+ cast_option = tflite.CastOptions.CastOptions()
+ cast_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos)
+
+ tflite.CastOptions.CastOptionsStart(new_builder)
+ return tflite.CastOptions.CastOptionsEnd(new_builder)
+
+ # DequantizeOptions:
+ import tflite.DequantizeOptions
+ if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().DequantizeOptions:
+
+ dequantize_option = tflite.DequantizeOptions.DequantizeOptions()
+ dequantize_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos)
+
+ tflite.EqualOptions.DequantizeOptionsStart(new_builder)
+ return tflite.DequantizeOptions.DequantizeOptionsEnd(new_builder)
+
+ # MaximumMinimumOptions: not supported
+
+ # ArgMaxOptions
+ import tflite.ArgMaxOptions
+ if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().ArgMaxOptions:
+
+ arg_max_option = tflite.ArgMaxOptions.ArgMaxOptions()
+ arg_max_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos)
+
+ tflite.ArgMaxOptions.ArgMaxOptionsStart(new_builder)
+ tflite.ArgMaxOptions.ArgMaxOptionsAddOutputType(new_builder,
+ arg_max_option.OutputType())
+ return tflite.ArgMaxOptions.ArgMaxOptionsEnd(new_builder)
+
+ # LessOptions: not supported
+
+ # NegOptions
+ import tflite.NegOptions
+ if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().NegOptions:
+
+ neg_option = tflite.NegOptions.NegOptions()
+ neg_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos)
+
+ tflite.NegOptions.NegOptionsStart(new_builder)
+ return tflite.NegOptions.NegOptionsEnd(new_builder)
+
+ # EqualOptions
+ import tflite.EqualOptions
+ if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().EqualOptions:
+
+ equal_option = tflite.EqualOptions.EqualOptions()
+ equal_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos)
+
+ tflite.EqualOptions.EqualOptionsStart(new_builder)
+ return tflite.EqualOptions.EqualOptionsEnd(new_builder)
+
+ # PadV2Options: not supported
+ # GreaterOptions: not supported
+ # GreaterEqualOptions: not supported
+ # LessEqualOptions: not supported
+ # SelectOptions: not supported
+ # SliceOptions: not supported
+
+ # TransposeConvOptions
+ import tflite.TransposeConvOptions
+ if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().TransposeConvOptions:
+
+ transposeconv_option = tflite.TransposeConvOptions.TransposeConvOptions()
+ transposeconv_option.Init(selected_builtin_option.Bytes,
+ selected_builtin_option.Pos)
+
+ tflite.TransposeConvOptions.TransposeConvOptionsStart(new_builder)
+ tflite.TransposeConvOptions.TransposeConvOptionsAddPadding(
+ new_builder, transposeconv_option.Padding())
+ tflite.TransposeConvOptions.TransposeConvOptionsAddStrideW(
+ new_builder, transposeconv_option.StrideW())
+ tflite.TransposeConvOptions.TransposeConvOptionsAddStrideH(
+ new_builder, transposeconv_option.StrideH())
+ return tflite.TransposeConvOptions.TransposeConvOptionsEnd(new_builder)
+
+ # SparseToDenseOptions: not supported
+ # TileOptions: not supported
+ # ExpandDimsOptions: not supported
+
+ # NotEqualOptions:
+ import tflite.NotEqualOptions
+ if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().NotEqualOptions:
+
+ notequal_option = tflite.NotEqualOptions.NotEqualOptions()
+ notequal_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos)
+
+ tflite.NotEqualOptions.NotEqualOptionsStart(new_builder)
+ return tflite.NotEqualOptions.NotEqualOptionsEnd(new_builder)
+
+ # ShapeOptions: not supported
+ # PowOptions: not supported
+ # ArgMinOptions: not supported
+ # FakeQuantOptions: not supported
+
+ # PackOptions:
+ import tflite.PackOptions
+ if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().PackOptions:
+
+ pack_option = tflite.PackOptions.PackOptions()
+ pack_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos)
+
+ tflite.PackOptions.PackOptionsStart(new_builder)
+ tflite.PackOptions.PackOptionsAddValuesCount(new_builder,
+ pack_option.ValuesCount())
+ tflite.PackOptions.PackOptionsAddAxis(new_builder, pack_option.Axis())
+ return tflite.PackOptions.PackOptionsEnd(new_builder)
+
+ # LogicalOrOptions:
+ import tflite.LogicalOrOptions
+ if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().LogicalOrOptions:
+
+ logical_or_option = tflite.LogicalAndOptions.LogicalOrOptions()
+ logical_or_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos)
+
+ tflite.LogicalOrOptions.LogicalOrOptionsStart(new_builder)
+ return tflite.LogicalOrOptions.LogicalOrOptionsEnd(new_builder)
+
+ # OneHotOptions: not supported
+
+ # LogicalNotOptions
+ import tflite.LogicalNotOptions
+ if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().LogicalNotOptions:
+
+ equal_option = tflite.LogicalNotOptions.LogicalNotOptions()
+ equal_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos)
+
+ tflite.LogicalNotOptions.LogicalNotOptionsStart(new_builder)
+ return tflite.LogicalNotOptions.LogicalNotOptionsEnd(new_builder)
+
+ # UnpackOptions:
+ import tflite.UnpackOptions
+ if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().UnpackOptions:
+
+ unpack_option = tflite.unpackOptions.unpackOptions()
+ unpack_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos)
+
+ tflite.unpackOptions.UnpackOptionsStart(new_builder)
+ tflite.unpackOptions.UnpackOptionsAddNum(new_builder, unpack_option.Num())
+ tflite.PackOptions.UnpackOptionsAddAxis(new_builder, unpack_option.Axis())
+ return tflite.UnpackOptions.UnpackOptionsEnd(new_builder)
+
+ # FloorDivOptions: not supported
+ # SquareOptions: not supported
+ # ZerosLikeOptions: not supported
+ # FillOptions: not supported
+
+ # LogicalAndOptions
+ import tflite.LogicalAndOptions
+ if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().LogicalAndOptions:
+
+ logical_and_option = tflite.LogicalAndOptions.LogicalAndOptions()
+ logical_and_option.Init(selected_builtin_option.Bytes,
+ selected_builtin_option.Pos)
+
+ tflite.LogicalAndOptions.LogicalAndOptionsStart(new_builder)
+ return tflite.LogicalAndOptions.LogicalAndOptionsEnd(new_builder)
# Cannot handle builtin option type yet
- return 0
+ print("Cannot handle this option yet")
+ exit(1)
def GenerateOperator(new_builder, selected_operator, used_tensors_dic,
@@ -556,7 +916,7 @@ def GenerateSubgraph(new_builder, selected_subgraph, opcode_list, new_input_tens
# Name
subgraph_name = selected_subgraph.Name()
have_name = False
- if subgraph_name != "":
+ if subgraph_name and subgraph_name != "":
have_name = True
new_subgraph_name = new_builder.CreateString(subgraph_name)
diff --git a/tools/tflitefile_tool/tensor_printer.py b/tools/tflitefile_tool/tensor_printer.py
new file mode 100644
index 000000000..f566a6e10
--- /dev/null
+++ b/tools/tflitefile_tool/tensor_printer.py
@@ -0,0 +1,80 @@
+#!/usr/bin/python
+
+# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from tensor_wrapping import Tensor
+
+SYMBOLS = ['B', 'K', 'M', 'G', 'T']
+
+
+def ConvertBytesToHuman(n):
+ n = int(n)
+ if n < 0:
+ return 0
+
+ format_str = "%(val)3.1f%(symb)s"
+ prefix = {}
+ for i, s in enumerate(SYMBOLS[1:]):
+ prefix[s] = 1 << (i + 1) * 10
+
+ for symbol in reversed(SYMBOLS[1:]):
+ if n >= prefix[symbol]:
+ v = float(n) / prefix[symbol]
+ return format_str % dict(symb=symbol, val=v)
+
+ return format_str % dict(symb=SYMBOLS[0], val=n)
+
+
+class TensorPrinter(object):
+ def __init__(self, verbose, tensor):
+ self.verbose = verbose
+ self.tensor = tensor
+
+ def PrintInfo(self, depth_str=""):
+ if (self.verbose < 1):
+ pass
+
+ print_str = ""
+ if self.tensor.tensor_idx < 0:
+ print_str = "Tensor {0:4}".format(self.tensor.tensor_idx)
+ else:
+ buffer_idx = self.tensor.tf_tensor.Buffer()
+ isEmpty = "Filled"
+ if (self.tensor.tf_buffer.DataLength() == 0):
+ isEmpty = " Empty"
+ shape_str = self.GetShapeString()
+ type_name = self.tensor.type_name
+
+ shape_name = ""
+ if self.tensor.tf_tensor.Name() != 0:
+ shape_name = self.tensor.tf_tensor.Name()
+
+ memory_size = ConvertBytesToHuman(self.tensor.memory_size)
+
+ print_str = "Tensor {0:4} : buffer {1:4} | {2} | {3:7} | Memory {4:6} | Shape {5} ({6})".format(
+ self.tensor.tensor_idx, buffer_idx, isEmpty, type_name, memory_size,
+ shape_str, shape_name)
+ print(depth_str + print_str)
+
+ def GetShapeString(self):
+ if self.tensor.tf_tensor.ShapeLength() == 0:
+ return "Scalar"
+ return_string = "["
+ for shape_idx in range(self.tensor.tf_tensor.ShapeLength()):
+ if (shape_idx != 0):
+ return_string += ", "
+ return_string += str(self.tensor.tf_tensor.Shape(shape_idx))
+ return_string += "]"
+ return return_string
diff --git a/tools/tflitefile_tool/tensor_wrapping.py b/tools/tflitefile_tool/tensor_wrapping.py
index b1fba57d2..a32a573ce 100755
--- a/tools/tflitefile_tool/tensor_wrapping.py
+++ b/tools/tflitefile_tool/tensor_wrapping.py
@@ -1,5 +1,19 @@
#!/usr/bin/python
+# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
import tflite.Tensor
import tflite.TensorType
@@ -16,39 +30,47 @@ def SetTensorTypeStr():
TensorTypeList[fieldValue] = fieldName
+TYPES = {
+ 'BOOL': 1,
+ 'COMPLEX64': 8,
+ 'FLOAT16': 2,
+ 'FLOAT32': 4,
+ 'INT16': 2,
+ 'INT32': 4,
+ 'INT64': 8,
+ 'UINT8': 1
+}
+
+
+def GetTypeSize(type_name):
+ try:
+ return TYPES[type_name]
+
+ except KeyError as error:
+ return 0
+
+
class Tensor(object):
def __init__(self, tensor_idx, tf_tensor, tf_buffer):
self.tensor_idx = tensor_idx
self.tf_tensor = tf_tensor
self.tf_buffer = tf_buffer
+ self.type_name = TensorTypeList[self.tf_tensor.Type()]
+ self.memory_size = self.GetMemorySize()
+
+ def GetMemorySize(self):
+ type_size = GetTypeSize(self.type_name)
+ if type_size == 0:
+ return 0
+
+ # memory size in bytes
+ size = int(type_size)
+ shape_length = self.tf_tensor.ShapeLength()
+ if shape_length == 0:
+ return size
+
+ for shape_idx in range(shape_length):
+ shape_size = int(self.tf_tensor.Shape(shape_idx))
+ size *= shape_size
- def PrintInfo(self, depth_str=""):
- print_str = ""
- if self.tensor_idx < 0:
- print_str = "Tensor {0:4}".format(self.tensor_idx)
- else:
- buffer_idx = self.tf_tensor.Buffer()
- isEmpty = "Filled"
- if (self.tf_buffer.DataLength() == 0):
- isEmpty = " Empty"
- shape_str = self.GetShapeString()
- type_name = TensorTypeList[self.tf_tensor.Type()]
-
- shape_name = ""
- if self.tf_tensor.Name() != 0:
- shape_name = self.tf_tensor.Name()
-
- print_str = "Tensor {0:4} : buffer {1:4} | {2} | {3:7} | Shape {4} ({5})".format(
- self.tensor_idx, buffer_idx, isEmpty, type_name, shape_str, shape_name)
- print(depth_str + print_str)
-
- def GetShapeString(self):
- if self.tf_tensor.ShapeLength() == 0:
- return "Scalar"
- return_string = "["
- for shape_idx in range(self.tf_tensor.ShapeLength()):
- if (shape_idx != 0):
- return_string += ", "
- return_string += str(self.tf_tensor.Shape(shape_idx))
- return_string += "]"
- return return_string
+ return size
diff --git a/tools/tflitefile_tool/tflite/BidirectionalSequenceRNNOptions.py b/tools/tflitefile_tool/tflite/BidirectionalSequenceRNNOptions.py
index 5c057b6bf..474ee4ba2 100644
--- a/tools/tflitefile_tool/tflite/BidirectionalSequenceRNNOptions.py
+++ b/tools/tflitefile_tool/tflite/BidirectionalSequenceRNNOptions.py
@@ -23,8 +23,9 @@ class BidirectionalSequenceRNNOptions(object):
def TimeMajor(self):
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
if o != 0:
- return self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos)
- return 0
+ return bool(
+ self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos))
+ return False
# BidirectionalSequenceRNNOptions
def FusedActivationFunction(self):
diff --git a/tools/tflitefile_tool/tflite/BuiltinOperator.py b/tools/tflitefile_tool/tflite/BuiltinOperator.py
index 2beda098e..8e2f9c680 100644
--- a/tools/tflitefile_tool/tflite/BuiltinOperator.py
+++ b/tools/tflitefile_tool/tflite/BuiltinOperator.py
@@ -84,3 +84,17 @@ class BuiltinOperator(object):
POW = 78
ARG_MIN = 79
FAKE_QUANT = 80
+ REDUCE_PROD = 81
+ REDUCE_MAX = 82
+ PACK = 83
+ LOGICAL_OR = 84
+ ONE_HOT = 85
+ LOGICAL_AND = 86
+ LOGICAL_NOT = 87
+ UNPACK = 88
+ REDUCE_MIN = 89
+ FLOOR_DIV = 90
+ REDUCE_ANY = 91
+ SQUARE = 92
+ ZEROS_LIKE = 93
+ FILL = 94
diff --git a/tools/tflitefile_tool/tflite/BuiltinOptions.py b/tools/tflitefile_tool/tflite/BuiltinOptions.py
index 5d3040839..7e1eb34ac 100644
--- a/tools/tflitefile_tool/tflite/BuiltinOptions.py
+++ b/tools/tflitefile_tool/tflite/BuiltinOptions.py
@@ -63,3 +63,13 @@ class BuiltinOptions(object):
PowOptions = 56
ArgMinOptions = 57
FakeQuantOptions = 58
+ PackOptions = 59
+ LogicalOrOptions = 60
+ OneHotOptions = 61
+ LogicalAndOptions = 62
+ LogicalNotOptions = 63
+ UnpackOptions = 64
+ FloorDivOptions = 65
+ SquareOptions = 66
+ ZerosLikeOptions = 67
+ FillOptions = 68
diff --git a/tools/tflitefile_tool/tflite/DepthwiseConv2DOptions.py b/tools/tflitefile_tool/tflite/DepthwiseConv2DOptions.py
index 9f0b3388f..786f7c53d 100644
--- a/tools/tflitefile_tool/tflite/DepthwiseConv2DOptions.py
+++ b/tools/tflitefile_tool/tflite/DepthwiseConv2DOptions.py
@@ -54,9 +54,23 @@ class DepthwiseConv2DOptions(object):
return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos)
return 0
+ # DepthwiseConv2DOptions
+ def DilationWFactor(self):
+ o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14))
+ if o != 0:
+ return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos)
+ return 1
+
+ # DepthwiseConv2DOptions
+ def DilationHFactor(self):
+ o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(16))
+ if o != 0:
+ return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos)
+ return 1
+
def DepthwiseConv2DOptionsStart(builder):
- builder.StartObject(5)
+ builder.StartObject(7)
def DepthwiseConv2DOptionsAddPadding(builder, padding):
@@ -79,5 +93,13 @@ def DepthwiseConv2DOptionsAddFusedActivationFunction(builder, fusedActivationFun
builder.PrependInt8Slot(4, fusedActivationFunction, 0)
+def DepthwiseConv2DOptionsAddDilationWFactor(builder, dilationWFactor):
+ builder.PrependInt32Slot(5, dilationWFactor, 1)
+
+
+def DepthwiseConv2DOptionsAddDilationHFactor(builder, dilationHFactor):
+ builder.PrependInt32Slot(6, dilationHFactor, 1)
+
+
def DepthwiseConv2DOptionsEnd(builder):
return builder.EndObject()
diff --git a/tools/tflitefile_tool/tflite/FakeQuantOptions.py b/tools/tflitefile_tool/tflite/FakeQuantOptions.py
index fc8023e60..c266bfc9d 100644
--- a/tools/tflitefile_tool/tflite/FakeQuantOptions.py
+++ b/tools/tflitefile_tool/tflite/FakeQuantOptions.py
@@ -44,8 +44,9 @@ class FakeQuantOptions(object):
def NarrowRange(self):
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10))
if o != 0:
- return self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos)
- return 0
+ return bool(
+ self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos))
+ return False
def FakeQuantOptionsStart(builder):
diff --git a/tools/tflitefile_tool/tflite/FillOptions.py b/tools/tflitefile_tool/tflite/FillOptions.py
new file mode 100644
index 000000000..ee6273514
--- /dev/null
+++ b/tools/tflitefile_tool/tflite/FillOptions.py
@@ -0,0 +1,28 @@
+# automatically generated by the FlatBuffers compiler, do not modify
+
+# namespace: tflite
+
+import flatbuffers
+
+
+class FillOptions(object):
+ __slots__ = ['_tab']
+
+ @classmethod
+ def GetRootAsFillOptions(cls, buf, offset):
+ n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
+ x = FillOptions()
+ x.Init(buf, n + offset)
+ return x
+
+ # FillOptions
+ def Init(self, buf, pos):
+ self._tab = flatbuffers.table.Table(buf, pos)
+
+
+def FillOptionsStart(builder):
+ builder.StartObject(0)
+
+
+def FillOptionsEnd(builder):
+ return builder.EndObject()
diff --git a/tools/tflitefile_tool/tflite/FloorDivOptions.py b/tools/tflitefile_tool/tflite/FloorDivOptions.py
new file mode 100644
index 000000000..90b797112
--- /dev/null
+++ b/tools/tflitefile_tool/tflite/FloorDivOptions.py
@@ -0,0 +1,28 @@
+# automatically generated by the FlatBuffers compiler, do not modify
+
+# namespace: tflite
+
+import flatbuffers
+
+
+class FloorDivOptions(object):
+ __slots__ = ['_tab']
+
+ @classmethod
+ def GetRootAsFloorDivOptions(cls, buf, offset):
+ n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
+ x = FloorDivOptions()
+ x.Init(buf, n + offset)
+ return x
+
+ # FloorDivOptions
+ def Init(self, buf, pos):
+ self._tab = flatbuffers.table.Table(buf, pos)
+
+
+def FloorDivOptionsStart(builder):
+ builder.StartObject(0)
+
+
+def FloorDivOptionsEnd(builder):
+ return builder.EndObject()
diff --git a/tools/tflitefile_tool/tflite/LogicalAndOptions.py b/tools/tflitefile_tool/tflite/LogicalAndOptions.py
new file mode 100644
index 000000000..84cdfd92a
--- /dev/null
+++ b/tools/tflitefile_tool/tflite/LogicalAndOptions.py
@@ -0,0 +1,28 @@
+# automatically generated by the FlatBuffers compiler, do not modify
+
+# namespace: tflite
+
+import flatbuffers
+
+
+class LogicalAndOptions(object):
+ __slots__ = ['_tab']
+
+ @classmethod
+ def GetRootAsLogicalAndOptions(cls, buf, offset):
+ n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
+ x = LogicalAndOptions()
+ x.Init(buf, n + offset)
+ return x
+
+ # LogicalAndOptions
+ def Init(self, buf, pos):
+ self._tab = flatbuffers.table.Table(buf, pos)
+
+
+def LogicalAndOptionsStart(builder):
+ builder.StartObject(0)
+
+
+def LogicalAndOptionsEnd(builder):
+ return builder.EndObject()
diff --git a/tools/tflitefile_tool/tflite/LogicalNotOptions.py b/tools/tflitefile_tool/tflite/LogicalNotOptions.py
new file mode 100644
index 000000000..966a419b7
--- /dev/null
+++ b/tools/tflitefile_tool/tflite/LogicalNotOptions.py
@@ -0,0 +1,28 @@
+# automatically generated by the FlatBuffers compiler, do not modify
+
+# namespace: tflite
+
+import flatbuffers
+
+
+class LogicalNotOptions(object):
+ __slots__ = ['_tab']
+
+ @classmethod
+ def GetRootAsLogicalNotOptions(cls, buf, offset):
+ n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
+ x = LogicalNotOptions()
+ x.Init(buf, n + offset)
+ return x
+
+ # LogicalNotOptions
+ def Init(self, buf, pos):
+ self._tab = flatbuffers.table.Table(buf, pos)
+
+
+def LogicalNotOptionsStart(builder):
+ builder.StartObject(0)
+
+
+def LogicalNotOptionsEnd(builder):
+ return builder.EndObject()
diff --git a/tools/tflitefile_tool/tflite/LogicalOrOptions.py b/tools/tflitefile_tool/tflite/LogicalOrOptions.py
new file mode 100644
index 000000000..0a820cdaa
--- /dev/null
+++ b/tools/tflitefile_tool/tflite/LogicalOrOptions.py
@@ -0,0 +1,28 @@
+# automatically generated by the FlatBuffers compiler, do not modify
+
+# namespace: tflite
+
+import flatbuffers
+
+
+class LogicalOrOptions(object):
+ __slots__ = ['_tab']
+
+ @classmethod
+ def GetRootAsLogicalOrOptions(cls, buf, offset):
+ n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
+ x = LogicalOrOptions()
+ x.Init(buf, n + offset)
+ return x
+
+ # LogicalOrOptions
+ def Init(self, buf, pos):
+ self._tab = flatbuffers.table.Table(buf, pos)
+
+
+def LogicalOrOptionsStart(builder):
+ builder.StartObject(0)
+
+
+def LogicalOrOptionsEnd(builder):
+ return builder.EndObject()
diff --git a/tools/tflitefile_tool/tflite/Model.py b/tools/tflitefile_tool/tflite/Model.py
index 4d1e01f44..b5072b171 100644
--- a/tools/tflitefile_tool/tflite/Model.py
+++ b/tools/tflitefile_tool/tflite/Model.py
@@ -71,7 +71,7 @@ class Model(object):
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10))
if o != 0:
return self._tab.String(o + self._tab.Pos)
- return ""
+ return None
# Model
def Buffers(self, j):
diff --git a/tools/tflitefile_tool/tflite/OneHotOptions.py b/tools/tflitefile_tool/tflite/OneHotOptions.py
new file mode 100644
index 000000000..fba03f85e
--- /dev/null
+++ b/tools/tflitefile_tool/tflite/OneHotOptions.py
@@ -0,0 +1,39 @@
+# automatically generated by the FlatBuffers compiler, do not modify
+
+# namespace: tflite
+
+import flatbuffers
+
+
+class OneHotOptions(object):
+ __slots__ = ['_tab']
+
+ @classmethod
+ def GetRootAsOneHotOptions(cls, buf, offset):
+ n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
+ x = OneHotOptions()
+ x.Init(buf, n + offset)
+ return x
+
+ # OneHotOptions
+ def Init(self, buf, pos):
+ self._tab = flatbuffers.table.Table(buf, pos)
+
+ # OneHotOptions
+ def Axis(self):
+ o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
+ if o != 0:
+ return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos)
+ return 0
+
+
+def OneHotOptionsStart(builder):
+ builder.StartObject(1)
+
+
+def OneHotOptionsAddAxis(builder, axis):
+ builder.PrependInt32Slot(0, axis, 0)
+
+
+def OneHotOptionsEnd(builder):
+ return builder.EndObject()
diff --git a/tools/tflitefile_tool/tflite/OperatorCode.py b/tools/tflitefile_tool/tflite/OperatorCode.py
index 0f945b901..ca0b49ef3 100644
--- a/tools/tflitefile_tool/tflite/OperatorCode.py
+++ b/tools/tflitefile_tool/tflite/OperatorCode.py
@@ -31,7 +31,7 @@ class OperatorCode(object):
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
if o != 0:
return self._tab.String(o + self._tab.Pos)
- return ""
+ return None
# OperatorCode
def Version(self):
diff --git a/tools/tflitefile_tool/tflite/PackOptions.py b/tools/tflitefile_tool/tflite/PackOptions.py
new file mode 100644
index 000000000..c1d5579fd
--- /dev/null
+++ b/tools/tflitefile_tool/tflite/PackOptions.py
@@ -0,0 +1,50 @@
+# automatically generated by the FlatBuffers compiler, do not modify
+
+# namespace: tflite
+
+import flatbuffers
+
+
+class PackOptions(object):
+ __slots__ = ['_tab']
+
+ @classmethod
+ def GetRootAsPackOptions(cls, buf, offset):
+ n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
+ x = PackOptions()
+ x.Init(buf, n + offset)
+ return x
+
+ # PackOptions
+ def Init(self, buf, pos):
+ self._tab = flatbuffers.table.Table(buf, pos)
+
+ # PackOptions
+ def ValuesCount(self):
+ o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
+ if o != 0:
+ return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos)
+ return 0
+
+ # PackOptions
+ def Axis(self):
+ o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
+ if o != 0:
+ return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos)
+ return 0
+
+
+def PackOptionsStart(builder):
+ builder.StartObject(2)
+
+
+def PackOptionsAddValuesCount(builder, valuesCount):
+ builder.PrependInt32Slot(0, valuesCount, 0)
+
+
+def PackOptionsAddAxis(builder, axis):
+ builder.PrependInt32Slot(1, axis, 0)
+
+
+def PackOptionsEnd(builder):
+ return builder.EndObject()
diff --git a/tools/tflitefile_tool/tflite/ReducerOptions.py b/tools/tflitefile_tool/tflite/ReducerOptions.py
index 5b6fa1acf..1f1a1b173 100644
--- a/tools/tflitefile_tool/tflite/ReducerOptions.py
+++ b/tools/tflitefile_tool/tflite/ReducerOptions.py
@@ -23,8 +23,9 @@ class ReducerOptions(object):
def KeepDims(self):
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
if o != 0:
- return self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos)
- return 0
+ return bool(
+ self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos))
+ return False
def ReducerOptionsStart(builder):
diff --git a/tools/tflitefile_tool/tflite/ResizeBilinearOptions.py b/tools/tflitefile_tool/tflite/ResizeBilinearOptions.py
index 66512bb1e..76948948e 100644
--- a/tools/tflitefile_tool/tflite/ResizeBilinearOptions.py
+++ b/tools/tflitefile_tool/tflite/ResizeBilinearOptions.py
@@ -23,8 +23,9 @@ class ResizeBilinearOptions(object):
def AlignCorners(self):
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8))
if o != 0:
- return self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos)
- return 0
+ return bool(
+ self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos))
+ return False
def ResizeBilinearOptionsStart(builder):
diff --git a/tools/tflitefile_tool/tflite/SequenceRNNOptions.py b/tools/tflitefile_tool/tflite/SequenceRNNOptions.py
index bee7a0fc6..2681296bb 100644
--- a/tools/tflitefile_tool/tflite/SequenceRNNOptions.py
+++ b/tools/tflitefile_tool/tflite/SequenceRNNOptions.py
@@ -23,8 +23,9 @@ class SequenceRNNOptions(object):
def TimeMajor(self):
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
if o != 0:
- return self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos)
- return 0
+ return bool(
+ self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos))
+ return False
# SequenceRNNOptions
def FusedActivationFunction(self):
diff --git a/tools/tflitefile_tool/tflite/SkipGramOptions.py b/tools/tflitefile_tool/tflite/SkipGramOptions.py
index 50738b924..9eb5059ea 100644
--- a/tools/tflitefile_tool/tflite/SkipGramOptions.py
+++ b/tools/tflitefile_tool/tflite/SkipGramOptions.py
@@ -37,8 +37,9 @@ class SkipGramOptions(object):
def IncludeAllNgrams(self):
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8))
if o != 0:
- return self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos)
- return 0
+ return bool(
+ self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos))
+ return False
def SkipGramOptionsStart(builder):
diff --git a/tools/tflitefile_tool/tflite/SparseToDenseOptions.py b/tools/tflitefile_tool/tflite/SparseToDenseOptions.py
index 2782ae573..952d08fc1 100644
--- a/tools/tflitefile_tool/tflite/SparseToDenseOptions.py
+++ b/tools/tflitefile_tool/tflite/SparseToDenseOptions.py
@@ -23,8 +23,9 @@ class SparseToDenseOptions(object):
def ValidateIndices(self):
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
if o != 0:
- return self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos)
- return 0
+ return bool(
+ self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos))
+ return False
def SparseToDenseOptionsStart(builder):
diff --git a/tools/tflitefile_tool/tflite/SquareOptions.py b/tools/tflitefile_tool/tflite/SquareOptions.py
new file mode 100644
index 000000000..0f9f5af9e
--- /dev/null
+++ b/tools/tflitefile_tool/tflite/SquareOptions.py
@@ -0,0 +1,28 @@
+# automatically generated by the FlatBuffers compiler, do not modify
+
+# namespace: tflite
+
+import flatbuffers
+
+
+class SquareOptions(object):
+ __slots__ = ['_tab']
+
+ @classmethod
+ def GetRootAsSquareOptions(cls, buf, offset):
+ n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
+ x = SquareOptions()
+ x.Init(buf, n + offset)
+ return x
+
+ # SquareOptions
+ def Init(self, buf, pos):
+ self._tab = flatbuffers.table.Table(buf, pos)
+
+
+def SquareOptionsStart(builder):
+ builder.StartObject(0)
+
+
+def SquareOptionsEnd(builder):
+ return builder.EndObject()
diff --git a/tools/tflitefile_tool/tflite/SubGraph.py b/tools/tflitefile_tool/tflite/SubGraph.py
index c20880a36..df9acd8ce 100644
--- a/tools/tflitefile_tool/tflite/SubGraph.py
+++ b/tools/tflitefile_tool/tflite/SubGraph.py
@@ -112,7 +112,7 @@ class SubGraph(object):
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12))
if o != 0:
return self._tab.String(o + self._tab.Pos)
- return ""
+ return None
def SubGraphStart(builder):
diff --git a/tools/tflitefile_tool/tflite/Tensor.py b/tools/tflitefile_tool/tflite/Tensor.py
index 468b120f4..e5f13301c 100644
--- a/tools/tflitefile_tool/tflite/Tensor.py
+++ b/tools/tflitefile_tool/tflite/Tensor.py
@@ -62,7 +62,7 @@ class Tensor(object):
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10))
if o != 0:
return self._tab.String(o + self._tab.Pos)
- return ""
+ return None
# Tensor
def Quantization(self):
@@ -79,8 +79,9 @@ class Tensor(object):
def IsVariable(self):
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14))
if o != 0:
- return self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos)
- return 0
+ return bool(
+ self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos))
+ return False
def TensorStart(builder):
diff --git a/tools/tflitefile_tool/tflite/UnpackOptions.py b/tools/tflitefile_tool/tflite/UnpackOptions.py
new file mode 100644
index 000000000..f580418e6
--- /dev/null
+++ b/tools/tflitefile_tool/tflite/UnpackOptions.py
@@ -0,0 +1,50 @@
+# automatically generated by the FlatBuffers compiler, do not modify
+
+# namespace: tflite
+
+import flatbuffers
+
+
+class UnpackOptions(object):
+ __slots__ = ['_tab']
+
+ @classmethod
+ def GetRootAsUnpackOptions(cls, buf, offset):
+ n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
+ x = UnpackOptions()
+ x.Init(buf, n + offset)
+ return x
+
+ # UnpackOptions
+ def Init(self, buf, pos):
+ self._tab = flatbuffers.table.Table(buf, pos)
+
+ # UnpackOptions
+ def Num(self):
+ o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
+ if o != 0:
+ return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos)
+ return 0
+
+ # UnpackOptions
+ def Axis(self):
+ o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
+ if o != 0:
+ return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos)
+ return 0
+
+
+def UnpackOptionsStart(builder):
+ builder.StartObject(2)
+
+
+def UnpackOptionsAddNum(builder, num):
+ builder.PrependInt32Slot(0, num, 0)
+
+
+def UnpackOptionsAddAxis(builder, axis):
+ builder.PrependInt32Slot(1, axis, 0)
+
+
+def UnpackOptionsEnd(builder):
+ return builder.EndObject()
diff --git a/tools/tflitefile_tool/tflite/ZerosLikeOptions.py b/tools/tflitefile_tool/tflite/ZerosLikeOptions.py
new file mode 100644
index 000000000..ca0880ab0
--- /dev/null
+++ b/tools/tflitefile_tool/tflite/ZerosLikeOptions.py
@@ -0,0 +1,28 @@
+# automatically generated by the FlatBuffers compiler, do not modify
+
+# namespace: tflite
+
+import flatbuffers
+
+
+class ZerosLikeOptions(object):
+ __slots__ = ['_tab']
+
+ @classmethod
+ def GetRootAsZerosLikeOptions(cls, buf, offset):
+ n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
+ x = ZerosLikeOptions()
+ x.Init(buf, n + offset)
+ return x
+
+ # ZerosLikeOptions
+ def Init(self, buf, pos):
+ self._tab = flatbuffers.table.Table(buf, pos)
+
+
+def ZerosLikeOptionsStart(builder):
+ builder.StartObject(0)
+
+
+def ZerosLikeOptionsEnd(builder):
+ return builder.EndObject()
diff --git a/tools/tflkit/README.md b/tools/tflkit/README.md
new file mode 100644
index 000000000..805a6e35b
--- /dev/null
+++ b/tools/tflkit/README.md
@@ -0,0 +1,366 @@
+# tflkit
+
+## Purpose
+
+There are a lot of tools related to TfLite. However, it is inconvenient to use the tools directly because there are many locations and parameters. The tflkit has been created to make it easier to run frequently used tools in scripts. The function provided in this directory uses existing tools rather than implementing them directly. So, additional modifications may occur depending on the TensorFlow version or other external factors. The function provided in this directory will be gradually expanded.
+
+## Prerequisites
+
+The scripts here use TensorFlow's tools, so you need an environment to build TensorFlow.
+Running the scripts within this tutorial requires:
+* [Install Bazel](https://docs.bazel.build/versions/master/install.html), the build tool used to compile TensorFlow.
+
+Initially, no external packages are installed on this project. Therefore, before running these scripts, you should install the associcated packages by running the following command once.
+```
+make configure
+```
+
+## Summarize TF model
+
+### TensorFlow
+
+TensorFlow uses `summarize_graph` tool to inspect the model and provide guesses about likely input and output nodes, as well as other information that's useful for debugging. For more information, see [Inspecting Graphs](https://github.com/tensorflow/tensorflow/tree/9590c4c32dd4346ea5c35673336f5912c6072bf2/tensorflow/tools/graph_transforms#inspecting-graphs) page.
+
+Usage:
+```
+$ bazel build tensorflow/tools/graph_transforms:summarize_graph
+$ bazel-bin/tensorflow/tools/graph_transforms/summarize_graph --in_graph=<pb file>
+```
+
+### tflkit
+
+Usage:
+```
+$ ./summarize_pb.sh <pb file>
+```
+
+The results shown below:
+```
+$ ./summarize_pb.sh inception_v3.pb
+
+ inception_v3.pb
+
+Inputs
+ name=input
+ type=float(1)
+ shape=[?,299,299,3]
+Outputs
+ name=InceptionV3/Predictions/Reshape_1, op=Reshape
+Op Types
+ 488 Const
+ 379 Identity
+ 95 Conv2D
+ 94 FusedBatchNorm
+ 94 Relu
+ 15 ConcatV2
+ 10 AvgPool
+ 4 MaxPool
+ 2 Reshape
+ 1 BiasAdd
+ 1 Placeholder
+ 1 Shape
+ 1 Softmax
+ 1 Squeeze
+
+ 14 Total
+```
+
+## Summarize TfLite model
+
+### tflkit
+
+Usage:
+```
+$ ./summarize_tflite.sh <tflite file>
+```
+
+The results shown below:
+```
+$ ./summarize_tflite.sh inception_v3.tflite
+[Main model]
+
+Main model input tensors: [317]
+Main model output tensors: [316]
+
+Operator 0: CONV_2D (instrs: 39,073,760, cycls: 39,073,760)
+ Fused Activation: RELU
+ Input Tensors[317, 0, 5]
+ Tensor 317 : buffer 183 | Empty | FLOAT32 | Shape [1, 299, 299, 3] (b'input')
+ Tensor 0 : buffer 205 | Filled | FLOAT32 | Shape [32, 3, 3, 3] (b'InceptionV3/Conv2d_1a_3x3/weights')
+ Tensor 5 : buffer 52 | Filled | FLOAT32 | Shape [32] (b'InceptionV3/InceptionV3/Conv2d_1a_3x3/Conv2D_bias')
+ Output Tensors[6]
+ Tensor 6 : buffer 285 | Empty | FLOAT32 | Shape [1, 149, 149, 32] (b'InceptionV3/InceptionV3/Conv2d_1a_3x3/Relu')
+
+[...]
+
+Operator 125: SOFTMAX (instrs: 4,003, cycls: 4,003)
+ Input Tensors[225]
+ Tensor 225 : buffer 142 | Empty | FLOAT32 | Shape [1, 1001] (b'InceptionV3/Logits/SpatialSqueeze')
+ Output Tensors[316]
+ Tensor 316 : buffer 53 | Empty | FLOAT32 | Shape [1, 1001] (b'InceptionV3/Predictions/Reshape_1')
+
+
+Number of all operator types: 6
+ CONV_2D : 95 (instrs: 11,435,404,777)
+ MAX_POOL_2D : 4 (instrs: 12,755,516)
+ AVERAGE_POOL_2D : 10 (instrs: 36,305,334)
+ CONCATENATION : 15 (instrs: 0)
+ RESHAPE : 1 (instrs: ???)
+ SOFTMAX : 1 (instrs: 4,003)
+Number of all operators : 126 (total instrs: 11,484,469,630)
+```
+
+## Convert a TensorFlow model into TfLite model
+
+### TensorFlow
+
+TensorFlow provides some kinds of converting guideline. In Python, the [TFLiteConverter](https://www.tensorflow.org/api_docs/python/tf/contrib/lite/TFLiteConverter) class will help you to convert a TensorFlow GraphDef or SavedModel into `output_format` using TOCO. The `output_format` can be `TFLITE` or `GRAPHVIZ_DOT` format. The default `output_format` is `TFLITE`. And there is a Python command line interface for running TOCO, and its name is [tflite_convert](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/python/tflite_convert.py). This converts a TensorFlow GraphDef or SavedModel into `TFLITE` or `GRAPHVIZ_DOT` format like [TFLiteConverter](https://www.tensorflow.org/api_docs/python/tf/contrib/lite/TFLiteConverter). These two way also supports to convert a TensorFlow Keras model into `output_format`. Both functions are implemented using a tool called TOCO.
+
+### with tflkit
+
+The tflkit uses the [tflite_convert](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/python/tflite_convert.py) python command line interface to convert a TensorFlow model into TfLite model. It only supports to convert a TensorFlow GraphDef file into `TFLITE` format file. This tool supports the creation of individual `TFLITE` files for different input shapes. When converting to multiple `TFLITE` files, it needs to put a string called `NAME` in `TFLITE_PATH`. The string `NAME` will be replaced by what is listed in teh `NAME` environment. This tool requires an information file as a parameter. There is an [example file](info/convert.template) for a convert information. The `--tensorflow_path` and `--tensorflow_version` can change the TensorFlow location. By default, it uses `externals/tensorflow` directory.
+
+Convert information:
+ * GRAPHDEF_PATH : Full filepath of file containing frozen TensorFlow GraphDef.
+ * TFLITE_PATH : Full filepath of the output TfLite model. If `NAME` optional environment is used, it must include `NAME` string in the file name. (ex. `[...]/inception_v3_NAME.tflite`)
+ * INPUT : Names of the input arrays, comma-separated.
+ * INPUT_SHAPE : Shapes correspoding to `INPUT`, colon-separated.
+ For the creation of individual `TFLITE` files for different input shapes, space-separated.
+ * OUTPUT : Names of the output arrays, comma-seperated.
+ * NAME(Optional) : Names of the individual `TFLITE` files for different input shapes, space-seperated.
+
+Usage (for example, [InceptionV3](https://storage.googleapis.com/download.tensorflow.org/models/tflite/model_zoo/upload_20180427/inception_v3_2018_04_27.tgz)):
+```
+$ wget https://storage.googleapis.com/download.tensorflow.org/models/tflite/model_zoo/upload_20180427/inception_v3_2018_04_27.tgz
+$ tar xzvf inception_v3_2018_04_27.tgz ./inception_v3.pb
+$ cat > convert.info << END
+GRAPHDEF_PATH="${PWD}/inception_v3.pb"
+TFLITE_PATH="${PWD}/inception_v3.tflite"
+INPUT="input"
+INPUT_SHAPE="1,299,299,3"
+OUTPUT="InceptionV3/Predictions/Reshape_1"
+#NAME=""
+END
+$ ./tflite_convert.sh --info=./convert.info --tensorflow_version=1.12
+$ ls *.tflite
+inception_v3.tflite
+```
+
+Usage (for example, multiple `TFLITE` files):
+```
+$ cat > convert_multiple.info << END
+GRAPHDEF_PATH="${PWD}/inception_v3.pb"
+TFLITE_PATH="${PWD}/inception_v3_NAME.tflite"
+INPUT="input"
+INPUT_SHAPE="1,299,299,3 3,299,299,3"
+OUTPUT="InceptionV3/Predictions/Reshape_1"
+NAME="batch1 batch3"
+END
+$ ./tflite_convert.sh --info=./convert_multiple.info --tensorflow_version=1.12
+$ ls *.tflite
+inception_v3_batch1.tflite
+inception_v3_batch3.tflite
+```
+
+## Optimize a TensorFlow model for inference
+
+### TensorFlow
+
+This [optimize tool](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/tools/optimize_for_inference.py) behaves like a transform tool. However, this tool is optimized to convert the trained TensorFlow graph for inference. This tool removes parts of a graph that are only needed for training. These include:
+ - Removing training-only operations like checkpoint saving.
+ - Stripping out parts of the graph that are never reached.
+ - Removing debug operations like CheckNumerics.
+ - Folding batch normalization ops into the pre-calculated weights.
+ - Fusing common operations into unified version.
+The input and output file of this tool is a TensorFlow GraphDef file.
+
+### with tflkit
+
+The [optimize_for_inference.sh](optimize_for_inference.sh) file invokes the TensorFlow [optimize tool](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/tools/optimize_for_inference.py). This tool requires a optimize information file as a parameter. Here is an [example file](info/optimize.template) for this tool. The information file needs `INPUT` and `OUTPUT` array names. The [summarize_pb.sh](summarize_pb.sh) file will help you to define the `INPUT` and `OUTPUT` array names. The `--tensorflow_path` can change the TensorFlow location. By default, it uses `externals/tensorflow` directory.
+
+Optimize information:
+ * GRAPHDEF_PATH : Full filepath of file containing frozen TensorFlow GraphDef.
+ * OPTIMIZE_PATH : Full filepath to save the output optimized graph.
+ * INPUT : Names of the input arrays, comma-separated.
+ * OUTPUT : Names of the output arrays, comma-seperated.
+
+Usage (for example, [InceptionV3](https://storage.googleapis.com/download.tensorflow.org/models/tflite/model_zoo/upload_20180427/inception_v3_2018_04_27.tgz)):
+```
+$ wget https://storage.googleapis.com/download.tensorflow.org/models/tflite/model_zoo/upload_20180427/inception_v3_2018_04_27.tgz
+$ tar xzvf inception_v3_2018_04_27.tgz ./inception_v3.pb
+$ cat > optimize.info << END
+GRAPHDEF_PATH="${PWD}/inception_v3.pb"
+OPTIMIZE_PATH="${PWD}/inception_v3.optimize.pb"
+INPUT="input"
+OUTPUT="InceptionV3/Predictions/Reshape_1"
+END
+$ ./optimize_for_inference.sh --info=./optimize.info
+$ ls *.pb
+inception_v3.optimize.pb inception_v3.pb
+```
+
+## Transform a TensorFlow graph
+
+### TensorFlow
+
+The trained TensorFlow model can be trasformed by some variants to deploy it in production. This [Graph Transform Tool](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/tools/graph_transforms#graph-transform-tool) provides to support this behavior. There are so many transform options in this tool. For more information on transform options, please see [this page](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/tools/graph_transforms#transform-reference). The input and output file of this tool is a TensorFlow GraphDef file.
+
+### with tflkit
+
+The [transform_graph.sh](transform_graph.sh) file supports to transform a TensorFlow GraphDef using various transform options. This tool requires a transform information file as a parameter and the transform options are described in the information file. There is an [example file](info/transform.template) for this tool. The information file needs `INPUT` and `OUTPUT` array names. The [summarize_pb.sh](summarize_pb.sh) file will help you to define the `INPUT` and `OUTPUT` array names. The `--tensorflow_path` can change the TensorFlow location. By default, it uses `externals/tensorflow` directory.
+
+Transform information:
+ * GRAPHDEF_PATH : Full filepath of file containing frozen TensorFlow GraphDef.
+ * TRANSFORM_PATH : Full filepath of the output TensorFlow GraphDef.
+ * INPUT : Names of the input arrays, comma-separated.
+ * OUTPUT : Names of the output arrays, comma-seperated.
+ * TRANSFORM_OPTIONS : Names of transform option, space-separated.
+ By default, it includes the following options.
+ * strip_unused_nodes : Removes all nodes not used in calculated the layer given in `OUTPUT` array, fed by `INPUT` array.
+ * remove_nodes : Removes the given name nodes from the graph.
+ * `Identity` is not necessary in inference graph. But if it needs in inference graph, this tool does not remove this node.
+ * `CheckNumerics` is useful during training but it is not necessary in inference graph.
+ * fold_constants : Replaces the sub-graps that always evaluate to constant expressions with those constants. This optimization is always executed at run-time after the graph is loaded, so it does'nt help latency, but it can simplify the graph and so make futher processing easier.
+ * fold_batch_norms : Scans the graph for any channel-wise multiplies immediately after convolutions, and multiplies the convolution's weights with the Mul instead so this can be omitted at inference time. It should be run after `fold_constants`.
+
+Usage (for example, [InceptionV3](https://storage.googleapis.com/download.tensorflow.org/models/tflite/model_zoo/upload_20180427/inception_v3_2018_04_27.tgz)):
+```
+$ wget https://storage.googleapis.com/download.tensorflow.org/models/tflite/model_zoo/upload_20180427/inception_v3_2018_04_27.tgz
+$ tar xzvf inception_v3_2018_04_27.tgz ./inception_v3.pb
+$ cat > transform.info << END
+GRAPHDEF_PATH="${PWD}/inception_v3.pb"
+TRANSFORM_PATH="${PWD}/inception_v3.transform.pb"
+INPUT="input"
+OUTPUT="InceptionV3/Predictions/Reshape_1"
+TRANSFORM_OPTIONS="strip_unused_nodes(type=float, shape=\"1,299,299,3\") remove_nodes(op=Identity, op=CheckNumerics) fold_constants(ignore_errors=true) fold_batch_norms"
+END
+$ ./transform_graph.sh --info=./transform.info
+$ ls *.pb
+inception_v3.pb inception_v3.transform.pb
+```
+
+## Freeze a TensorFlow model
+
+### TensorFlow
+
+TensorFlow provides methods to save and restore models. Each method stores related files in different ways. Here are two common ways to save the freeze stored models.
+ 1. Use [tf.train.Saver](https://www.tensorflow.org/guide/saved_model#save_and_restore_variables)
+ In this way, it creates a `MetaGraphDef` file and checkpoint files that contain the saved variables. Saving this way will result in the following files in the exported directory:
+
+ ```
+ $ ls /tmp/saver/
+ checkpoint model.ckpt.data-00000-of-00001 model.ckpt.index model.ckpt.meta
+ ```
+
+ 2. Use [SavedModel](https://www.tensorflow.org/guide/saved_model#build_and_load_a_savedmodel)
+ It is the easiest way to create a saved model. Saving this way will result in the following files in the exported directory:
+
+ ```
+ $ ls /tmp/saved_model/
+ saved_model.pb variables
+ $ tree /tmp/saved_model/
+ /tmp/saved_model/
+ ├── saved_model.pb
+ └── variables
+ ├── variables.data-00000-of-00001
+ └── variables.index
+ ```
+
+The [freeze_graph](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/tools/freeze_graph.py) tool receives these files as input parameters and combines the stored variables and the standalone graphdef to generate a frozen graphdef file.
+
+### with tflkit
+
+The tflkit provides the simple way to create a frozen graph using [freeze_graph](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/tools/freeze_graph.py) tool. This tool requires an information file as a parameter. There is an [example file](info/freeze.info) for a freeze tool. Either `SAVED_MODEL` or `META_GRAPH` must be declared. And `META_GRAPH` is always used with `CKPT_PATH`. The `--tensorflow_path` can change the TensorFlow location. By default, it uses `externals/tensorflow` directory.
+
+Freeze information:
+ * SAVED_MODEL : Full directory path with TensorFlow `SavedModel` file and variables.
+ * META_GRAPH : Full filepath of file containing TensorFlow `MetaGraphDef`.
+ * CKPT_PATH : Full filepath of file containing TensorFlow variables. (ex. [...]/*.ckpt)
+ * FROZEN_PATH : Full filepath to save the output frozen graph.
+ * OUTPUT : Names of the output arrays, comma-separated.
+
+Usage (for example, `tf.train.Saver`):
+```
+$ cat > sample_saver.py << END
+import tensorflow as tf
+
+# Create some variables.
+v1 = tf.get_variable("v1", shape=[3], initializer = tf.zeros_initializer)
+v2 = tf.get_variable("v2", shape=[5], initializer = tf.zeros_initializer)
+
+inc_v1 = v1.assign(v1+1)
+dec_v2 = v2.assign(v2-1)
+
+# Add an op to initialize the variables.
+init_op = tf.global_variables_initializer()
+
+# Add ops to save and restore all the variables.
+saver = tf.train.Saver()
+
+# Later, launch the model, initialize the variables, do some work, and save the
+# variables to disk.
+with tf.Session() as sess:
+ sess.run(init_op)
+ # Do some work with the model.
+ inc_v1.op.run()
+ dec_v2.op.run()
+ # Save the variables to disk.
+ save_path = saver.save(sess, "/tmp/saver/model.ckpt")
+ print("Model saved in path: %s" % save_path)
+END
+$ python sample_saver.py
+$ ls /tmp/saver/
+checkpoint model.ckpt.data-00000-of-00001 model.ckpt.index model.ckpt.meta
+$ cat > freeze_saver.info << END
+#SAVED_MODEL=""
+META_GRAPH="/tmp/saver/model.ckpt.meta"
+CKPT_PATH="/tmp/saver/model.ckpt"
+FROZEN_PATH="/tmp/saver/model.frozen.pb"
+OUTPUT="v2"
+END
+$ ./freeze_graph.sh --info=./freeze_saver.info
+$ ls /tmp/saver/*.pb
+/tmp/saver/model.frozen.pb
+```
+
+Usage (for example, `SavedModel`):
+```
+$ cat > sample_saved_model.py << END
+import tensorflow as tf
+
+# Create some variables.
+v1 = tf.get_variable("v1", shape=[3], initializer = tf.zeros_initializer)
+v2 = tf.get_variable("v2", shape=[5], initializer = tf.zeros_initializer)
+
+inc_v1 = v1.assign(v1+1)
+dec_v2 = v2.assign(v2-1)
+
+# Add an op to initialize the variables.
+init_op = tf.global_variables_initializer()
+
+# Later, launch the model, initialize the variables, do some work, and save the
+# variables to disk.
+with tf.Session() as sess:
+ sess.run(init_op)
+ # Do some work with the model.
+ inc_v1.op.run()
+ dec_v2.op.run()
+ # Save the variables to disk.
+ tf.saved_model.simple_save(sess, "/tmp/saved_model", inputs={'v1':v1}, outputs={'v2':v2})
+END
+$ python sample_saved_model.py
+$ ls /tmp/saved_model/
+saved_model.pb variables
+$ cat > freeze_saved_model.info << END
+SAVED_MODEL="/tmp/saved_model"
+#META_GRAPH=
+#CKPT_PATH=
+FROZEN_PATH="/tmp/saved_model/model.frozen.pb"
+OUTPUT="v2"
+END
+$ ./freeze_graph.sh --info=./info/freeze_saved_model.info
+$ ls /tmp/saved_model/
+model.frozen.pb saved_model.pb variables
+$ ls /tmp/saved_model/*.frozen.pb
+/tmp/saved_model/model.frozen.pb
+``` \ No newline at end of file
diff --git a/tools/tflkit/convert.template b/tools/tflkit/convert.template
new file mode 100644
index 000000000..88637de6f
--- /dev/null
+++ b/tools/tflkit/convert.template
@@ -0,0 +1,6 @@
+GRAPHDEF_PATH=
+TFLITE_PATH=
+INPUT=
+INPUT_SHAPE=
+OUTPUT=
+#NAME=
diff --git a/tools/tflkit/freeze.template b/tools/tflkit/freeze.template
new file mode 100644
index 000000000..076819c7f
--- /dev/null
+++ b/tools/tflkit/freeze.template
@@ -0,0 +1,5 @@
+SAVED_MODEL=
+META_GRAPH=
+CKPT_PATH=
+FROZEN_PATH=
+OUTPUT=
diff --git a/tools/tflkit/freeze_graph.sh b/tools/tflkit/freeze_graph.sh
new file mode 100755
index 000000000..c491ba4d2
--- /dev/null
+++ b/tools/tflkit/freeze_graph.sh
@@ -0,0 +1,98 @@
+#!/bin/bash
+
+usage()
+{
+ echo "usage : $0"
+ echo " --info=Information file"
+ echo " --tensorflow_path=TensorFlow path (Use externals/tensorflow by default)"
+}
+
+SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+
+TF_DIR="${SCRIPT_PATH}/../../externals/tensorflow"
+
+for i in "$@"
+do
+ case $i in
+ --info=*)
+ INFO=${i#*=}
+ ;;
+ --tensorflow_path=*)
+ TF_DIR=${i#*=}
+ ;;
+ -h|--help)
+ usage
+ exit 0
+ ;;
+ *)
+ usage
+ exit 1
+ ;;
+ esac
+ shift
+done
+
+if [ -z "$INFO" ]; then
+ echo "INFO is unset or set to the empty string"
+ usage
+ exit 1
+fi
+if [ -z "$TF_DIR" ]; then
+ echo "tensorflow_path is unset or set to the empty string"
+ usage
+ exit 1
+fi
+
+if [ ! -x "$(command -v bazel)" ]; then
+ echo "Cannot find bazel. Please install bazel."
+ exit 1
+fi
+
+source $INFO
+
+if [ -z "$SAVED_MODEL" ] && [ -z "$META_GRAPH" ]; then
+ echo "SAVED_MODEL or META_GRAPH + CKPT_PATH is unset or set to the empty string"
+ echo "Update the $INFO file"
+ exit 1
+fi
+if [ ! -z "$META_GRAPH" ] && [ -z "$CKPT_PATH" ]; then
+ echo "META_GRAPH is always used with CKPT_PATH"
+ echo "CKPT_PATH is unset or set to the empty string"
+ echo "Update the $INFO file"
+ exit 1
+fi
+if [ -z "$FROZEN_PATH" ]; then
+ echo "FROZEN_PATH is unset or set to the empty string"
+ echo "Update the $INFO file"
+ exit 1
+fi
+if [ -z "$OUTPUT" ]; then
+ echo "OUTPUT is unset or set to the empty string"
+ echo "Update the $INFO file"
+ exit 1
+fi
+
+CUR_DIR=$(pwd)
+{
+ echo "Enter $TF_DIR"
+ pushd $TF_DIR > /dev/null
+
+ if [ ! -z $SAVED_MODEL ]; then
+ bazel run tensorflow/python/tools:freeze_graph -- \
+ --input_saved_model_dir="$SAVED_MODEL" \
+ --input_binary=True \
+ --output_node_names="$OUTPUT" \
+ --output_graph="$FROZEN_PATH"
+ else
+ bazel run tensorflow/python/tools:freeze_graph -- \
+ --input_meta_graph="$META_GRAPH" \
+ --input_checkpoint="$CKPT_PATH" \
+ --input_binary=True \
+ --output_node_names="$OUTPUT" \
+ --output_graph="$FROZEN_PATH"
+ fi
+
+ popd
+
+ echo "OUTPUT FILE : $FROZEN_PATH"
+}
diff --git a/tools/tflkit/optimize.template b/tools/tflkit/optimize.template
new file mode 100644
index 000000000..5293a0319
--- /dev/null
+++ b/tools/tflkit/optimize.template
@@ -0,0 +1,4 @@
+GRAPHDEF_PATH=
+OPTIMIZE_PATH=
+INPUT=
+OUTPUT=
diff --git a/tools/tflkit/optimize_for_inference.sh b/tools/tflkit/optimize_for_inference.sh
new file mode 100755
index 000000000..ef6e52912
--- /dev/null
+++ b/tools/tflkit/optimize_for_inference.sh
@@ -0,0 +1,90 @@
+#!/bin/bash
+
+usage()
+{
+ echo "usage : $0"
+ echo " --info=Information file"
+ echo " --tensorflow_path=TensorFlow path (Use externals/tensorflow by default)"
+}
+
+SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+
+TF_DIR="${SCRIPT_PATH}/../../externals/tensorflow"
+
+for i in "$@"
+do
+ case $i in
+ --info=*)
+ INFO=${i#*=}
+ ;;
+ --tensorflow_path=*)
+ TF_DIR=${i#*=}
+ ;;
+ -h|--help)
+ usage
+ exit 0
+ ;;
+ *)
+ usage
+ exit 1
+ ;;
+ esac
+ shift
+done
+
+if [ -z "$INFO" ]; then
+ echo "INFO is unset or set to the empty string"
+ usage
+ exit 1
+fi
+if [ -z "$TF_DIR" ]; then
+ echo "tensorflow_path is unset or set to the empty string"
+ usage
+ exit 1
+fi
+
+if [ ! -x "$(command -v bazel)" ]; then
+ echo "Cannot find bazel. Please install bazel."
+ exit 1
+fi
+
+source $INFO
+
+if [ -z "$GRAPHDEF_PATH" ]; then
+ echo "GRAPHDEF_PATH is unset or set to the empty string"
+ echo "Update the $INFO file"
+ exit 1
+fi
+if [ -z "$OPTIMIZE_PATH" ]; then
+ echo "OPTIMIZE_PATH is unset or set to the empty string"
+ echo "Update the $INFO file"
+ exit 1
+fi
+if [ -z "$INPUT" ]; then
+ echo "INPUT is unset or set to the empty string"
+ echo "Update the $INFO file"
+ exit 1
+fi
+if [ -z "$OUTPUT" ]; then
+ echo "OUTPUT is unset or set to the empty string"
+ echo "Update the $INFO file"
+ exit 1
+fi
+
+CUR_DIR=$(pwd)
+{
+ echo "Enter $TF_DIR"
+ pushd $TF_DIR > /dev/null
+
+ bazel run tensorflow/python/tools:optimize_for_inference -- \
+ --input="$GRAPHDEF_PATH" \
+ --output="$OPTIMIZE_PATH" \
+ --frozen_graph=True \
+ --input_names="$INPUT" \
+ --output_names="$OUTPUT" \
+ --toco_compatible=True
+
+ popd
+
+ echo "OUTPUT FILE : $OPTIMIZE_PATH"
+}
diff --git a/tools/tflkit/summarize_pb.py b/tools/tflkit/summarize_pb.py
new file mode 100644
index 000000000..633804114
--- /dev/null
+++ b/tools/tflkit/summarize_pb.py
@@ -0,0 +1,111 @@
+import argparse
+import os
+import subprocess
+import re
+
+
+class cd:
+ """Context manager for changing the current working directory"""
+
+ def __init__(self, newPath):
+ self.newPath = os.path.expanduser(newPath)
+
+ def __enter__(self):
+ self.savedPath = os.getcwd()
+ os.chdir(self.newPath)
+
+ def __exit__(self, etype, value, traceback):
+ os.chdir(self.savedPath)
+
+
+def CheckExt(choices, name):
+ ext = os.path.splitext(name)[1][1:]
+ if ext not in choices:
+ parser.error("file does not end with one of {}".format(choices))
+ return name
+
+
+def PrintName(path):
+ print("")
+ print('\t' + os.path.basename(path))
+ print("")
+
+
+def PrintInput(data):
+ print("Inputs")
+ sub = data.split('(', 1)[1].rsplit(')', 1)[0]
+ for i in re.split(', ', sub):
+ print('\t' + i)
+
+
+def PrintOutput(data):
+ print("Outputs")
+ sub = re.findall('\((.*?)\)', data)
+ for i in sub:
+ print('\t' + i)
+
+
+def PrintOpType(data):
+ print("Op Types")
+ cnt = 0
+ sub = data.rsplit(':', 1)[1].split(',')
+ for i in sub:
+ cnt = cnt + 1
+ print('\t' + i.lstrip())
+ print('\t{0} Total'.format(cnt))
+
+
+def BuildTensorFlowSummarizeGraph(tensorflow_path):
+ with cd(tensorflow_path):
+ subprocess.call(
+ ['bazel', 'build', 'tensorflow/tools/graph_transforms:summarize_graph'])
+
+
+def SummarizeGraph(args):
+ if args.verbose is True:
+ vstr = ""
+ PrintName(args.input_file)
+ with cd(args.tensorflow_path):
+ proc = subprocess.Popen(
+ [
+ 'bazel-bin/tensorflow/tools/graph_transforms/summarize_graph',
+ '--in_graph=' + args.input_file
+ ],
+ stdout=subprocess.PIPE)
+ while True:
+ line = proc.stdout.readline().decode()
+ if args.verbose:
+ vstr += line
+ if line != '':
+ if 'inputs:' in line:
+ PrintInput(line)
+ elif 'outputs:' in line:
+ PrintOutput(line)
+ elif 'Op types used:' in line:
+ PrintOpType(line)
+ else:
+ break
+
+ if args.verbose:
+ print(vstr)
+
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ '--input_file',
+ required=True,
+ type=lambda s: CheckExt((['pb']), s),
+ help='pb file to read')
+ parser.add_argument(
+ '--tensorflow_path',
+ default='../../externals/tensorflow',
+ help='TensorFlow git repository path')
+ parser.add_argument('--verbose', action='store_true')
+ args = parser.parse_args()
+
+ # Build summarize_graph in external/tensorflow
+ BuildTensorFlowSummarizeGraph(args.tensorflow_path)
+
+ # Summarize graph
+ SummarizeGraph(args)
diff --git a/tools/tflkit/summarize_pb.sh b/tools/tflkit/summarize_pb.sh
new file mode 100755
index 000000000..141f27bc3
--- /dev/null
+++ b/tools/tflkit/summarize_pb.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+python summarize_pb.py --input_file=$1 $2
diff --git a/tools/tflkit/summarize_tflite.sh b/tools/tflkit/summarize_tflite.sh
new file mode 100755
index 000000000..e15550b07
--- /dev/null
+++ b/tools/tflkit/summarize_tflite.sh
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+python "${SCRIPT_PATH}/../tflitefile_tool/model_parser.py" ${@}
diff --git a/tools/tflkit/tflite_convert.sh b/tools/tflkit/tflite_convert.sh
new file mode 100755
index 000000000..2056797ab
--- /dev/null
+++ b/tools/tflkit/tflite_convert.sh
@@ -0,0 +1,136 @@
+#!/bin/bash
+
+usage()
+{
+ echo "usage : $0"
+ echo " --info=Information file"
+ echo " --tensorflow_path=TensorFlow path (Use externals/tensorflow by default)"
+ echo " --tensorflow_version=TensorFlow version (Must be entered)"
+}
+
+SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+
+TF_DIR="${SCRIPT_PATH}/../../externals/tensorflow"
+
+for i in "$@"
+do
+ case $i in
+ --info=*)
+ INFO=${i#*=}
+ ;;
+ --tensorflow_path=*)
+ TF_DIR=${i#*=}
+ ;;
+ --tensorflow_version=*)
+ TF_VERSION=${i#*=}
+ ;;
+ -h|--help)
+ usage
+ exit 0
+ ;;
+ *)
+ usage
+ exit 1
+ ;;
+ esac
+ shift
+done
+
+if [ -z "$INFO" ]; then
+ echo "INFO is unset or set to the empty string"
+ usage
+ exit 1
+fi
+if [ -z "$TF_DIR" ]; then
+ echo "tensorflow_path is unset or set to the empty string"
+ usage
+ exit 1
+fi
+if [ -z "$TF_VERSION" ]; then
+ echo "tensorflow_version is unset or set to the empty string"
+ usage
+ exit 1
+fi
+
+if [ ! -x "$(command -v bazel)" ]; then
+ echo "Cannot find bazel. Please install bazel."
+ exit 1
+fi
+
+source $INFO
+
+if [ -z "$GRAPHDEF_PATH" ]; then
+ echo "GRAPHDEF_PATH is unset or set to the empty string"
+ echo "Update the $INFO file"
+ exit 1
+fi
+if [ -z "$TFLITE_PATH" ]; then
+ echo "TFLITE_PATH is unset or set to the empty string"
+ echo "Update the $INFO file"
+ exit 1
+fi
+if [ -z "$INPUT" ]; then
+ echo "INPUT is unset or set to the empty string"
+ echo "Update the $INFO file"
+ exit 1
+fi
+if [ -z "$INPUT_SHAPE" ]; then
+ echo "INPUT_SHAPE is unset or set to the empty string"
+ echo "Update the $INFO file"
+ exit 1
+fi
+if [ -z "$OUTPUT" ]; then
+ echo "OUTPUT is unset or set to the empty string"
+ echo "Update the $INFO file"
+ exit 1
+fi
+
+CUR_DIR=$(pwd)
+{
+ echo "Enter $TF_DIR"
+ pushd $TF_DIR > /dev/null
+
+ NAME_LIST=()
+ INPUT_SHAPE_LIST=()
+ if [ -z "$NAME" ]; then
+ NAME_LIST+=("$TFLITE_PATH")
+ INPUT_SHAPE_LIST+=("$INPUT_SHAPE")
+ else
+ for name in $NAME; do
+ NAME_LIST[${#NAME_LIST[*]}]="${TFLITE_PATH/NAME/$name}"
+ done
+ for shape in $INPUT_SHAPE; do
+ INPUT_SHAPE_LIST[${#INPUT_SHAPE_LIST[*]}]="$shape"
+ done
+ if (( ${#NAME_LIST[*]} != ${#INPUT_SHAPE_LIST[*]} )); then
+ echo "The number of NAME and INPUT_SHAPE are different"
+ echo "Update the $INFO file"
+ exit 1
+ fi
+ fi
+
+ for (( i=0; i < ${#NAME_LIST[@]}; ++i )); do
+ if [ "${TF_VERSION%%.*}" = "2" ]; then
+ bazel run tensorflow/lite/python:tflite_convert -- \
+ --output_file="${NAME_LIST[$i]}" \
+ --graph_def_file="$GRAPHDEF_PATH" \
+ --input_arrays="$INPUT" \
+ --input_shapes="${INPUT_SHAPE_LIST[$i]}" \
+ --output_arrays="$OUTPUT" \
+ --allow_custom_ops=true
+ else
+ bazel run tensorflow/contrib/lite/python:tflite_convert -- \
+ --output_file="${NAME_LIST[$i]}" \
+ --graph_def_file="$GRAPHDEF_PATH" \
+ --input_arrays="$INPUT" \
+ --input_shapes="${INPUT_SHAPE_LIST[$i]}" \
+ --output_arrays="$OUTPUT" \
+ --allow_custom_ops
+ fi
+ done
+ popd
+
+ for (( i=0; i < ${#NAME_LIST[@]}; ++i )); do
+ echo "OUTPUT FILE : ${NAME_LIST[$i]}"
+ done
+}
diff --git a/tools/tflkit/transform.template b/tools/tflkit/transform.template
new file mode 100644
index 000000000..8a97f3da2
--- /dev/null
+++ b/tools/tflkit/transform.template
@@ -0,0 +1,5 @@
+GRAPHDEF_PATH=
+TRANSFORM_PATH=
+INPUT=
+OUTPUT=
+TRANSFORM_OPTIONS="strip_unused_nodes remove_nodes(op=Identity, op=CheckNumerics) fold_constants(ignore_errors=true) fold_batch_norms"
diff --git a/tools/tflkit/transform_graph.sh b/tools/tflkit/transform_graph.sh
new file mode 100755
index 000000000..828a36300
--- /dev/null
+++ b/tools/tflkit/transform_graph.sh
@@ -0,0 +1,94 @@
+#!/bin/bash
+
+usage()
+{
+ echo "usage : $0"
+ echo " --info=Information file"
+ echo " --tensorflow_path=TensorFlow path (Use externals/tensorflow by default)"
+}
+
+SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+
+TF_DIR="${SCRIPT_PATH}/../../externals/tensorflow"
+
+for i in "$@"
+do
+ case $i in
+ --info=*)
+ INFO=${i#*=}
+ ;;
+ --tensorflow_path=*)
+ TF_DIR=${i#*=}
+ ;;
+ -h|--help)
+ usage
+ exit 0
+ ;;
+ *)
+ usage
+ exit 1
+ ;;
+ esac
+ shift
+done
+
+if [ -z "$INFO" ]; then
+ echo "INFO is unset or set to the empty string"
+ usage
+ exit 1
+fi
+if [ -z "$TF_DIR" ]; then
+ echo "tensorflow_path is unset or set to the empty string"
+ usage
+ exit 1
+fi
+
+if [ ! -x "$(command -v bazel)" ]; then
+ echo "Cannot find bazel. Please install bazel."
+ exit 1
+fi
+
+source $INFO
+
+if [ -z "$GRAPHDEF_PATH" ]; then
+ echo "GRAPHDEF_PATH is unset or set to the empty string"
+ echo "Update the $INFO file"
+ exit 1
+fi
+if [ -z "$TRANSFORM_PATH" ]; then
+ echo "TRANSFORM_PATH is unset or set to the empty string"
+ echo "Update the $INFO file"
+ exit 1
+fi
+if [ -z "$INPUT" ]; then
+ echo "INPUT is unset or set to the empty string"
+ echo "Update the $INFO file"
+ exit 1
+fi
+if [ -z "$OUTPUT" ]; then
+ echo "OUTPUT is unset or set to the empty string"
+ echo "Update the $INFO file"
+ exit 1
+fi
+if [ -z "$TRANSFORM_OPTIONS" ]; then
+ echo "TRANSFORM_OPTIONS is unset or set to the empty string"
+ echo "Update the $INFO file"
+ exit 1
+fi
+
+CUR_DIR=$(pwd)
+{
+ echo "Enter $TF_DIR"
+ pushd $TF_DIR > /dev/null
+
+ bazel run tensorflow/tools/graph_transforms/transform_graph -- \
+ --in_graph="$GRAPHDEF_PATH" \
+ --out_graph="$TRANSFORM_PATH" \
+ --inputs="$INPUT" \
+ --outputs="$OUTPUT" \
+ --transforms="$TRANSFORM_OPTIONS"
+
+ popd
+
+ echo "OUTPUT FILE : $TRANSFORM_PATH"
+}