Setup Machine Learning Environment

Setup on macOS 10.12.5 — Following Goal. Setup Keras with tensorflow or cntk backend for machine learning (includes deep learning). (I decided to be based on Python 2.7)

Step 1: Download Anaconda Command Line Installer and run it as follows. Go through the wizards steps, afterwards check the installation i.e.

$ bash Anaconda2–4.4.0-MacOSX-x86_64.sh
...
$ which python
/Users/ak/Applications/anaconda2/bin/python
akmac2:~ ak$ python
Python 2.7.13 |Anaconda 4.4.0 (x86_64)| (default, Dec 20 2016, 23:05:08)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> exit()
$

Create a workspace directory where you want to store your project files

$ mkdir $HOME/Workspace/deeplearning
$ cd $HOME/Workspace/deeplearning

Step 2: Install Tensorflow inside an anaconda environment

$ conda create -n keras
Fetching package metadata .........
Solving package specifications:
Package plan for installation in environment /Users/ak/Applications/anaconda2/envs/keras
..
$ source activate keras
(keras) deeplearning $ pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.2.1-py2-none-any.whl
...
...
(keras) deeplearning $

Hint: To leave the conda environment just use: source deactivate keras.

Step 3: Test tensorflow installation

# Deactivated Warnings https://github.com/tensorflow/tensorflow/issues/7778
(keras) deeplearning $ vi hellotf.py
import os
import tensorflow as tf
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
(keras) deeplearning $ python hellotf.py
Hello, TensorFlow!

Hint: Setting TF_CPP_MIN_LOG_LEVEL to 2 disables warnings.

Step 4: Install Keras and test keras installation

(keras) deeplearning $ pip install keras
...
Successfully installed keras-2.0.6 theano-0.9.0
(keras) deeplearning $ curl https://raw.githubusercontent.com/fchollet/keras/master/examples/mnist_mlp.py -O
...
(keras) deeplearning $ python mnist_mlp.py
...
Test loss: 0.0875640926854 (3 epochs)
Test accuracy: 0.9747 (3 epochs)

Disclaimer: A MacBook might not be the best device for machine learning. I hope it will be sufficient to get hands on some practical use cases for object detection. Stay tuned for more details.

Resources