Skip to content

Commit

Permalink
modified Makefile for pytorch, and changed document and run.sh in the…
Browse files Browse the repository at this point in the history
… WSJ recipe accordingly.
  • Loading branch information
sw005320 committed Dec 25, 2017
1 parent e72c979 commit 2e608c1
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 97 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright 2017 Johns Hopkins University (Shinji Watanabe)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Build Status](https://travis-ci.org/espnet/espnet.svg?branch=master)](https://travis-ci.org/espnet/espnet)

ESPnet is an end-to-end speech processing toolkit.
ESPnet uses [chainer](https://chainer.org/) as a main deep learning engine,
ESPnet uses [chainer](https://chainer.org/) and [pytorch](http://pytorch.org/) as a main deep learning engine,
and also follows [Kaldi](http://kaldi-asr.org/) style data processing, feature extraction/format, and recipes to provide a complete setup for speech recognition and other speech processing experiments.

## Installation
Expand Down Expand Up @@ -31,16 +31,20 @@ The following directory is an example of performing ASR experiment with the VoxF
```sh
$ cd egs/voxforge/asr1
```
Once move to the directory, then, execute the following main script:
Once move to the directory, then, execute the following main script with a chainer backend:
```sh
$ ./run.sh
```
or execute the following main script with a pytorch backend:
```sh
$ ./run.sh --backend pytorch --etype blstmp
```
With this main script, you can perform a full procedure of ASR experiments including
- Data download
- Data preparation (Kaldi style, see http://kaldi-asr.org/doc/data_prep.html)
- Feature extraction (Kaldi style, see http://kaldi-asr.org/doc/feat.html)
- Dictionary and JSON format data preparation
- Training based on [chainer](https://chainer.org/).
- Training based on [chainer](https://chainer.org/) or [pytorch](http://pytorch.org/).
- Recognition and scoring

### Error due to matplotlib
Expand Down
6 changes: 4 additions & 2 deletions egs/chime4/asr1_1ch/path.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
MAIN_ROOT=$PWD/../../..
KALDI_ROOT=$MAIN_ROOT/tools/kaldi
JQ_ROOT=$MAIN_ROOT/tools/jq
SPNET_ROOT=$MAIN_ROOT/src

[ -f $KALDI_ROOT/tools/env.sh ] && . $KALDI_ROOT/tools/env.sh
Expand All @@ -9,8 +8,11 @@ export PATH=$PWD/utils/:$KALDI_ROOT/tools/openfst/bin:$KALDI_ROOT/tools/sctk/bin
. $KALDI_ROOT/tools/config/common_path.sh
export LC_ALL=C

export PATH=$SPNET_ROOT/utils/:$SPNET_ROOT/bin/:$JQ_ROOT:$PATH
export PATH=$SPNET_ROOT/utils/:$SPNET_ROOT/bin/:$PATH
source $MAIN_ROOT/tools/venv/bin/activate
export PYTHONPATH=$SPNET_ROOT/nets/:$SPNET_ROOT/utils/:$SPNET_ROOT/bin/:$PYTHONPATH

export OMP_NUM_THREADS=1
if [[ $(hostname -f) == *.clsp.jhu.edu ]] ; then
export CUDA_VISIBLE_DEVICES=$(/usr/local/bin/free-gpu)
fi
6 changes: 4 additions & 2 deletions egs/csj/asr1/path.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
MAIN_ROOT=$PWD/../../..
KALDI_ROOT=$MAIN_ROOT/tools/kaldi
JQ_ROOT=$MAIN_ROOT/tools/jq
SPNET_ROOT=$MAIN_ROOT/src

[ -f $KALDI_ROOT/tools/env.sh ] && . $KALDI_ROOT/tools/env.sh
Expand All @@ -9,8 +8,11 @@ export PATH=$PWD/utils/:$KALDI_ROOT/tools/openfst/bin:$KALDI_ROOT/tools/sctk/bin
. $KALDI_ROOT/tools/config/common_path.sh
export LC_ALL=C

export PATH=$SPNET_ROOT/utils/:$SPNET_ROOT/bin/:$JQ_ROOT:$MAIN_ROOT/tools/nkf/nkf-2.1.4/:$PATH
export PATH=$SPNET_ROOT/utils/:$SPNET_ROOT/bin/:$MAIN_ROOT/tools/nkf/nkf-2.1.4/:$PATH
source $MAIN_ROOT/tools/venv/bin/activate
export PYTHONPATH=$SPNET_ROOT/nets/:$SPNET_ROOT/utils/:$SPNET_ROOT/bin/:$PYTHONPATH

export OMP_NUM_THREADS=1
if [[ $(hostname -f) == *.clsp.jhu.edu ]] ; then
export CUDA_VISIBLE_DEVICES=$(/usr/local/bin/free-gpu)
fi
6 changes: 4 additions & 2 deletions egs/hkust/asr1/path.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
MAIN_ROOT=$PWD/../../..
KALDI_ROOT=$MAIN_ROOT/tools/kaldi
JQ_ROOT=$MAIN_ROOT/tools/jq
SPNET_ROOT=$MAIN_ROOT/src

[ -f $KALDI_ROOT/tools/env.sh ] && . $KALDI_ROOT/tools/env.sh
Expand All @@ -9,8 +8,11 @@ export PATH=$PWD/utils/:$KALDI_ROOT/tools/openfst/bin:$KALDI_ROOT/tools/sctk/bin
. $KALDI_ROOT/tools/config/common_path.sh
export LC_ALL=C

export PATH=$SPNET_ROOT/utils/:$SPNET_ROOT/bin/:$JQ_ROOT:$PATH
export PATH=$SPNET_ROOT/utils/:$SPNET_ROOT/bin/:$PATH
source $MAIN_ROOT/tools/venv/bin/activate
export PYTHONPATH=$SPNET_ROOT/nets/:$SPNET_ROOT/utils/:$SPNET_ROOT/bin/:$PYTHONPATH

export OMP_NUM_THREADS=1
if [[ $(hostname -f) == *.clsp.jhu.edu ]] ; then
export CUDA_VISIBLE_DEVICES=$(/usr/local/bin/free-gpu)
fi
6 changes: 4 additions & 2 deletions egs/tedlium/asr1/path.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
MAIN_ROOT=$PWD/../../..
KALDI_ROOT=$MAIN_ROOT/tools/kaldi
JQ_ROOT=$MAIN_ROOT/tools/jq
SPNET_ROOT=$MAIN_ROOT/src

[ -f $KALDI_ROOT/tools/env.sh ] && . $KALDI_ROOT/tools/env.sh
Expand All @@ -9,8 +8,11 @@ export PATH=$PWD/utils/:$KALDI_ROOT/tools/openfst/bin:$KALDI_ROOT/tools/sctk/bin
. $KALDI_ROOT/tools/config/common_path.sh
export LC_ALL=C

export PATH=$SPNET_ROOT/utils/:$SPNET_ROOT/bin/:$JQ_ROOT:$PATH
export PATH=$SPNET_ROOT/utils/:$SPNET_ROOT/bin/:$PATH
source $MAIN_ROOT/tools/venv/bin/activate
export PYTHONPATH=$SPNET_ROOT/nets/:$SPNET_ROOT/utils/:$SPNET_ROOT/bin/:$PYTHONPATH

export OMP_NUM_THREADS=1
if [[ $(hostname -f) == *.clsp.jhu.edu ]] ; then
export CUDA_VISIBLE_DEVICES=$(/usr/local/bin/free-gpu)
fi
6 changes: 4 additions & 2 deletions egs/voxforge/asr1/path.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
MAIN_ROOT=$PWD/../../..
KALDI_ROOT=$MAIN_ROOT/tools/kaldi
JQ_ROOT=$MAIN_ROOT/tools/jq
SPNET_ROOT=$MAIN_ROOT/src

[ -f $KALDI_ROOT/tools/env.sh ] && . $KALDI_ROOT/tools/env.sh
Expand All @@ -9,8 +8,11 @@ export PATH=$PWD/utils/:$KALDI_ROOT/tools/openfst/bin:$KALDI_ROOT/tools/sctk/bin
. $KALDI_ROOT/tools/config/common_path.sh
export LC_ALL=C

export PATH=$SPNET_ROOT/utils/:$SPNET_ROOT/bin/:$JQ_ROOT:$PATH
export PATH=$SPNET_ROOT/utils/:$SPNET_ROOT/bin/:$PATH
source $MAIN_ROOT/tools/venv/bin/activate
export PYTHONPATH=$SPNET_ROOT/nets/:$SPNET_ROOT/utils/:$SPNET_ROOT/bin/:$PYTHONPATH

export OMP_NUM_THREADS=1
if [[ $(hostname -f) == *.clsp.jhu.edu ]] ; then
export CUDA_VISIBLE_DEVICES=$(/usr/local/bin/free-gpu)
fi
6 changes: 4 additions & 2 deletions egs/wsj/asr1/path.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
MAIN_ROOT=$PWD/../../..
KALDI_ROOT=$MAIN_ROOT/tools/kaldi
JQ_ROOT=$MAIN_ROOT/tools/jq
SPNET_ROOT=$MAIN_ROOT/src

[ -f $KALDI_ROOT/tools/env.sh ] && . $KALDI_ROOT/tools/env.sh
Expand All @@ -9,8 +8,11 @@ export PATH=$PWD/utils/:$KALDI_ROOT/tools/openfst/bin:$KALDI_ROOT/tools/sctk/bin
. $KALDI_ROOT/tools/config/common_path.sh
export LC_ALL=C

export PATH=$SPNET_ROOT/utils/:$SPNET_ROOT/bin/:$JQ_ROOT:$PATH
export PATH=$SPNET_ROOT/utils/:$SPNET_ROOT/bin/:$PATH
source $MAIN_ROOT/tools/venv/bin/activate
export PYTHONPATH=$SPNET_ROOT/nets/:$SPNET_ROOT/utils/:$SPNET_ROOT/bin/:$PYTHONPATH

export OMP_NUM_THREADS=1
if [[ $(hostname -f) == *.clsp.jhu.edu ]] ; then
export CUDA_VISIBLE_DEVICES=$(/usr/local/bin/free-gpu)
fi
71 changes: 19 additions & 52 deletions egs/wsj/asr1/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,17 @@ else
fi
mkdir -p ${expdir}

# switch backend
if [[ ${backend} == chainer ]]; then
train_script=asr_train.py
decode_script=asr_recog.py
else
train_script=asr_train_th.py
decode_script=asr_recog_th.py
fi

if [ ${stage} -le 3 ]; then
echo "stage 3: Network Training"
if [[ ${backend} == chainer ]]; then
train_script=asr_train.py
else
train_script=asr_train_th.py
fi

${cuda_cmd} ${expdir}/train.log \
${train_script} \
Expand Down Expand Up @@ -190,7 +194,7 @@ if [ ${stage} -le 3 ]; then
fi

if [ ${stage} -le 4 ]; then
echo "stage 4: Decoding data preparation"
echo "stage 4: Decoding"
nj=32

for rtask in ${recog_set}; do
Expand All @@ -201,42 +205,17 @@ if [ ${stage} -le 4 ]; then
data=data/${rtask}
split_data.sh --per-utt ${data} ${nj};

# make json labels for recognition
data2json.sh ${data} ${dict} > ${data}/data.json

) &
done
wait
echo "Finished"
fi


if [ ${stage} -le 5 ]; then
echo "stage 5: Decoding"
nj=32

for rtask in ${recog_set}; do
(
decode_dir=decode_${rtask}_beam${beam_size}_e${recog_model}_p${penalty}_len${minlenratio}-${maxlenratio}

# split data
data=data/${rtask}
sdata=${data}/split${nj}utt;

# feature extraction
feats="ark,s,cs:apply-cmvn --norm-vars=true data/${train_set}/cmvn.ark scp:${sdata}/JOB/feats.scp ark:- |"
if ${do_delta}; then
feats="$feats add-deltas ark:- ark:- |"
feats="$feats add-deltas ark:- ark:- |"
fi
#### use CPU for decoding
gpu=0

if [[ ${backend} == chainer ]]; then
decode_script=asr_recog.py
else
decode_script=asr_recog_th.py
fi
mkdir -p ${expdir}/${decode_dir}/log
# make json labels for recognition
data2json.sh ${data} ${dict} > ${data}/data.json

#### use CPU for decoding
gpu=-1

${decode_cmd} JOB=1:${nj} ${expdir}/${decode_dir}/log/decode.JOB.log \
${decode_script} \
Expand All @@ -250,24 +229,12 @@ if [ ${stage} -le 5 ]; then
--penalty ${penalty} \
--maxlenratio ${maxlenratio} \
--minlenratio ${minlenratio} \
--debugmode ${debugmode} \
--verbose ${verbose} \
&
--debugmode ${debugmode} \
--verbose ${verbose} &
wait
) &
done
wait
fi

if [ ${stage} -le 6 ]; then
echo "stage 6: Evaluation"
nj=32

for rtask in ${recog_set}; do
(
decode_dir=decode_${rtask}_beam${beam_size}_e${recog_model}_p${penalty}_len${minlenratio}-${maxlenratio}
score_sclite.sh --nlsyms ${nlsyms} ${expdir}/${decode_dir} ${dict}

) &
done
wait
Expand Down
11 changes: 2 additions & 9 deletions src/bin/asr_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,15 +418,8 @@ def main():
for key in sorted(vars(args).keys()):
logging.info('ARGS: ' + key + ': ' + str(vars(args)[key]))

if args.gpu == 'jhu':
# TODO make this one controlled at conf/gpu.conf or whatever
# this is JHU CLSP cluster setup
cmd = '/home/gkumar/scripts/free-gpu'
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout_data, stderr_data = p.communicate()
gpu_id = int(stdout_data.rstrip())
else:
gpu_id = int(args.gpu)
# Set gpu
gpu_id = int(args.gpu)
logging.info('gpu id: ' + str(gpu_id))
if gpu_id >= 0:
# Make a specified GPU current
Expand Down
11 changes: 2 additions & 9 deletions src/bin/asr_train_th.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,15 +427,8 @@ def main():
for key in sorted(vars(args).keys()):
logging.info('ARGS: ' + key + ': ' + str(vars(args)[key]))

if args.gpu == 'jhu':
# TODO make this one controlled at conf/gpu.conf or whatever
# this is JHU CLSP cluster setup
cmd = '/home/gkumar/scripts/free-gpu'
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout_data, stderr_data = p.communicate()
gpu_id = int(stdout_data.rstrip())
else:
gpu_id = int(args.gpu)
# Set gpu
gpu_id = int(args.gpu)
logging.info('gpu id: ' + str(gpu_id))
if gpu_id >= 0:
# Make a specified GPU current
Expand Down
21 changes: 10 additions & 11 deletions tools/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.PHONY: all clean


all: kaldi venv venv/bin/activate nkf kaldi-io-for-python.git pytorch warp-ctc
all: kaldi venv venv/bin/activate nkf kaldi-io-for-python.git venv/lib/python2.7/site-packages/torch warp-ctc

kaldi-io-for-python.git:
git clone https://github.com/vesis84/kaldi-io-for-python.git
Expand Down Expand Up @@ -29,17 +29,16 @@ nkf:
cd nkf; wget http://gigenet.dl.osdn.jp/nkf/64158/nkf-2.1.4.tar.gz
cd nkf; tar zxvf nkf-2.1.4.tar.gz; cd nkf-2.1.4; $(MAKE) prefix=.

clean:
rm -fr kaldi_github kaldi kaldi_python venv nkf kaldi-io-for-python ../src/utils/kaldi_io_py.py
find -iname "*.pyc" -delete


# optional deps for pytorch backends
pytorch:
pip install http://download.pytorch.org/whl/cu80/torch-0.3.0.post4-cp27-cp27mu-linux_x86_64.whl
venv/lib/python2.7/site-packages/torch: venv/bin/activate
. venv/bin/activate; pip install pip --upgrade; pip install http://download.pytorch.org/whl/cu80/torch-0.3.0.post4-cp27-cp27mu-linux_x86_64.whl

warp-ctc:
warp-ctc: venv/lib/python2.7/site-packages/torch
git clone https://github.com/SeanNaren/warp-ctc.git
cd warp-ctc && mkdir build && cd build && cmake .. && make -j4
pip install cffi
. venv/bin/activate; pip install cffi
cd warp-ctc/pytorch_binding && python setup.py install # maybe need to: apt-get install python-dev

clean:
rm -fr kaldi_github kaldi kaldi_python venv nkf kaldi-io-for-python ../src/utils/kaldi_io_py.py warp-ctc
find -iname "*.pyc" -delete

0 comments on commit 2e608c1

Please sign in to comment.