Imported Upstream version 1.8.0
[platform/core/ml/nnfw.git] / compiler / one-cmds / one-import-tflite
1 #!/bin/bash
2
3 # Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #    http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 set -e
18
19 DRIVER_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
20
21 usage()
22 {
23   echo "Convert TensorFlow lite model to circle."
24   echo "Usage: one-import-tflite"
25   echo "    --version Show version information and exit"
26   echo "    --input_path <path/to/tflitemodel>"
27   echo "    --output_path <path/to/circle>"
28   exit 255
29 }
30
31 version()
32 {
33   $DRIVER_PATH/one-version one-import-tflite
34   exit 255
35 }
36
37 # Parse command-line arguments
38 #
39 while [ "$#" -ne 0 ]; do
40   CUR="$1"
41
42   case $CUR in
43     '--help')
44       usage
45       ;;
46     '--version')
47       version
48       ;;
49     '--input_path')
50       export INPUT_PATH="$2"
51       shift 2
52       ;;
53     '--output_path')
54       export OUTPUT_PATH="$2"
55       shift 2
56       ;;
57     *)
58       echo "Unknown parameter: ${CUR}"
59       shift
60       ;;
61   esac
62 done
63
64 if [ -z ${INPUT_PATH} ] || [ ! -e ${INPUT_PATH} ]; then
65   echo "Error: input model not found"
66   echo ""
67   usage
68 fi
69
70 # remove previous log
71 rm -rf "${OUTPUT_PATH}.log"
72
73 show_err_onexit()
74 {
75   cat "${OUTPUT_PATH}.log"
76 }
77
78 trap show_err_onexit ERR
79
80 # convert .tflite to .circle
81 echo "${DRIVER_PATH}/tflite2circle" "${INPUT_PATH}" "${OUTPUT_PATH}" > "${OUTPUT_PATH}.log"
82
83 "${DRIVER_PATH}/tflite2circle" "${INPUT_PATH}" "${OUTPUT_PATH}" >> "${OUTPUT_PATH}.log" 2>&1