-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert_checkpoint_to_edgetpu_tflite.sh
75 lines (65 loc) · 2.37 KB
/
convert_checkpoint_to_edgetpu_tflite.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
# Copyright 2020 Google LLC
#
# 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
#
# https://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.
# Exit script on error.
set -e
# Echo each command, easier for debugging.
set -x
usage() {
cat << END_OF_USAGE
Converts TensorFlow checkpoint to EdgeTPU-compatible TFLite file.
--checkpoint_num Checkpoint number, by default 0.
--help Display this help.
END_OF_USAGE
}
ckpt_number=0
while [[ $# -gt 0 ]]; do
case "$1" in
--checkpoint_num)
ckpt_number=$2
shift 2 ;;
--help)
usage
exit 0 ;;
--*)
echo "Unknown flag $1"
usage
exit 1 ;;
esac
done
source "$PWD/constants.sh"
mkdir -p "${OUTPUT_DIR}"
echo "GENERATING label file..."
echo "0 Abyssinian" >> "${OUTPUT_DIR}/labels.txt"
echo "1 american_bulldog" >> "${OUTPUT_DIR}/labels.txt"
echo "EXPORTING frozen graph from checkpoint..."
python object_detection/export_tflite_ssd_graph.py \
--pipeline_config_path="/home/uvan/google-coral/tutorials/docker/object_detection/pipeline.config" \
--trained_checkpoint_prefix="/home/uvan/google-coral/tutorials/docker/object_detection/out/train/model.ckpt-0.data-00000-of-00001" \
--output_directory="/home/uvan/google-coral/tutorials/docker/object_detection/out" \
--add_postprocessing_op=true
echo "CONVERTING frozen graph to TF Lite file..."
tflite_convert \
--output_file="/home/uvan/google-coral/tutorials/docker/object_detection/out/output_tflite_graph.tflite" \
--graph_def_file="/home/uvan/google-coral/tutorials/docker/object_detection/out/tflite_graph.pb" \
--inference_type=QUANTIZED_UINT8 \
--input_arrays="${INPUT_TENSORS}" \
--output_arrays="${OUTPUT_TENSORS}" \
--mean_values=128 \
--std_dev_values=128 \
--input_shapes=1,300,300,3 \
--change_concat_input_ranges=false \
--allow_nudging_weights_to_use_fast_gemm_kernel=true \
--allow_custom_ops
echo "TFLite graph generated at ${OUTPUT_DIR}/output_tflite_graph.tflite"