3 # Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
19 DRIVER_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
23 echo "Quantize circle model."
24 echo "Usage: one-quantize"
25 echo " --version Show version information and exit"
26 echo " --input_dtype Input data type (supported: float32, default=float32)"
27 echo " --quantized_dtype Output quantized data type (supported: uint8, default=uint8)"
28 echo " --granularity Quantize granularity (supported: layer, channel, default=layer)"
29 echo " --min_percentile Minimum percentile (0.0~100.0, default=1.0)"
30 echo " --max_percentile Maximum percentile (0.0~100.0, default=99.0)"
31 echo " --mode Record mode (supported: percentile/moving_average, default=percentile)"
32 echo " --input_path <path/to/input/circle>"
33 echo " --input_data <path/to/input/data>"
34 echo " --output_path <path/to/output/circle>"
40 $DRIVER_PATH/one-version one-quantize
51 # Parse command-line arguments
53 while [ "$#" -ne 0 ]; do
103 echo "Unknown parameter: ${CUR}"
109 if [ -z ${INPUT_PATH} ] || [ ! -e ${INPUT_PATH} ]; then
110 echo "Error: input model not found"
114 if [ -z ${INPUT_DATA} ] || [ ! -e ${INPUT_DATA} ]; then
115 echo "Error: input data not found"
120 FILE_BASE=$(basename ${OUTPUT_PATH})
121 MODEL_NAME="${FILE_BASE%.*}"
124 trap "{ rm -rf $TMPDIR; }" EXIT
126 # remove previous log
127 rm -rf "${OUTPUT_PATH}.log"
131 cat "${OUTPUT_PATH}.log"
134 trap show_err_onexit ERR
137 echo "${DRIVER_PATH}/circle-quantizer" \
138 --quantize_dequantize_weights ${INPUT_DTYPE} ${QUANTIZED_DTYPE} ${GRANULARITY} \
139 "${INPUT_PATH}" "${TMPDIR}/${MODEL_NAME}.1.circle" > "${OUTPUT_PATH}.log"
140 echo " " >> "${OUTPUT_PATH}.log"
142 "${DRIVER_PATH}/circle-quantizer" \
143 --quantize_dequantize_weights ${INPUT_DTYPE} ${QUANTIZED_DTYPE} ${GRANULARITY} \
144 "${INPUT_PATH}" "${TMPDIR}/${MODEL_NAME}.1.circle" >> "${OUTPUT_PATH}.log" 2>&1
146 echo " " >> "${OUTPUT_PATH}.log"
147 echo "${DRIVER_PATH}/record-minmax" \
148 --input_model "${TMPDIR}/${MODEL_NAME}.1.circle" \
149 --input_data "${INPUT_DATA}" \
150 --min_percentile ${MIN_PERCENTILE} --max_percentile ${MAX_PERCENTILE} \
152 --output_model "${TMPDIR}/${MODEL_NAME}.2.circle" >> "${OUTPUT_PATH}.log" 2>&1
153 echo " " >> "${OUTPUT_PATH}.log"
155 "${DRIVER_PATH}/record-minmax" \
156 --input_model "${TMPDIR}/${MODEL_NAME}.1.circle" \
157 --input_data "${INPUT_DATA}" \
158 --min_percentile ${MIN_PERCENTILE} --max_percentile ${MAX_PERCENTILE} \
160 --output_model "${TMPDIR}/${MODEL_NAME}.2.circle" >> "${OUTPUT_PATH}.log" 2>&1
162 echo " " >> "${OUTPUT_PATH}.log"
163 echo "${DRIVER_PATH}/circle-quantizer" \
164 --quantize_with_minmax ${INPUT_DTYPE} ${QUANTIZED_DTYPE} ${GRANULARITY} \
165 "${TMPDIR}/${MODEL_NAME}.2.circle" "${OUTPUT_PATH}" >> "${OUTPUT_PATH}.log" 2>&1
166 echo " " >> "${OUTPUT_PATH}.log"
168 "${DRIVER_PATH}/circle-quantizer" \
169 --quantize_with_minmax ${INPUT_DTYPE} ${QUANTIZED_DTYPE} ${GRANULARITY} \
170 "${TMPDIR}/${MODEL_NAME}.2.circle" "${OUTPUT_PATH}" >> "${OUTPUT_PATH}.log" 2>&1