If you are new to tensorflow, we recommend to start this series from part 1
After reading this article you will know,
- installing tensorflow
- basic construct of tensorflow model
- some popular functions of tensorflow
Before even begin installing tensorflow, I am assuming you have already installed anaconda with python 3.6, if not then comment below. Setting up tensorflow, is quite simple, follow these steps
Making base environment as a tensorflow environment
- Open anaconda prompt
- type following command for cpu version of tf
pip install --ignore-installed --upgrade tensorflow
- type following command for gpu version of tf
pip install --ignore-installed --upgrade tensorflow-gpu
though above method works well but, It is recommend to create a separate tensorflow environment. For this follow following steps.
- Open anaconda prompt
- create a environment in anaconda named tensorflow
conda create -n tensorflow pip python=3.6
- activate the tenorflow environment by issuing following command
then install it by running same above commands for cpu or gpu. you can think of environment as workspace in anaconda.To check if tensorflow properly installed type following in ipython notebook.
import tensorflow as tf string = tf.constant('Hello world') print(tf.Session().run(string))
Basic Construct of tensorflow model
tensorflow model consist of mainly following parts defined in a sequence,
- Defining placeholders
tf.placeholder(tf.float32) #this creates a placeholder of type float, it can also be created as matrix or array
- we can also create weight and bias matrix
Weight_matrix = tf.Variable(tf.zeros([x_dimension, y_dimension])) #creates weight matrix bias_matrix = tf.Variable(tf.zeros(['total no of bias needed'])) #create a bias matrix
- define loss function for e.g Mean squared loss
- if you remembered how we calculate predicted_y in simple logistic unit
predicted_y = tf.nn.sigmoid(tf.matmul(x, W) + b)
- after this we can define a optimizer for our model, for e.g gradient descent optimizer.
optimization = tf.train.GradientDescentOptimizer(0.1).minimize(loss_function)
The following parts will change according to problem statement but for a simple logistic unit this is the parts we construct.
Popular functions of tensorflow
There are many function in whole tensorflow framework covering all is beyond scope of this article, so we will cover only those which we will be using
tf.nn.sigmoid : It produce element wise sigmoid activated value of a matrix vector or scaler.
tf.matmul : It is a efficient implementation of dot product in tensorflow.
tf.train : train is itself not a function but a class which contains implementation of almost all popular optimizers like GD, SGD, rms_prop, adadelta etc.
rest of the functions will be covered as we go in more detail, In next article we will cover how you can build a complete MLP for MNIST using tensorflow.
For part 3 click here.