Introduction to TensorFlow
TensorFlow is a deep learning library from Google that is open-source and available on GitHub. TensorFlow excels at numerical computing, which is critical for deep learning. It has a rich set of application programming interfaces in most major languages and environments needed for deep learning projects: Python, C, C++, Rust, Haskell, Go, Java, Android, IoS, Mac OS, Windows, Linux, and Raspberry Pi. The primary unit in TensorFlow is a tensor. A tensor consists of a set of primitive values shaped into an array of any number of dimensions. These massive numbers of large arrays are the reason that GPUs and other processors designed to do floating point mathematics excel at speeding up these algorithms.
A tensor is a set of primitives in a multidimensional array, ranked by number of dimensions
0: 5.0 1: [5.0, 10.0, 15.0, 20.0, 25.0} 2: [[5.0, 10.0], [15.0, 20.0], [25.0, 30.0], [35.0, 40.0, 45.0]]
In TensorFlow programs, you will need to use variables to hold tensors in memory. Some tensors are constants and not variables; for example, static numbers. An important note is that before you start using variables, you must initialize them to a value. TensorFlow first builds a graph of all the operation to be done, and then when a “session” is called, it “runs” the graph. It’s built to be scalable, by changing internal data representation to tensors (AKA multi-dimensional arrays).
Doing Some Simple Math
import tensorflow as tf firstnumber = tf.constant([10, 20, 30, 35, 40, 50]) secondnumber = tf.Variable(firstnumber + 50) with tf.Session() as session: session.run(tf.global_variables_initializer()) print(session.run(secondnumber))
The APIs are well-documented and well-designed, so it was easy for example for me to port the LabelImage Java example to work as a processor for Apache NiFi. Some people prefer a higher-level interface for neural network programming; one that’s highly popular is Keras. Keras is available for Python and works not only for TensorFlow but also for CNTK and Theano. I recommend using Python 3.6 and starting with plain TensorFlow before you investigate Keras. TensorFlow programs are usually structured into a construction phase, which assembles a data graph, and an execution phase, which uses a session to execute operations in the graph.
Questioning whether TensorFlow is ready for production environments belies the fact that TensorFlow has been in the open-source community for almost two years and has been used by many companies. TensorFlow excels in production environments due to its distributed and parallel design and its ability to access data from Hadoop HDFS. Another key feature of TensorFlow is TensorFlow Serving, which is a high-performance production server for deploy and serve machine learning models using gRPC as its network protocol.