-
Notifications
You must be signed in to change notification settings - Fork 1
/
package_model_mac.sh
executable file
·85 lines (66 loc) · 2.18 KB
/
package_model_mac.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
84
85
#!/bin/bash
export BASE_DIR=$(
cd $(dirname $0)
pwd -L
)
source $(
cd $(dirname $0)
pwd -L
)/common.sh
display_usage() {
echo "
Usage:
$(basename "$0") <checkpoint> <tpu_ip> [--help or -h]
Description:
Packages model for edge TPU
Arguments:
checkpoint: model checkpoint
tpu_ip: IP of your TPU
"
}
# check whether user had supplied -h or --help . If yes display usage
if [[ ($1 == "--help") || $1 == "-h" ]]; then
display_usage
exit 0
fi
# Check the numbers of arguments
if [ $# -lt 2 ]; then
echo "Not enough arguments!" >&2
display_usage
exit 1
fi
if [ $# -gt 2 ]; then
echo "Too many arguments!" >&2
display_usage
exit 1
fi
# Exporting variables
checkpoint="$1"
tpu_ip=$2
export_vars
log_file="$BASE_DIR/logs/$checkpoint-$(date '+%Y%m%d_%H%M%S').log"
echo "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓"
echo "┃ Starting to package model ┃"
echo "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛"
echo ""
echo "⏱ $(date +%H%Mhrs)"
echo ""
rm -rf trained-inference-graphs/* > /dev/null 2>&1
rm -rf trainedModels/* > /dev/null 2>&1
rm -rf trainedTFLite/* > /dev/null 2>&1
nohup $BASE_DIR/create_tf_lite_model.sh $checkpoint >> $log_file 2>&1 &
wait_for_process "create_tf_lite_model.sh" "creating tf lite"
docker run -it --rm -v $BASE_DIR/trainedModels:/home/edgetpu edgetpu_compiler edgetpu_compiler LogoObjD.tflite >> $log_file 2>&1
printf "\r${CHECK_MARK} model compiled for edge tpu"
echo ""
ssh mendel@$tpu_ip rm -f /home/mendel/mtg/LogoObjD_edgetpu.tflite >> $log_file 2>&1
scp $BASE_DIR/trainedModels/LogoObjD_edgetpu.tflite mendel@$tpu_ip:~/mtg/ >> $log_file 2>&1
printf "\r${CHECK_MARK} model uploaded to TPU"
echo ""
echo "${CHECK_MARK} Package completed; run your model: edgetpu_detect_server --model mtg/LogoObjD_edgetpu.tflite --label mtg/label.txt --threshold=0.51"
echo ""
echo "⏱ $(date +%H%Mhrs)"
echo ""
echo "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓"
echo "┃ Finished to package model ┃"
echo "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛"