Advanced: Build TensorFlow

If you need to compile TensorFlow from scratch, you can do it, but its very slow to get everything compiled. Once its compiled, its really fast to train models!

We have to start this way,  until there's more automated methods...so here's a guide on how we did it

While this method takes a long time its the only way we were able to build models, hopefully there will be an easy to use pip installer soon!

We need to use version 0.23.1 of bazel (the build tool), so we'll install that specific version like this:

cd ~
curl -O -L https://github.com/bazelbuild/bazel/releases/download/0.23.1/bazel-0.23.1-installer-linux-x86_64.sh
chmod +x bazel-0.23.1-installer-linux-x86_64.sh
./bazel-0.23.1-installer-linux-x86_64.sh

You can verify it with bazel version

For some reason, the image is still using Python 2.7, so grab the future package so we can run python3 code

pip install future

We also need to get the right version of the 'estimator' package (we use it later)

pip uninstall tensorflow_estimator

pip install -I tensorflow_estimator==1.13.0

We need to build a specific commit of TensorFlow, so clone the repo then switch to that commit

git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow
git checkout 4a464440b2e8f382f442b6e952d64a56701ab045

Go with the default configuration by running

yes "" | ./configure

Finally start the TensorFlow compile and speech training with

bazel run -c opt --copt=-mavx2 --copt=-mfma tensorflow/examples/speech_commands:train -- --model_architecture=tiny_conv --window_stride=20 --preprocess=micro --wanted_words="yes,no" --silence_percentage=25 --unknown_percentage=25 --quantize=1

This will create a micro model of the large speech data set with only "yes" and "no" words in the model (to keep it small/simple)

This will take many hours especially the first time! Go take a break and do something else (or, you can try using your computer but it will be slow because Docker is sucking up all the computational resources to compile 16,000 files)

After TensorFlow has completed compiling it will take another 2+ hours to run the training. In the end you will get something like this:

This guide was first published on Jul 17, 2019. It was last updated on Jul 17, 2019. This page (Advanced: Build TensorFlow) was last updated on Dec 02, 2019.