-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_tensorflowlite.sh
executable file
·83 lines (66 loc) · 1.68 KB
/
build_tensorflowlite.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
76
77
78
79
80
81
82
83
#!/bin/sh
SHARDS_INSTALL=IS_LIB
IS_LOCAL=./ext/libtensorflowlite_c.so
if test -f "$IS_LOCAL"; then
echo "--"
echo "tensorflow lite library installed, skipping installation"
echo "--"
exit 0
fi
echo "--"
echo "preparing... (requires build-essential and cmake)"
echo "--"
# clone the required repositories
git clone --depth 1 --branch "v2.16.1" https://github.com/tensorflow/tensorflow
echo "--"
echo "configuring..."
echo "--"
mkdir tflite_build
cd tflite_build
cmake ../tensorflow/tensorflow/lite/c \
-DTFLITE_ENABLE_GPU=ON
echo "--"
echo "building..."
echo "--"
cmake --build . -j3 || true
FILE=./libtensorflowlite_c.so
if test -f "$FILE"; then
echo "--"
echo "build success!"
else
echo "build failed, retrying..."
cmake --build . -j1
if test -f "$FILE"; then
echo "--"
echo "build success!"
else
echo "--"
echo "build failed... Leaving files in place for inspection"
echo "--"
exit 1
fi
fi
echo "copying library into place.."
echo "--"
# we'll put the lib into a few different places so it'll run when using crystal normally
# Temp location crystal runs applications from
mkdir -p ~/.cache/crystal/
cp ./libtensorflowlite_c.so ~/.cache/crystal/
# A location to use when building
mkdir -p ../ext
cp ./libtensorflowlite_c.so ../ext/
# other locations you might be running the application from
# check if being installed as a lib
if [ "$1" = "$SHARDS_INSTALL" ]; then
echo "copying into parent directory.."
mkdir -p ../../../bin
cp ./libtensorflowlite_c.so ../../../bin/
cp ./libtensorflowlite_c.so ../../../
else
echo "run manually, assuming library development mode"
fi
cd ..
rm -rf ./tensorflow
rm -rf ./tflite_build
echo "--"
echo "Done"