A Beginner’s Guide to TensorFlow: Installation, Concepts, and Key Features
Hasanul Banna Himel
Beta MLSA | Postman student expert | Prev SWE Fellow @Headstarter
What is Tensorflow ?
Applications of Tensorflow :
Tensorflow is used in applications such as Search Engines, Text Translation, Image Captioning, Recommendation Systems, etc
Installation of Tensorflow :
1. Installing tensorflow in python3
$ pip3 install tensorflow
2. Install Tensorflow in Anaconda Environment
$ conda install tensorflow
Tensor
A tensor is a typed multi-dimenstional array. It can be 0-dimensional, 1-dimensional, 2-dimensional and 3-dimensional or n-dimensional.
Types of Tensors :
Important Keywords :
1. Shape of a tensor :
>> tensor.shape
2. Constant :
a = tf.constant([[1, 2], [3, 4]])
3. Variable :
领英推荐
new_variable = tf.Variable([.5], dtype=tf.float32)
new_variable = tf.get_variable("my_variable", [1, 2, 3])
4. Placeholder :
5. Rank :
Important Components of Tensorflow:
1. Graph:
tf.get_default_graph()
# Creating a new graph
graph = tf.graph()
# Printing all operations in a graph
print(graph.get_operations())
Advantages of Graphs :
2. Session:
with tf.Session() as sess: # Creating a session
# Perform operations here
Mathematical operations of Tensorflow
>> tf.add(x,y) # Add two tensors of same type, x+y
>> tf.sub(x, y) # Subtract two tensors of same type, x-y
>> tf.mul(x, y) # Multiply two tensors element-wise
>> tf.pow(x, y) # Element-wise power of x to y
>> tf.exp(x) # Equivalent to pow(e, x)
>> tf.sqrt(x) # Equivlent to pow(x, 0.5)
>> tf.div(x, y) # Element wise division of x and y
>> tf.truediv(x, y) # Same as tf.div, but casts the arguments as float
>> tf.floordiv(x, y) # Same as truediv, excepts rouds final answer to an integer
>> tf.mod(x, y) # Element wise remainder from division
3. Graph Visualizer
It is a component of TensorBoard that renders the structure of your graph visually in browser.
# Saving a graph for visualization
with tf.Session() as sess:
writer = tf.summary.FileWriter("/tmp/log/...", sess.graph)
Imperative Programming Environment used by Tensorflow
Eager Execution
tf.enable_eager_execution() # To enable eager execution in old versions of Tensorflow