Skip to content

Commit

Permalink
Update to TensorFlow 1.13
Browse files Browse the repository at this point in the history
  • Loading branch information
reuben committed Mar 19, 2019
1 parent ff356f3 commit 91fa181
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 35 deletions.
16 changes: 5 additions & 11 deletions DeepSpeech.py
Expand Up @@ -27,12 +27,6 @@
from util.preprocess import preprocess
from util.text import Alphabet

#TODO: remove once fully switched to 1.13
try:
import tensorflow.lite as lite # 1.13
except ImportError:
import tensorflow.contrib.lite as lite # 1.12


# Graph Creation
# ==============
Expand Down Expand Up @@ -91,21 +85,21 @@ def BiRNN(batch_x, seq_length, dropout, reuse=False, batch_size=None, n_steps=-1
b1 = variable_on_worker_level('b1', [Config.n_hidden_1], tf.zeros_initializer())
h1 = variable_on_worker_level('h1', [Config.n_input + 2*Config.n_input*Config.n_context, Config.n_hidden_1], tf.contrib.layers.xavier_initializer())
layer_1 = tf.minimum(tf.nn.relu(tf.add(tf.matmul(batch_x, h1), b1)), FLAGS.relu_clip)
layer_1 = tf.nn.dropout(layer_1, (1.0 - dropout[0]))
layer_1 = tf.nn.dropout(layer_1, rate=dropout[0])
layers['layer_1'] = layer_1

# 2nd layer
b2 = variable_on_worker_level('b2', [Config.n_hidden_2], tf.zeros_initializer())
h2 = variable_on_worker_level('h2', [Config.n_hidden_1, Config.n_hidden_2], tf.contrib.layers.xavier_initializer())
layer_2 = tf.minimum(tf.nn.relu(tf.add(tf.matmul(layer_1, h2), b2)), FLAGS.relu_clip)
layer_2 = tf.nn.dropout(layer_2, (1.0 - dropout[1]))
layer_2 = tf.nn.dropout(layer_2, rate=dropout[1])
layers['layer_2'] = layer_2

# 3rd layer
b3 = variable_on_worker_level('b3', [Config.n_hidden_3], tf.zeros_initializer())
h3 = variable_on_worker_level('h3', [Config.n_hidden_2, Config.n_hidden_3], tf.contrib.layers.xavier_initializer())
layer_3 = tf.minimum(tf.nn.relu(tf.add(tf.matmul(layer_2, h3), b3)), FLAGS.relu_clip)
layer_3 = tf.nn.dropout(layer_3, (1.0 - dropout[2]))
layer_3 = tf.nn.dropout(layer_3, rate=dropout[2])
layers['layer_3'] = layer_3

# Now we create the forward and backward LSTM units.
Expand Down Expand Up @@ -149,7 +143,7 @@ def BiRNN(batch_x, seq_length, dropout, reuse=False, batch_size=None, n_steps=-1
b5 = variable_on_worker_level('b5', [Config.n_hidden_5], tf.zeros_initializer())
h5 = variable_on_worker_level('h5', [Config.n_cell_dim, Config.n_hidden_5], tf.contrib.layers.xavier_initializer())
layer_5 = tf.minimum(tf.nn.relu(tf.add(tf.matmul(output, h5), b5)), FLAGS.relu_clip)
layer_5 = tf.nn.dropout(layer_5, (1.0 - dropout[5]))
layer_5 = tf.nn.dropout(layer_5, rate=dropout[5])
layers['layer_5'] = layer_5

# Now we apply the weight matrix `h6` and bias `b6` to the output of `layer_5`
Expand Down Expand Up @@ -821,7 +815,7 @@ def do_graph_freeze(output_file=None, output_node_names=None, variables_blacklis
frozen_graph = do_graph_freeze(output_node_names=output_names, variables_blacklist='')
output_tflite_path = os.path.join(FLAGS.export_dir, output_filename.replace('.pb', '.tflite'))

converter = lite.TFLiteConverter(frozen_graph, input_tensors=inputs.values(), output_tensors=outputs.values())
converter = tf.lite.TFLiteConverter(frozen_graph, input_tensors=inputs.values(), output_tensors=outputs.values())
converter.post_training_quantize = True
tflite_model = converter.convert()

Expand Down
32 changes: 15 additions & 17 deletions Dockerfile
@@ -1,6 +1,6 @@
# Need devel version cause we need /usr/include/cudnn.h
# for compiling libctc_decoder_with_kenlm.so
FROM nvidia/cuda:9.0-cudnn7-devel-ubuntu16.04
FROM nvidia/cuda:10.0-cudnn7-devel-ubuntu18.04


# >> START Install base software
Expand Down Expand Up @@ -31,21 +31,21 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
liblzma-dev \
locales \
pkg-config \
libsox-dev
libsox-dev \
openjdk-8-jdk \
bash-completion \
g++ \
unzip

# Install NCCL 2.2
RUN apt-get install -qq -y --allow-downgrades --allow-change-held-packages libnccl2=2.2.13-1+cuda9.0 libnccl-dev=2.2.13-1+cuda9.0

RUN apt-get install -qq -y --allow-downgrades --allow-change-held-packages libnccl2=2.3.7-1+cuda10.0 libnccl-dev=2.3.7-1+cuda10.0

# Install Bazel
RUN apt-get install -y openjdk-8-jdk
# Use bazel 0.11.1 cause newer bazel fails to compile TensorFlow (https://github.com/tensorflow/tensorflow/issues/18450#issuecomment-381380000)
RUN apt-get install -y --no-install-recommends bash-completion g++ zlib1g-dev
RUN curl -LO "https://github.com/bazelbuild/bazel/releases/download/0.15.2/bazel_0.15.2-linux-x86_64.deb"
RUN curl -LO "https://github.com/bazelbuild/bazel/releases/download/0.19.2/bazel_0.19.2-linux-x86_64.deb"
RUN dpkg -i bazel_*.deb

# Install CUDA CLI Tools
RUN apt-get install -qq -y cuda-command-line-tools-9-0
RUN apt-get install -qq -y cuda-command-line-tools-10-0

# Install pip
RUN wget https://bootstrap.pypa.io/get-pip.py && \
Expand All @@ -62,19 +62,17 @@ RUN wget https://bootstrap.pypa.io/get-pip.py && \
# Clone TensoFlow from Mozilla repo
RUN git clone https://github.com/mozilla/tensorflow/
WORKDIR /tensorflow
RUN git checkout r1.12
RUN git checkout r1.13


# GPU Environment Setup
ENV TF_NEED_CUDA 1
ENV CUDA_TOOLKIT_PATH /usr/local/cuda
ENV CUDA_PKG_VERSION 9-0=9.0.176-1
ENV CUDA_VERSION 9.0.176
ENV TF_CUDA_VERSION 9.0
ENV TF_CUDNN_VERSION 7.3.0
ENV TF_CUDA_VERSION 10.0
ENV TF_CUDNN_VERSION 7
ENV CUDNN_INSTALL_PATH /usr/lib/x86_64-linux-gnu/
ENV TF_CUDA_COMPUTE_CAPABILITIES 6.0
ENV TF_NCCL_VERSION 2.2.13
ENV TF_NCCL_VERSION 2.3
# ENV NCCL_INSTALL_PATH /usr/lib/x86_64-linux-gnu/

# Common Environment Setup
Expand Down Expand Up @@ -186,7 +184,7 @@ RUN cp /tensorflow/bazel-bin/native_client/generate_trie /DeepSpeech/native_clie

# Install TensorFlow
WORKDIR /DeepSpeech/
RUN pip install tensorflow-gpu==1.12.0
RUN pip install tensorflow-gpu==1.13.1


# Make DeepSpeech and install Python bindings
Expand All @@ -212,7 +210,7 @@ ENV PYTHONIOENCODING UTF-8
# Build KenLM in /DeepSpeech/native_client/kenlm folder
WORKDIR /DeepSpeech/native_client
RUN rm -rf kenlm \
&& git clone https://github.com/kpu/kenlm && cd kenlm \
&& git clone --depth 1 https://github.com/kpu/kenlm && cd kenlm \
&& mkdir -p build \
&& cd build \
&& cmake .. \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -238,7 +238,7 @@ If you have a capable (Nvidia, at least 8GB of VRAM) GPU, it is highly recommend

```bash
pip3 uninstall tensorflow
pip3 install 'tensorflow-gpu==1.12.0'
pip3 install 'tensorflow-gpu==1.13.1'
```

Please ensure you have the required [CUDA dependency](#cuda-dependency).
Expand Down
4 changes: 2 additions & 2 deletions native_client/BUILD
Expand Up @@ -3,7 +3,7 @@
load("@org_tensorflow//tensorflow:tensorflow.bzl",
"tf_cc_shared_object", "if_cuda")

load("@org_tensorflow//tensorflow/contrib/lite:build_def.bzl",
load("@org_tensorflow//tensorflow/lite:build_def.bzl",
"tflite_copts", "tflite_linkopts")

config_setting(
Expand Down Expand Up @@ -92,7 +92,7 @@ tf_cc_shared_object(
}) + tflite_linkopts(),
deps = select({
"//native_client:tflite": [
"//tensorflow/contrib/lite/kernels:builtin_ops",
"//tensorflow/lite/kernels:builtin_ops",
],
"//conditions:default": [
"//tensorflow/core:core_cpu",
Expand Down
2 changes: 1 addition & 1 deletion native_client/README.md
Expand Up @@ -50,7 +50,7 @@ Check the [main README](../README.md) for more details.
If you'd like to build the binaries yourself, you'll need the following pre-requisites downloaded/installed:

* [TensorFlow requirements](https://www.tensorflow.org/install/install_sources)
* [TensorFlow `r1.12` sources](https://github.com/mozilla/tensorflow/tree/r1.12)
* [TensorFlow `r1.13` sources](https://github.com/mozilla/tensorflow/tree/r1.13)
* [libsox](https://sourceforge.net/projects/sox/)

It is required to use our fork of TensorFlow since it includes fixes for common problems encountered when building the native client files.
Expand Down
4 changes: 2 additions & 2 deletions native_client/deepspeech.cc
Expand Up @@ -19,8 +19,8 @@
#include "tensorflow/core/platform/env.h"
#include "tensorflow/core/util/memmapped_file_system.h"
#else // USE_TFLITE
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/kernels/register.h"
#include "tensorflow/lite/model.h"
#include "tensorflow/lite/kernels/register.h"
#endif // USE_TFLITE

#include "c_speech_features.h"
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
@@ -1,7 +1,7 @@
pandas
progressbar2
python-utils
tensorflow == 1.12.0
tensorflow == 1.13.1
numpy == 1.15.4
matplotlib
scipy
Expand Down

0 comments on commit 91fa181

Please sign in to comment.