forked from zhenhuaw-me/tflite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-schema.sh
executable file
·59 lines (51 loc) · 1.76 KB
/
update-schema.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
#!/bin/bash
# which version?
read -p "Which version of TensorFlow would you like to obtain the schema (\"v1.14.0\" for example): " version
if [ -z ${version} ]; then
exit 1
fi
read -p "Going to obtain schema from version \"${version}\", continue? [Y|N] " input_str
if [ -z ${input_str} -o "${input_str}" != "Y" ]; then
exit 0
fi
if [ "$(uname -s)" == "Darwin" ]; then
root_dir=$(dirname $(dirname $(greadlink -f $0})))
else
root_dir=$(dirname $(dirname $(readlink -f $0})))
fi
schema_path="${root_dir}/3rdparty/schema.fbs"
output_path="${root_dir}"
# download schema.fbs
repo_tree='https://raw.githubusercontent.com/tensorflow/tensorflow'
file_path='tensorflow/lite/schema/schema.fbs'
url="${repo_tree}/${version}/${file_path}"
echo "Now, downloading from ${url}"
curl ${url} -o "${schema_path}"
# exit?
if [ $(grep -q "404: Not Found" ${schema_path}) ]; then
echo "Error: fail to download schema from ${url}"
exit 1
fi
changed_lines=$(git diff ${schema_path} | wc -l)
if [ ${changed_lines} -eq 0 ]; then
echo "No change to schema, exit!"
exit 0
fi
echo "Building flatbuffers python module in ${output_path}"
rm -f ${root_dir}/tflite/*.py
FBSC=$(which flatc)
if [ ${?} -ne 0 ]; then
echo "Error: Flatbuffer complier doesn't exist! Build with https://google.github.io/flatbuffers/flatbuffers_guide_building.html"
exit 1
fi
${FBSC} --python -o ${output_path} ${schema_path}
# revert the __init__.py
git checkout ${root_dir}/tflite/__init__.py
git checkout ${root_dir}/tflite/utils.py
# commit the schema change?
read -p "Going to create a commit for these changes, continue? [Y|N] " input_str
if [ -z ${input_str} -o "${input_str}" != "Y" ]; then
exit 0
fi
git add ${schema_path} ${output_path}/tflite
git commit -m "update schema.fbs and tflite module to ${version}"