summaryrefslogtreecommitdiff
path: root/compiler/one-cmds
diff options
context:
space:
mode:
authorChunseok Lee <chunseok.lee@samsung.com>2020-12-14 14:43:43 +0900
committerChunseok Lee <chunseok.lee@samsung.com>2020-12-14 14:43:43 +0900
commit62529acabbafce7730601ed01d5709d7bc0d378a (patch)
treebf6912cfa8fac4a2997292bfcb3c82055734c97e /compiler/one-cmds
parent6ea13af5257155ff993c205cf997b870cc627f73 (diff)
downloadnnfw-62529acabbafce7730601ed01d5709d7bc0d378a.tar.gz
nnfw-62529acabbafce7730601ed01d5709d7bc0d378a.tar.bz2
nnfw-62529acabbafce7730601ed01d5709d7bc0d378a.zip
Imported Upstream version 1.12.0upstream/1.12.0
Diffstat (limited to 'compiler/one-cmds')
-rw-r--r--compiler/one-cmds/how-to-use-one-commands.txt1
-rw-r--r--compiler/one-cmds/one-codegen29
-rw-r--r--compiler/one-cmds/one-import-bcq4
-rw-r--r--compiler/one-cmds/one-import-tf2
-rw-r--r--compiler/one-cmds/one-optimize4
-rw-r--r--compiler/one-cmds/tests/one-build_001.cfg2
-rw-r--r--compiler/one-cmds/tests/one-build_002.cfg2
-rw-r--r--compiler/one-cmds/tests/one-build_neg_002.cfg2
-rw-r--r--compiler/one-cmds/tests/one-build_neg_003.cfg2
-rw-r--r--compiler/one-cmds/tests/one-build_neg_004.cfg2
-rw-r--r--compiler/one-cmds/tests/one-import_002.cfg2
-rw-r--r--compiler/one-cmds/tests/one-import_003.cfg13
-rw-r--r--compiler/one-cmds/tests/one-import_003.test42
-rw-r--r--compiler/one-cmds/tests/one-import_004.cfg13
-rw-r--r--compiler/one-cmds/tests/one-import_004.test42
-rw-r--r--compiler/one-cmds/tests/prepare_test_materials.sh14
16 files changed, 149 insertions, 27 deletions
diff --git a/compiler/one-cmds/how-to-use-one-commands.txt b/compiler/one-cmds/how-to-use-one-commands.txt
index 62a497828..d4e3269e8 100644
--- a/compiler/one-cmds/how-to-use-one-commands.txt
+++ b/compiler/one-cmds/how-to-use-one-commands.txt
@@ -161,6 +161,7 @@ Current transformation options are
- make_batchnorm_gamma_positive: This makes negative gamma of batch normalization into a small positive value (1e-10).
Note that this pass can change the execution result of the model.
So, use it only when the impact is known to be acceptable.
+- replace_cw_mul_add_with_depthwise_conv: This will replace channel-wise Mul/Add with DepthwiseConv2D.
- resolve_customop_add: This will convert Custom(Add) to normal Add operator
- resolve_customop_batchmatmul: This will convert Custom(BatchMatMul) to
normal BatchMatMul operator
diff --git a/compiler/one-cmds/one-codegen b/compiler/one-cmds/one-codegen
index f2d82307c..fbe3d52d2 100644
--- a/compiler/one-cmds/one-codegen
+++ b/compiler/one-cmds/one-codegen
@@ -87,24 +87,19 @@ def main():
# verify arguments
_verify_arg(parser, args)
- # get file path to log
+ # make a command to run given backend driver
dir_path = os.path.dirname(os.path.realpath(__file__))
- logfile_path = os.path.realpath(args.output_path) + '.log'
-
- with open(logfile_path, 'wb') as f:
- # make a command to run given backend driver
- codegen_path = os.path.join(dir_path, getattr(args, 'backend') + '-compile')
- codegen_cmd = [codegen_path] + unknown_args
-
- f.write((' '.join(codegen_cmd) + '\n').encode())
-
- # run backend driver
- with subprocess.Popen(
- codegen_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
- bufsize=1) as p:
- for line in p.stdout:
- sys.stdout.buffer.write(line)
- f.write(line)
+ codegen_path = os.path.join(dir_path, getattr(args, 'backend') + '-compile')
+ codegen_cmd = [codegen_path] + unknown_args
+ if _utils._is_valid_attr(args, 'command'):
+ codegen_cmd += getattr(args, 'command').split()
+
+ # run backend driver
+ with subprocess.Popen(
+ codegen_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
+ bufsize=1) as p:
+ for line in p.stdout:
+ sys.stdout.buffer.write(line)
if __name__ == '__main__':
diff --git a/compiler/one-cmds/one-import-bcq b/compiler/one-cmds/one-import-bcq
index 5ea1f57fa..50f587946 100644
--- a/compiler/one-cmds/one-import-bcq
+++ b/compiler/one-cmds/one-import-bcq
@@ -43,13 +43,13 @@ def _get_parser():
converter_version.add_argument(
'--v1',
action='store_const',
- dest='converter_version',
+ dest='converter_version_cmd',
const='--v1',
help='use TensorFlow Lite Converter 1.x')
converter_version.add_argument(
'--v2',
action='store_const',
- dest='converter_version',
+ dest='converter_version_cmd',
const='--v2',
help='use TensorFlow Lite Converter 2.x')
diff --git a/compiler/one-cmds/one-import-tf b/compiler/one-cmds/one-import-tf
index 49009d331..3a7c69af3 100644
--- a/compiler/one-cmds/one-import-tf
+++ b/compiler/one-cmds/one-import-tf
@@ -52,8 +52,6 @@ def _get_parser():
const='--v2',
help='use TensorFlow Lite Converter 2.x')
- #converter_version.set_defaults(converter_version='--v1')
-
parser.add_argument('--converter_version', type=str, help=argparse.SUPPRESS)
# input model format
diff --git a/compiler/one-cmds/one-optimize b/compiler/one-cmds/one-optimize
index 4c5f10903..f03bb8dcc 100644
--- a/compiler/one-cmds/one-optimize
+++ b/compiler/one-cmds/one-optimize
@@ -73,6 +73,10 @@ def _get_parser():
circle2circle_group.add_argument(
'--fuse_instnorm', action='store_true', help='fuse ops to InstanceNorm operator')
circle2circle_group.add_argument(
+ '--replace_cw_mul_add_with_depthwise_conv',
+ action='store_true',
+ help='replace channel-wise Mul/Add with DepthwiseConv2D')
+ circle2circle_group.add_argument(
'--resolve_customop_add',
action='store_true',
help='convert Custom(Add) op to Add op')
diff --git a/compiler/one-cmds/tests/one-build_001.cfg b/compiler/one-cmds/tests/one-build_001.cfg
index 8524bbd1f..b022ba74b 100644
--- a/compiler/one-cmds/tests/one-build_001.cfg
+++ b/compiler/one-cmds/tests/one-build_001.cfg
@@ -13,7 +13,7 @@ output_path=inception_v3.circle
input_arrays=input
input_shapes=1,299,299,3
output_arrays=InceptionV3/Predictions/Reshape_1
-v2=True
+converter_version=v2
[one-optimize]
input_path=inception_v3.circle
diff --git a/compiler/one-cmds/tests/one-build_002.cfg b/compiler/one-cmds/tests/one-build_002.cfg
index 183077680..bbf09159b 100644
--- a/compiler/one-cmds/tests/one-build_002.cfg
+++ b/compiler/one-cmds/tests/one-build_002.cfg
@@ -13,7 +13,7 @@ output_path=inception_v3.circle
input_arrays=input
input_shapes=1,299,299,3
output_arrays=InceptionV3/Predictions/Reshape_1
-v2=True
+converter_version=v2
[one-optimize]
input_path=inception_v3.circle
diff --git a/compiler/one-cmds/tests/one-build_neg_002.cfg b/compiler/one-cmds/tests/one-build_neg_002.cfg
index 360c601e0..99db96651 100644
--- a/compiler/one-cmds/tests/one-build_neg_002.cfg
+++ b/compiler/one-cmds/tests/one-build_neg_002.cfg
@@ -13,7 +13,7 @@ output_path=inception_v3.circle
input_arrays=input
input_shapes=1,299,299,3
output_arrays=InceptionV3/Predictions/Reshape_1
-v2=True
+converter_version=v2
[one-optimize]
input_path=inception_v3.circle
diff --git a/compiler/one-cmds/tests/one-build_neg_003.cfg b/compiler/one-cmds/tests/one-build_neg_003.cfg
index 91e7875ac..fa027cb95 100644
--- a/compiler/one-cmds/tests/one-build_neg_003.cfg
+++ b/compiler/one-cmds/tests/one-build_neg_003.cfg
@@ -4,7 +4,7 @@ output_path=inception_v3.circle
input_arrays=input
input_shapes=1,299,299,3
output_arrays=InceptionV3/Predictions/Reshape_1
-v2=True
+converter_version=v2
[one-optimize]
input_path=inception_v3.circle
diff --git a/compiler/one-cmds/tests/one-build_neg_004.cfg b/compiler/one-cmds/tests/one-build_neg_004.cfg
index 4d312c47c..571077b42 100644
--- a/compiler/one-cmds/tests/one-build_neg_004.cfg
+++ b/compiler/one-cmds/tests/one-build_neg_004.cfg
@@ -13,7 +13,7 @@ output_path=inception_v3.circle
input_arrays=input
input_shapes=1,299,299,3
output_arrays=InceptionV3/Predictions/Reshape_1
-v2=True
+converter_version=v2
[one-optimize]
input_path=inception_v3.circle
diff --git a/compiler/one-cmds/tests/one-import_002.cfg b/compiler/one-cmds/tests/one-import_002.cfg
index 9a90abecd..8d6ae2c35 100644
--- a/compiler/one-cmds/tests/one-import_002.cfg
+++ b/compiler/one-cmds/tests/one-import_002.cfg
@@ -13,4 +13,4 @@ output_path=inception_v3.circle
input_arrays=input
input_shapes=1,299,299,3
output_arrays=InceptionV3/Predictions/Reshape_1
-v2=True
+converter_version=v2
diff --git a/compiler/one-cmds/tests/one-import_003.cfg b/compiler/one-cmds/tests/one-import_003.cfg
new file mode 100644
index 000000000..b679ebdb3
--- /dev/null
+++ b/compiler/one-cmds/tests/one-import_003.cfg
@@ -0,0 +1,13 @@
+[one-build]
+one-import-tf=True
+one-import-tflite=False
+one-import-bcq=False
+one-optimize=False
+one-quantize=False
+one-pack=False
+one-codegen=False
+
+[one-import-tf]
+model_format=saved_model
+input_path=test_saved_model
+output_path=test_saved_model.circle
diff --git a/compiler/one-cmds/tests/one-import_003.test b/compiler/one-cmds/tests/one-import_003.test
new file mode 100644
index 000000000..6093f1422
--- /dev/null
+++ b/compiler/one-cmds/tests/one-import_003.test
@@ -0,0 +1,42 @@
+#!/bin/bash
+
+# Copyright (c) 2020 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 of TF 2.x saved model
+
+filename_ext="$(basename -- $0)"
+filename="${filename_ext%.*}"
+
+trap_err_onexit()
+{
+ echo "${filename_ext} FAILED"
+ exit 255
+}
+
+trap trap_err_onexit ERR
+
+configfile="one-import_003.cfg"
+outputfile="test_saved_model.circle"
+
+rm -f ${outputfile}
+
+# run test
+one-import tf -C ${configfile} > /dev/null
+
+if [[ ! -s "${outputfile}" ]]; then
+ trap_err_onexit
+fi
+
+echo "${filename_ext} SUCCESS"
diff --git a/compiler/one-cmds/tests/one-import_004.cfg b/compiler/one-cmds/tests/one-import_004.cfg
new file mode 100644
index 000000000..d28c8dff6
--- /dev/null
+++ b/compiler/one-cmds/tests/one-import_004.cfg
@@ -0,0 +1,13 @@
+[one-build]
+one-import-tf=True
+one-import-tflite=False
+one-import-bcq=False
+one-optimize=False
+one-quantize=False
+one-pack=False
+one-codegen=False
+
+[one-import-tf]
+model_format=keras_model
+input_path=test_keras_model.h5
+output_path=test_keras_model.circle
diff --git a/compiler/one-cmds/tests/one-import_004.test b/compiler/one-cmds/tests/one-import_004.test
new file mode 100644
index 000000000..9d10c431a
--- /dev/null
+++ b/compiler/one-cmds/tests/one-import_004.test
@@ -0,0 +1,42 @@
+#!/bin/bash
+
+# Copyright (c) 2020 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 of TF 2.x keras model
+
+filename_ext="$(basename -- $0)"
+filename="${filename_ext%.*}"
+
+trap_err_onexit()
+{
+ echo "${filename_ext} FAILED"
+ exit 255
+}
+
+trap trap_err_onexit ERR
+
+configfile="one-import_004.cfg"
+outputfile="test_keras_model.circle"
+
+rm -f ${outputfile}
+
+# run test
+one-import tf -C ${configfile} > /dev/null
+
+if [[ ! -s "${outputfile}" ]]; then
+ trap_err_onexit
+fi
+
+echo "${filename_ext} SUCCESS"
diff --git a/compiler/one-cmds/tests/prepare_test_materials.sh b/compiler/one-cmds/tests/prepare_test_materials.sh
index cb1067e28..bc3d65d92 100644
--- a/compiler/one-cmds/tests/prepare_test_materials.sh
+++ b/compiler/one-cmds/tests/prepare_test_materials.sh
@@ -63,6 +63,20 @@ if [[ ! -s "inception_v3_test_data.h5" ]]; then
--output_path inception_v3_test_data.h5
fi
+if [[ ! -d "test_saved_model" ]]; then
+ rm -rf test_saved_model.zip
+ wget https://github.com/Samsung/ONE/files/5516226/test_saved_model.zip
+ unzip test_saved_model.zip
+ # https://github.com/Samsung/ONE/issues/4268#issuecomment-724578237
+fi
+
+if [[ ! -s "test_keras_model.h5" ]]; then
+ rm -rf test_keras_model.zip
+ wget https://github.com/Samsung/ONE/files/5520777/test_keras_model.zip
+ unzip test_keras_model.zip
+ # https://github.com/Samsung/ONE/issues/4268#issuecomment-725025805
+fi
+
# prepare 'inception_v3.circle' file used for quantization test
inputfile="./inception_v3.pb"
outputfile="./inception_v3.circle"