Testing Out TensorFlow Environment

Testing Out TensorFlow Environment.

Posted by vishwambharu@gmail.com on December 11, 2016

Automated driving sounds cool, so I'm too excited to learn something about the technologies involved in this space. And one of the first things I had to do was to learn TensorFlow.

Here are the steps I used to install TensorFlow on macOS Sierra.

  • Install Anaconda.
  • Run the following steps to setup Anaconda environment:
    conda create --name=IntroToTensorFlow python=3 anaconda
    source activate IntroToTensorFlow
    conda install -c conda-forge tensorflow
    
  • Run the following code in your favourate python code editor to make sure TensorFlow environment is working as expected:
    import tensorflow as tf
    import numpy as np
    import matplotlib.pyplot as plt
    %matplotlib inline
    
    # 2x5 Tensor of randomally distributed numbers
    normal = tf.random_normal([2, 5], mean=2.0, stddev=4.0)
    with tf.Session() as sess:
        out = sess.run(normal)
        print(out) # print the 2x5 matrix
        x, y = out # split up the 2x5 matrix into two 1x5 vectors, x and y
        plt.scatter(x, y) # create scatter plot with x and y
        plt.show() # show scatter plot
    
    You should see the scatter plot output something similar to this: Output