I have a few problems where I have heard TensorFlow might be the correct solution. Specifically recognizing typed documents and facial recognition. There are a few examples in this space which might be a better library but I lack even basic skills here. So! Time to get some xp to level up my understanding of this technology!

Installation

Docker is great for reducing the barrier to entry. Especially with the multiple versions of Python which might be running around on different machines. They produce multiple images however since I am just getting started I will be playing around with the CPU implementation. The images are fairly large at 1.08GBs with a docker pull tensorflow/tensorflow today. I assume this will only get larger as time goes on. Seems successful as the running the suggested command produced the following:

:> docker run -it --rm tensorflow/tensorflow \
    python -c "import tensorflow as tf; tf.enable_eager_execution(); print(tf.reduce_sum(tf.random_normal([1000, 1000])))"
2019-02-09 23:37:05.745909: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-02-09 23:37:05.761375: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2293020000 Hz
2019-02-09 23:37:05.762104: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x4c5cac0 executing computations on platform Host. Devices:
2019-02-09 23:37:05.762177: I tensorflow/compiler/xla/service/service.cc:158]   StreamExecutor device (0): <undefined>, <undefined>
tf.Tensor(533.91956, shape=(), dtype=float32)

Running docker run -it tensorflow/tensorflow bash get me a reasonable interactive environment with Python 2.7.12.

Doing the Flow

The first tutorial TensorFlow has is a classifier for fashion clothes. Seems like a reasonable start.

matplotlib

Shamelessly I dropped the first code segment into a REPL of Python! This resulted in an error highlighting a matplotlib is not installed. To get this installed I had to do the following inside the container:

pip install matplotlib
apt-get -y install python-tk

Now print(tf.__version__) yields 1.13.0-rc1.

Kicking the Tires

Fairly genius to avoid needing to instruct people on how to retrieve MNIST data by having it autodownload using (train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()! The matplotlib sensibly needs access to an X11 Display Server to view the data, which I was hoping the container had pre-setup. As I go through this I hope that does not become a road block.

The following warning was generated, I am hoping this has little impact on anything I do as I do not understand the implications.

WARNING:tensorflow:From /usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/resource_variable_ops.py:435: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.

Under Evaluating Accuracy they define overfitting as performing worse on new data than on their training data. np.argmax(predictions[0]) will provide the element it has the greatest confidence in.

With the tutorial there is a lot of information lost by not being able to visual the output in the manner suggested.

Getting matplotlib connected to X11

I mainly followed Sourabh Bajaj’s article on the subject. It boils down to three parts:

  1. Ensure the Xquartz configuration allows for remote authenticated connections.
  2. Instructing the display server to allow access from the host IP:
    • IP=$(ifconfig en0 | grep inet | awk '$1=="inet" {print $2}')
    • xhost + $IP This is the discovered IP of the host. This will change based on the network, so when your IP changes you should be aware.
  3. Add -e DISPLAY=$IP:0 -v /tmp/.X11-unix:/tmp/.X11-unix to your docker command.

You can confirm this by using apt-get -y install xterm. This will install a number of libraries but will prove if your connection works as intended.

Conclusion

Not all visualizations worked as expected with this method. Which was a bit sad. However I was able to get the predictions to occur as expected from the tutorial. I will need to spend more time digesting what is going on there. There are many questions I have! Like how do we know the two layers are sufficient? If we create more layers can we get higher certainty? Or do I need more nodes per layer?