Skip to content

Commit

Permalink
Added conda local install, partialy adjusted model to pycandle
Browse files Browse the repository at this point in the history
  • Loading branch information
w.jurasz committed Jun 4, 2019
1 parent 993e5ec commit e5ff4c3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
22 changes: 14 additions & 8 deletions install_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ case ${i} in
CUDA="${i#*=}"
shift # past argument=value
;;
-e=*|--venv=*)
VENV="${i#*=}"
-a=*|--anaconda=*)
ANACONDA="${i#*=}"
shift # past argument=value
;;
-p=*|--python_path=*)
VENV_PATH="${i#*=}"
-e=*|--venv=*)
VENV="${i#*=}"
shift # past argument=value
;;
*)
Expand All @@ -26,11 +26,12 @@ case ${i} in
esac
done

VENV=${VENV:-true}
VENV=${VENV:-./venv}

if [ "$VENV" = true ] ; then
VENV_PATH=${VENV_PATH:-./venv}
source ${VENV_PATH}/bin/activate
if [ -z ${ANACONDA+x} ] ; then
conda activate ${ANACONDA}
elif [ -z ${VENV+x} ] ; then
source ${VENV}/bin/activate
fi

#TODO: Infer this automatically
Expand All @@ -50,4 +51,9 @@ cd ../pytorch_binding && python setup.py install
cd ../..
rm -rf warp-ctc

git clone [email protected]:pytorch/audio.git
cd audio; MACOSX_DEPLOYMENT_TARGET=10.9 CC=clang CXX=clang++ python setup.py install
cd ..
rm -rf audio

pip install -r post_requirements.txt
1 change: 0 additions & 1 deletion post_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
-e git://github.com/pytorch/audio.git#egg=torchaudio-0.2
-e git://github.com/NVIDIA/apex.git#egg=apex
5 changes: 3 additions & 2 deletions sonosco/datasets/AudioDataLoader.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def _collate_fn(self, batch):
inputs[x][0].narrow(1, 0, batch[x][0].size(1)).copy_(batch[x][0])
input_percentages[x] = batch[x][0].size(1) / float(max_seqlength)
target_sizes[x] = len(batch[x][1])
targets.extend(batch[x][1])
targets.append([batch[x][1]])

return inputs, torch.IntTensor(targets), input_percentages, torch.from_numpy(target_sizes)
# return inputs, torch.IntTensor(targets), input_percentages, torch.from_numpy(target_sizes)
return (inputs, input_percentages), torch.IntTensor(targets)
12 changes: 8 additions & 4 deletions sonosco/models/deepspeech2.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,14 @@ def forward(self, input_):


class BatchRNN(nn.Module):
def __init__(self, input_size, hidden_size, rnn_type=nn.LSTM, batch_norm=True):
def __init__(self, input_size, hidden_size, rnn_type=nn.LSTM, batch_norm=True, bidirectional=True):
super(BatchRNN, self).__init__()
self.bidirectional = bidirectional
self.input_size = input_size
self.hidden_size = hidden_size
self.batch_norm = SequenceWise(nn.BatchNorm1d(input_size)) if batch_norm else None
self.rnn = rnn_type(input_size=input_size, hidden_size=hidden_size,
bidirectional=True, bias=True)
bidirectional=self.bidirectional, bias=True)

def flatten_parameters(self):
self.rnn.flatten_parameters()
Expand Down Expand Up @@ -155,9 +156,12 @@ def __init__(self, rnn_type=nn.LSTM, labels="abc", rnn_hid_size=768, nb_layers=5

self.inference_softmax = InferenceBatchSoftmax()

def forward(self, x, lengths):
def forward(self, xx):
# if x.is_cuda and self.mixed_precision:
# x = x.half()
x, input_percentages = xx

lengths = input_percentages.mul_(int(x.size(3))).int()
lengths = lengths.cpu().int()
output_lengths = self.get_seq_lens(lengths)
x, _ = self.conv(x, output_lengths)
Expand All @@ -176,7 +180,7 @@ def forward(self, x, lengths):
x = x.transpose(0, 1)
# identity in training mode, softmax in eval mode
x = self.inference_softmax(x)
return x, output_lengths
return x

def get_seq_lens(self, input_length):
"""
Expand Down
2 changes: 1 addition & 1 deletion sonosco/pycandle_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ def load_datasets(manifest_path, batch_size_train, batch_size_test):
train_loader = load_datasets("./datasets/download_datasets/libri_test_clean_manifest.csv",
batch_size_train=64, batch_size_test=64)
optimizer = torch.optim.Adam(model.parameters(), lr=0.01)
model_trainer = ModelTrainer(model, optimizer, F.nll_loss, 20, train_loader, gpu=0)
model_trainer = ModelTrainer(model, optimizer, F.nll_loss, 20, train_loader, gpu=None)
model_trainer.start_training()

0 comments on commit e5ff4c3

Please sign in to comment.