Cheatsheet1 in TensorFlow
- Fundamental Data Types in TensorFlow
- How to Use TensorBoard in TensorFlow
- How to Run TensorFlow in the Cloud
-
- 1. Create a Google Cloud Platform project.
- 2. Enable access to the ML Engine.
- 3. Install the Cloud Software Development Kit (SDK).
- 4. Upload training/prediction data to Cloud Storage.
- 5. Add a setup.py module in your application’s package.
- 6. Launch a training job for the ML Engine.
- 7. Launch a prediction job for the ML Engine.
Fundamental Data Types in TensorFlow
You can write TensorFlow applications in a number of different languages, such as Python, C++, and Java. But no matter which language you use, you need to be familiar with a series of TensorFlow-specific data types:
- Tensors and placeholders: A tensor is an instance of the
Tensor
class, and it serves as a general-purpose multidimensional array. A placeholder is also aTensor
, but instead of being initialized in code, it receives data from a session that will be valid during one execution of the session. Placeholders make it possible to update a tensor’s content from one session execution to the next. - Graphs: A graph is a container similar to a list or a tuple. Only one graph can be active at a time, and when you code an operation that accepts tensors or variables, the tensors, variables, and operation are stored as elements in the graph. When you create an optimizer and call its
minimize
method, TensorFlow stores the resulting operation in the graph. - Sessions. Graphs store operations, but they can’t perform operations by themselves. Instead, you need to create a session and call its
run
method. If you callrun
with a tensor or operation, the method will execute the operations in the graph needed to obtain the desired result. - Optimizers. The goal of machine learning is to refine a mathematical model of a real-world system until it resembles the system as closely as possible. This refinement process is called
optimization
, and researchers have devised many optimization methods. TensorFlow supports many of these algorithms and provides an optimizer class for each. Regardless of the class, you can obtain an optimization operation by calling the optimizer’sminimize
method. - Variables. Unlike tensors and placeholders, a variable is an instance of the
Variable
class. Its primary purpose is to contain data to be updated during the optimization process. For example, if your application models a system with a straight line, you’ll store the line’s slope and y-intercept as variables. But before you can use variables t