TensorFlow provides multiple APIs (Application Programming Interfaces). These can be classified into 2 major categories:
Low-level API:
- complete programming control
- recommended for machine learning researchers
- provides fine levels of control over the models
- TensorFlow Core is the low-level API of TensorFlow.
High-level API: - built on top of TensorFlow Core
- easier to learn and use than TensorFlow Core
- make repetitive tasks easier and more consistent between different users
- tf.contrib.learn is an example of a high level API.
Given below is an example using Variable:
# importing tensorflow
import tensorflow as tf
# creating nodes in computation graph
node = tf.Variable(tf.zeros([2,2]))
# running computation graph
with tf.Session() as sess:
# initialize all global variables
sess.run(tf.global_variables_initializer())
# evaluating node
print("Tensor value before addition:\n",sess.run(node))
# elementwise addition to tensor
node = node.assign(node + tf.ones([2,2]))
# evaluate node again
print("Tensor value after addition:\n", sess.run(node))
Output:
Tensor value before addition:
[[ 0. 0.]
[ 0. 0.]]
Tensor value after addition:
[[ 1. 1.]
[ 1. 1.]]