Tensorflow Tutorial

  2 mins read  

Tensorflow Tutorial

Install python and tensorflow

  1. Input the flowing command to install python:

    sudo apt-get install python-dev python-pip
    

    python_install_command

  2. Input the flowing command to install tensorflow:

    export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.3.0-cp27-none-linux_x86_64.whl
    sudo pip install $TF_BINARY_URL
    

    tflearn

    tflearn

  3. Check whether the tensorflow is installed successfully:

    python
    import tensorflow as tf
    print tf.__version__
    

    tf_version

Make some configuration for the vim

vim ~/.vimrc
set ts=4
set nu

vim_vimrc

vimrc_content

Examples

First example

import tensorflow as tf

a=tf.constant([1.0,2.0])
b=tf.constant([3.0,4.0])
result=a+b
print result

tf3_1tf3_1_content

Graph: Build the calculation process of the neural network, but do not perform the calculation.

3_1_result_explanationgraph

Second example

import tensorflow as tf

x = tf.constant([[1.0,2.0]])
w = tf.constant([[3.0],[4.0]])
y = tf.matmul(x,w)
print y
with tf.Session() as sess:
    print sess.run(y)

Session:

A class for running TensorFlow operations.

A Session object encapsulates the environment in which Operation objects are executed, and Tensor objects are evaluated.

tf3_2

tf3_2_content

Now, there are many warnings, and we can remove them by modifying the .bashrc file. First, we need to do is adding export TF_CPP_MIN_LOG_LEVEL=2 to the end of this file. Then, we should input source ~/.bashrc, and execute this command to make the change that we just made effective. Finally, after we run tf3_2.py again, we can find that those warnings are disappearing now.

clear_warings

bashrc_adding_content