forked from tensorflow/tfjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate_converter.sh
More file actions
executable file
·156 lines (129 loc) · 3.73 KB
/
validate_converter.sh
File metadata and controls
executable file
·156 lines (129 loc) · 3.73 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env bash
#
# Copyright 2018 Google LLC
#
# Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.
# =============================================================================
#
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SKIP_PY_BENCHMAKRS=0
IS_TFJS_NODE=0 # Whether tfjs-node or tfjs-node-gpu is being benchmarked.
IS_TFJS_NODE_GPU=0 # Whether tfjs-node-gpu is being benchmarked.
LOG_FLAG=""
while true; do
if [[ "$1" == "--tfjs-node" ]]; then
IS_TFJS_NODE=1
IS_TFJS_NODE_GPU=0
shift
elif [[ "$1" == "--tfjs-node-gpu" ]]; then
IS_TFJS_NODE=1
IS_TFJS_NODE_GPU=1
shift
elif [[ "$1" == "--log" ]]; then
HASH="$(git rev-parse HEAD)"
if [[ -z "${HASH}" ]]; then
echo "ERROR: Failed to retrieve git commit hash" 1>&2
exit 1
fi
LOG_FLAG="--log"
shift
elif [[ -z "$1" ]]; then
break
else
echo "ERROR: Unrecognized argument: $1"
exit 1
fi
done
cd ${SCRIPT_DIR}
yarn
yarn upgrade \
@tensorflow/tfjs-core \
@tensorflow/tfjs-converter \
@tensorflow/tfjs
if [[ "${IS_TFJS_NODE}" == "1" ]]; then
rm -rf tfjs-node/
cp -r ../../tfjs-node .
cd tfjs-node
rm -rf dist/
if [[ "${IS_TFJS_NODE_GPU}" == "1" ]]; then
yarn node scripts/install.js gpu download
else
yarn node scripts/install.js cpu download
fi
yarn && yarn build && yarn yalc publish
cd ..
yarn yalc link '@tensorflow/tfjs-node'
# yalc publish does not deliver libtensorflow and node native addon, so we
# need to copy libtensorflow and build addon from source
cp -r tfjs-node/deps .yalc/@tensorflow/tfjs-node/
cd .yalc/@tensorflow/tfjs-node
yarn && yarn build-addon-from-source
cd ../../..
else
rm -rf tfjs-core/
cp -r ../../tfjs-core .
cd tfjs-core
rm -rf dist/ node_modules/ && yarn
yarn build && yarn yalc publish
cd ..
yarn yalc link '@tensorflow/tfjs-core'
rm -rf tfjs-converter/
cp -r ../../tfjs-converter .
cd tfjs-converter
rm -rf dist/ node_modules/ && yarn
yarn build && yarn yalc publish
cd ..
yarn yalc link '@tensorflow/tfjs-converter'
fi
# Run Python script to generate the model and weights JSON files.
# The extension names are ".js" because they will later be converted into
# sourceable JavaScript files.
if [[ -z "$(which pip)" ]]; then
echo "pip is not on path. Attempting to install it..."
apt-get update
apt-get install -y python-pip
fi
DATA_ROOT="${SCRIPT_DIR}/data"
echo "Installing virtualenv..."
pip install virtualenv
VENV_DIR="$(mktemp -d)_venv"
echo "Creating virtualenv at ${VENV_DIR} ..."
virtualenv "${VENV_DIR}"
source "${VENV_DIR}/bin/activate"
echo "Installing Python dependencies..."
if [[ "${IS_TFJS_NODE_GPU}" == "1" ]]; then
pip install -r python/requirements_gpu.txt
else
pip install -r python/requirements.txt
fi
echo "Running python converter..."
python "${SCRIPT_DIR}/python/validation.py" "${DATA_ROOT}"
echo "Cleaning up virtualenv directory ${VENV_DIR}..."
deactivate
rm -rf "${VENV_DIR}"
# Clean up virtualenv directory.
rm -rf "${VENV_DIR}"
if [[ ! -d "${DATA_ROOT}" ]]; then
echo "Cannot find data root directory: ${DATA_ROOT}"
exit 1
fi
if [[ "${IS_TFJS_NODE}" == "1" ]]; then
GPU_FLAG=""
if [[ "${IS_TFJS_NODE_GPU}" == "1" ]]; then
GPU_FLAG="--gpu"
fi
echo "Starting validation karma tests in Node.js..."
yarn ts-node run_node_tests.ts \
--filename "models/validation.ts" \
${GPU_FLAG} \
${LOG_FLAG} \
--hashes "{\"tfjs-node\": \"${HASH}\"}"
else
echo "Starting validation karma tests in the browser..."
yarn karma start karma.conf.validations.js \
"${LOG_FLAG}" \
--hashes="{\"tfjs-core\":\"${HASH}\",\"tfjs-converter\":\"${HASH}\"}"
fi