This repository has been archived by the owner on Jun 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
/
upload-current.sh
executable file
·77 lines (59 loc) · 1.76 KB
/
upload-current.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
#!/usr/bin/env bash
S3_BUCKET=$1
S3_PREFIX=$2
MODEL_DIR=data/minio/bucket/current/model/
while getopts ":c:" opt; do
case $opt in
c) CHECKPOINT="$OPTARG"
;;
\?) echo "Invalid option -$OPTARG" >&2
;;
esac
done
CHECKPOINT_FILE=$MODEL_DIR"deepracer_checkpoints.json"
if [ ! -f ${CHECKPOINT_FILE} ]; then
echo "Checkpoint file not found!"
exit 1
else
echo "found checkpoint index file "$CHECKPOINT_FILE
fi;
if [ -z "$CHECKPOINT" ]; then
echo "Checkpoint not supplied, checking for latest checkpoint"
LAST_CHECKPOINT=`cat $CHECKPOINT_FILE |jq ".last_checkpoint.name"`
BEST_CHECKPOINT=`cat $CHECKPOINT_FILE |jq ".best_checkpoint.name"`
CHECKPOINT=$LAST_CHECKPOINT
echo "latest checkpoint = "$CHECKPOINT
else
echo "Checkpoint supplied: ["${CHECKPOINT}"]"
fi
MODEL=`echo $CHECKPOINT |sed "s@^[^0-9]*\([0-9]\+\).*@\1@"`
mkdir -p checkpoint
MODEL_FILE=$MODEL_DIR"model_"$MODEL".pb"
METADATA_FILE=$MODEL_DIR"model_metadata.json"
if test ! -f "$MODEL_FILE"; then
echo "$MODEL_FILE doesn't exist"
exit 1
else
cp $MODEL_FILE checkpoint/
fi
if test ! -f "$METADATA_FILE"; then
echo "$METADATA_FILE doesn't exist"
exit 1
else
cp $METADATA_FILE checkpoint/
fi
CHECKPOINT_FILES=`echo $CHECKPOINT* |sed "s/\"//g"`
for i in $( find $MODEL_DIR -type f -name $CHECKPOINT_FILES ); do
cp $i checkpoint/
done
VAR1=`cat $CHECKPOINT_FILE |jq ".last_checkpoint = .best_checkpoint"`
VAR2=`echo $VAR1 |jq ".last_checkpoint.name = $CHECKPOINT"`
VAR3=`echo $VAR2 |jq ".best_checkpoint.name = $CHECKPOINT"`
echo $VAR3 >checkpoint/deepracer_checkpoints.json
# upload files to s3
for filename in checkpoint/*; do
aws s3 cp $filename s3://$S3_BUCKET/$S3_PREFIX/model/
done
tar -czvf ${CHECKPOINT}-checkpoint.tar.gz checkpoint/*
rm -rf checkpoint
echo 'done uploading model!'