Chapter 2. Introduction to TensorFlow Primitives

This chapter will introduce you to fundamental aspects of TensorFlow. In particular, you will learn how to perform basic computation using TensorFlow. A large part of this chapter will be spent introducing the concept of tensors, and discussing how tensors are represented and manipulated within TensorFlow. This discussion will necessitate a brief overview of some of the mathematical concepts that underlie tensorial mathematics. In particular, we’ll briefly review basic linear algebra and demonstrate how to perform basic linear algebraic operations with TensorFlow.

We’ll follow this discussion of basic mathematics with a discussion of the differences between declarative and imperative programming styles. Unlike many programming languages, TensorFlow is largely declarative. Calling a TensorFlow operation adds a description of a computation to TensorFlow’s “computation graph.” In particular, TensorFlow code “describes” computations and doesn’t actually perform them. In order to run TensorFlow code, users need to create tf.Session objects. We introduce the concept of sessions and describe how users perform computations with them in TensorFlow.

We end the chapter by discussing the notion of variables. Variables in TensorFlow hold tensors and allow for stateful computation that modifies variables to occur. We demonstrate how to create variables and update their values via TensorFlow.

Introducing Tensors

Tensors are fundamental mathematical ...

Get TensorFlow for Deep Learning now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.