From f148dbd23a90180fc2b37276e184322b6f4ec36b Mon Sep 17 00:00:00 2001 From: josh Date: Fri, 22 Mar 2019 22:31:09 +0100 Subject: [PATCH] getting the outputs shaped correctly --- .compute | 41 ++++++++++++++++++++++------------------- DeepSpeech.py | 21 +++++++++++++++++---- util/flags.py | 4 ++++ 3 files changed, 43 insertions(+), 23 deletions(-) diff --git a/.compute b/.compute index 629e3d4f..d5854db1 100755 --- a/.compute +++ b/.compute @@ -2,6 +2,11 @@ set -xe +# check HTTP_PROXY +if ! (( $( env | grep -iq "^http_proxy=" ) )); then + source /etc/profile +fi + apt-get install -y python3-venv python3 -m venv /tmp/venv source /tmp/venv/bin/activate @@ -11,28 +16,26 @@ pip install tensorflow-gpu==1.13.0-rc2 # Install ds_ctcdecoder package from TaskCluster pip install $(python3 util/taskcluster.py --decoder) +pip install pandas mkdir -p ../keep/summaries -data="${SHARED_DIR}/data" -fis="${data}/LDC/fisher" -swb="${data}/LDC/LDC97S62/swb" -lbs="${data}/OpenSLR/LibriSpeech/librivox" +CV="${SHARED_DIR}/data/mozilla/CommonVoice/v2.0" python -u DeepSpeech.py \ --notest\ - --train_welsh\ - --dev_welsh \ - --train_kyrgyz\ - --dev_kyrgyz \ - --train_batch_size 24 \ - --dev_batch_size 48 \ - --test_batch_size 48 \ - --n_hidden 2048 \ - --learning_rate 0.0001 \ - --dropout_rate 0.2 \ - --epoch 13 \ - --display_step 0 \ - --validation_step 1 \ - --checkpoint_dir "../keep" \ - --summary_dir "../keep/summaries" + --train_welsh "${CV}/cy/clips/train.csv"\ + --dev_welsh "${CV}/cy/clips/dev.csv"\ + --train_kyrgyz "${CV}/ky/clips/train.csv"\ + --dev_kyrgyz "${CV}/ky/clips/dev.csv"\ + --train_batch_size 24 \ + --dev_batch_size 48 \ + --test_batch_size 48 \ + --n_hidden 2048 \ + --learning_rate 0.0001 \ + --dropout_rate 0.2 \ + --epoch 13 \ + --display_step 0 \ + --validation_step 1 \ + --checkpoint_dir "../keep" \ + --summary_dir "../keep/summaries" diff --git a/DeepSpeech.py b/DeepSpeech.py index 86c1ec09..a4e756e4 100755 --- a/DeepSpeech.py +++ b/DeepSpeech.py @@ -16,7 +16,7 @@ import progressbar import shutil import tensorflow as tf import traceback - +import pandas from ds_ctcdecoder import ctc_beam_search_decoder, Scorer from six.moves import zip, range from tensorflow.python.tools import freeze_graph @@ -187,11 +187,24 @@ def calculate_mean_edit_distance_and_loss(model_feeder, tower, dropout, reuse): # Calculate the logits of the batch using BiRNN logits, _ = BiRNN(batch_x, batch_seq_len, dropout, reuse) + # SPECIAL FOR LANG-ID + + batch_shape = tf.shape(batch_x) + batch_size = batch_shape[0] + n_steps = batch_shape[1] + output = logits + # permute time and batch + output = tf.reshape(output, [n_steps, batch_size, -1]) + output = tf.transpose(output, [1, 0, 2]) + output = tf.reshape(output, [batch_size, n_steps, -1]) + # mean over time steps + output = tf.reduce_sum(output, axis=1) / tf.cast(batch_seq_len, tf.float32) + total_loss = tf.nn.sigmoid_cross_entropy_with_logits( + labels=tf.cast(batch_y, tf.float32), logits=output + ) + # Compute the CTC loss using TensorFlow's `ctc_loss` #total_loss = tf.nn.ctc_loss(labels=batch_y, inputs=logits, sequence_length=batch_seq_len) - total_loss = tf.nn.sigmoid_cross_entropy_with_logits( - labels=tf.cast(batch_y, tf.float32), logits - ) output_probs = tf.sigmoid(output) prediction = tf.cast(output_probs > 0.5, tf.int32) diff --git a/util/flags.py b/util/flags.py index 88c1ccb4..77a05250 100644 --- a/util/flags.py +++ b/util/flags.py @@ -10,6 +10,10 @@ def create_flags(): # Importer # ======== + tf.app.flags.DEFINE_string ('train_welsh', '', 'comma separated list of files specifying the dataset used for training. multiple files will get merged') + tf.app.flags.DEFINE_string ('dev_welsh', '', 'comma separated list of files specifying the dataset used for validation. multiple files will get merged') + tf.app.flags.DEFINE_string ('train_kyrgyz', '', 'comma separated list of files specifying the dataset used for training. multiple files will get merged') + tf.app.flags.DEFINE_string ('dev_kyrgyz', '', 'comma separated list of files specifying the dataset used for validation. multiple files will get merged') tf.app.flags.DEFINE_string ('train_files', '', 'comma separated list of files specifying the dataset used for training. multiple files will get merged') tf.app.flags.DEFINE_string ('dev_files', '', 'comma separated list of files specifying the dataset used for validation. multiple files will get merged') tf.app.flags.DEFINE_string ('test_files', '', 'comma separated list of files specifying the dataset used for testing. multiple files will get merged')