-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
105 lines (80 loc) · 3.34 KB
/
run.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
#!/bin/bash
# The "main script" of RawSpeechClassification.
# SPDX-FileCopyrightText: Copyright © Idiap Research Institute <[email protected]>
#
# SPDX-FileContributor: S. Pavankumar Dubagunta <[email protected]>
# SPDX-FileContributor: Mathew Magimai Doss <[email protected]>
# SPDX-FileContributor: Olivier Bornet <[email protected]>
# SPDX-FileContributor: Olivier Canévet <[email protected]>
#
# SPDX-License-Identifier: GPL-3.0-only
# bash ${0} -C ~/miniconda3 -n rsclf-torch -D /path/to/dir -R /path/to/dataset
echo "Start to run on $(hostname) at $(date +'%F %T')"
SECONDS=0
CONDA_HOME=
CONDA_ENV=
spliceSize=25
arch="subseg"
datadir=
ROOT=""
######################################################################
while getopts ":C:n:o:a:D:R:" opt
do
case ${opt} in
C) CONDA_HOME="${OPTARG}" ;;
n) CONDA_ENV="${OPTARG}" ;;
o) OUTPUT="${OPTARG}" ;;
a) arch="${OPTARG}" ;;
D) datadir="${OPTARG}" ;;
R) ROOT="${OPTARG}" ;;
\?) echo "Invalid option -%s\n" "${OPTARG}" ; exit 1 ;;
esac
done
shift $(( OPTIND - 1 ))
######################################################################
[[ -z ${CONDA_HOME} ]] && echo "Missing option -C (eg: ~/miniconda3)" && exit 1
[[ -z ${CONDA_ENV} ]] && echo "Missing option -n (eg: env_name)" && exit 1
[[ -z ${datadir} ]] && echo "Missing option -D (eg: dir containing train.list, test.list, cv.list)" && exit 1
######################################################################
eval "$(${CONDA_HOME}/bin/conda shell.bash hook)"
conda activate ${CONDA_ENV}
if [[ `conda list | grep torch` ]] ; then
echo "Using torch backend"
export KERAS_BACKEND=torch
elif [[ `conda list | grep tensorflow` ]] ; then
echo "Using tensorflow backend"
export KERAS_BACKEND=tensorflow
elif [[ `conda list | grep jaxlib` ]] ; then
echo "Using jax backend"
export KERAS_BACKEND=jax
fi
mkdir -p ${OUTPUT}
conda env export > ${OUTPUT}/env.yaml
conda list > ${OUTPUT}/env.txt
echo "Using architecture '${arch}'"
exp=${OUTPUT}/cnn_${arch} # Output directory
# Wav file lists
train_list=${datadir}/train.list
cv_list=${datadir}/cv.list
test_list=${datadir}/test.list
# Feature directories
train_feat=${OUTPUT}/train_feat
cv_feat=${OUTPUT}/cv_feat
test_feat=${OUTPUT}/test_feat
# Extract features
[ -d $cv_feat ] || rsclf-wav2feat --wav-list-file $cv_list --feature-dir $cv_feat --mode "train" --root "${ROOT}"
[ -d $train_feat ] || rsclf-wav2feat --wav-list-file $train_list --feature-dir $train_feat --mode "train" --root "${ROOT}"
[ -d $test_feat ] || rsclf-wav2feat --wav-list-file $test_list --feature-dir $test_feat --mode "test" --root "${ROOT}"
# Train
[ -f $exp/cnn.keras ] || rsclf-train --train-feature-dir $train_feat --validation-feature-dir $cv_feat --output-dir $exp --arch $arch --splice-size $spliceSize --verbose 2
[ ! -f $exp/cnn.keras ] && echo "Training failed. Check logs." && exit 1
# Test
[ -s $exp/scores.txt ] || rsclf-test --feature-dir $test_feat --model-filename $exp/cnn.keras --output-dir $exp --splice-size $spliceSize --verbose 0
[ ! -s $exp/scores.txt ] && echo "Testing failed. Check logs." && exit 1
# Plot results
[ -s $exp/log.dat ] && rsclf-plot --output-dir ${OUTPUT} ${exp}
[ ! -s $OUTPUT/plot.png ] && echo "Plotting failed." && exit 1
echo "Plot saved at ${OUTPUT}/plot.png"
echo
echo "Script took $(date -u -d @${SECONDS} +"%T")"
echo "End at $(date +'%F %T')"