-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_autoenc.sh
executable file
·137 lines (101 loc) · 3.53 KB
/
run_autoenc.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
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
#!/usr/bin/env bash
### Define your parameters here:
DEFAULT_CAFFE_ROOT=~/scr/conv/caffe
if [ -z "${CAFFE_ROOT}" ]; then
CAFFE_ROOT=${DEFAULT_CAFFE_ROOT}
fi
DATAROOT=dataset/autoencoder/conditions
DATASET=noisy_to_clean
NET=ae
### Helper functions
MAXFILES=$1
SAMPLES=$2
TIMESLICE=$3
LR=$4
GAMMA=$5
REG=$6
MAXITER=$7
AUGMENT=$8
NNARCH=$9
TESTSETSIZE=`python -c "print int($MAXFILES * $SAMPLES * .7)"`
LOSSWEIGHT=`python -c "print 1./($TIMESLICE*257)"`
AUGMENTSTRING=""
if [ $AUGMENT -eq 1 ]; then
AUGMENTSTRING="--augment_input"
fi
echo "TEST SET SIZE: $TESTSETSIZE"
echo "LOSS WEIGHT: $LOSSWEIGHT"
DATACOND=ae_${DATASET}.f${MAXFILES}.s${SAMPLES}.t${TIMESLICE}
EXPTNAME=${DATACOND}.lr${LR}.g${GAMMA}.reg${REG}.iter${MAXITER}.aug${AUGMENT}.nn_${NNARCH}
TRAINDIR=project/cnn-speech-denoising/${DATAROOT}/${DATACOND}/train/sampled
TESTDIR=project/cnn-speech-denoising/${DATAROOT}/${DATACOND}/dev/sampled
LOGDIR=${CAFFE_ROOT}/project/cnn-speech-denoising/log
SPLITLOG=${LOGDIR}/${EXPTNAME}.split.log
SAMPLELOG=${LOGDIR}/${EXPTNAME}.sample.log
CAFFELOG=${LOGDIR}/${EXPTNAME}.caffe.log
STARTDIR=$PWD
fail() {
cd $STARTDIR
exit 1
}
success() {
cd $STARTDIR
exit 0
}
cd_proj() {
cd ${CAFFE_ROOT}/project/cnn-speech-denoising
}
cd_caffe() {
cd ${CAFFE_ROOT}
}
split() {
echo Splitting dataset to $SPLITLOG
cd_proj
if [ ! -d $DATAROOT/$DATACOND ]; then
# do a 70/30 split on the ${DATASET} dataset in to train and dev
python autoenc_split_dataset.py $DATAROOT/${DATASET} $DATAROOT/$DATACOND --max_files_to_process $MAXFILES > $SPLITLOG || fail
else
echo "Reusing previous split()..."
fi
}
sample() {
echo Sampling dataset to $SAMPLELOG
cd_proj
if [ ! -d $DATAROOT/$DATACOND/train/sampled ]; then
# sample the training data, normalize and dump the normalization params to disk
python autoenc_patch_sampler.py $DATAROOT/${DATACOND}/train $AUGMENTSTRING --samples_per_file $SAMPLES --normalize_spec $DATAROOT/${DATACOND}/trained_normalization_params.pkl --x_len $TIMESLICE > $SAMPLELOG || fail
# sample the dev data, normalize using the normalization params dumped during training
python autoenc_patch_sampler.py $DATAROOT/${DATACOND}/dev $AUGMENTSTRING --samples_per_file $SAMPLES --normalize_spec $DATAROOT/${DATACOND}/trained_normalization_params.pkl --x_len $TIMESLICE --dev >> $SAMPLELOG || fail
else
echo "Reusing previous sample()..."
fi
}
train() {
echo Training caffe to $CAFFELOG
cd_caffe
in_net=project/cnn-speech-denoising/models/model0/${NET}.prototxt.template
out_net=project/cnn-speech-denoising/models/model0/${EXPTNAME}.prototxt
python project/cnn-speech-denoising/resolveTemplateVars.py --net $NNARCH $in_net $out_net \
"+TEST_DIR+,${TESTDIR}" \
"+TRAIN_DIR+,${TRAINDIR}" \
"+LOSS_WEIGHT+,${LOSSWEIGHT}"
in_solver=project/cnn-speech-denoising/models/model0/${NET}_solver.prototxt.template
out_solver=project/cnn-speech-denoising/models/model0/${EXPTNAME}_solver.prototxt
python project/cnn-speech-denoising/resolveTemplateVars.py $in_solver $out_solver \
"+EXPT_NAME+,${EXPTNAME}" \
"+LEARNING_RATE+,${LR}" \
"+GAMMA+,${GAMMA}" \
"+MAX_ITER+,${MAXITER}" \
"+REG+,${REG}" \
"+TEST_SET_SIZE+,${TESTSETSIZE}"
./build/tools/caffe train \
--solver=project/cnn-speech-denoising/models/model0/${EXPTNAME}_solver.prototxt > $CAFFELOG 2>&1 || fail
}
### Run what you want here:
mkdir -p $LOGDIR
# If the directory $DATAROOT/$DATACOND already exists, these will be no-ops and will reuse existing data
split
sample
# This trains caffe
train
success