-
Notifications
You must be signed in to change notification settings - Fork 447
/
train-local
executable file
·56 lines (48 loc) · 1.17 KB
/
train-local
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
#!/bin/bash
set -e
# parse arguments
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--config-file)
CONFIG_FILE="$2"
shift # past argument
shift # past value
;;
--samples-file)
SAMPLES_FILE="$2"
shift # past argument
shift # past value
;;
--image-dir)
IMAGE_DIR="$2"
shift # past argument
shift # past value
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
# parse config file and assign parameters to variables
eval "$(jq -r "to_entries|map(\"export \(.key)=\(.value|tostring)\")|.[]" $CONFIG_FILE)"
# create train job dir
TIMESTAMP=$(date +%Y_%m_%d_%H_%M_%S)
TRAIN_JOB_DIR=train_jobs/$TIMESTAMP
mkdir -p $TRAIN_JOB_DIR
# copy config and samples file to train job dir
cp $CONFIG_FILE $TRAIN_JOB_DIR/config.json
cp $SAMPLES_FILE $TRAIN_JOB_DIR/samples.json
# start training
DOCKER_RUN="docker run -d
-v $IMAGE_DIR:/src/images
-v "$(pwd)/$TRAIN_JOB_DIR":/src/$TRAIN_JOB_DIR
-e TRAIN_JOB_DIR=$TRAIN_JOB_DIR
$docker_image"
eval $DOCKER_RUN
# stream logs from container
CONTAINER_ID=$(docker ps -l -q)
docker logs $CONTAINER_ID --follow