TensorFlow Quick Reference Table - Cheat Sheet.

TensorFlow Quick Reference Table - Cheat Sheet.

TensorFlow Quick Reference Table – Cheat Sheet.

TensorFlow is very popular deep learning library, with its complexity can be overwhelming especially for new users. Here is a short summary of often used functions, if you want to download it in pdf it is available here:

TensorFlow Cheat Sheet – TensorFlow.eu

Import TensorFlow:

import tensorflow as tf

Basic math operations:

tf.add() sum
tf.subtract() substraction
tf.multiply() multiplication
tf.div() division
tf.mod() module
tf.abs() absolute value
tf.negative() negative value
tf.sign() return sign
tf.reciprocal() reciprocal
tf.square() square
tf.round() nearest intiger
tf.sqrt() square root
tf.pow() power
tf.exp() exponent
tf.log() logarithm
tf.maximum() maximum
tf.minimum() minimum
tf.cos() cosine
tf.sin() sine

Basic operations on tensors:

tf.string_to_number() converts string to numeric type
tf.cast() casts to new type
tf.shape() returns shape of tensor
tf.reshape() reshapes tensor
tf.diag() creates tensor with given diagonal values
tf.zeros() creates tensor with all elements set to zero
tf.fill() creates tensor with all elements set given value
tf.concat() concatenates tensors
tf.slice() extracts slice from tensor
tf.transpose() transpose the argument
tf.matmul() matrices multiplication
tf.matrix_determinant() determinant of matrices
tf.matrix_inverse() computes inverse of matrices

Control Flow:

tf.while_loop() repeat body while condition true
tf.case() case operator
tf.count_up_to() incriments ref untill limit
tf.tuple() groups tensors together

Logical/Comparison Operators:

tf.equal() returns truth value element-wise
tf.not_equal() returns truth value of X!=Y
tf.less() returns truth value of X<Y
tf.less_equal() returns truth value of X<=Y
tf.greater() returns truth value of X>Y
tf.greater_equal() returns truth value of X>=Y
tf.is_nan() returns which elements are NaN
tf.logical_and() returns truth value of ‘AND’ for given tensors
tf.logical_or() returns truth value of ‘OR’ for given tensors
tf.logical_not() returns truth value of ‘NOT’ for given tensors
tf.logical_xor() returns truth value of ‘XOR’ for given tensors

Working with Images:

tf.image.decode_image() converts image to tensor type uint8
tf.image.resize_images() resize images
tf.image.resize_image_with_crop_or_pad() resize image by cropping or padding
tf.image.flip_up_down() flip image horizontally
tf.image.rot90() rotate image 90 degrees counter-clockwise
tf.image.rgb_to_grayscale() converts image from RGB to grayscale
tf.image.per_image_standardization() scales image to zero mean and unit norm

Neural Networks:

tf.nn.relu() rectified linear activation function
tf.nn.softmax() softmax activation function
tf.nn.sigmoid() sigmoid activation function
tf.nn.tanh() hyperbolic tangent activation function
tf.nn.dropout dropout
tf.nn.bias_add adds bias to value
tf.nn.all_candidate_sampler() set of all classes
tf.nn.weighted_moments() returns mean and variance
tf.nn.softmax_cross_entropy_with_logits() softmax cross entropy
tf.nn.sigmoid_cross_entropy_with_logits() sigmoid cross entropy
tf.nn.l2_normalize() normalization using L2 Norm
tf.nn.l2_loss() L2 loss
tf.nn.dynamic_rnn() RNN specified by given cell
tf.nn.conv2d() 2D convolutions given 4D input
tf.nn.conv1d() 1D convolution given 3D input
tf.nn.batch_normalization() batch normalization
tf.nn.xw_plus_b() computes matmul(x,weights)+biases

High level Machine Learning:

tf.contrib.keras Keras API as high level API for TensorFlow
tf.contrib.layers.one_hot_column() one hot encoding
tf.contrib.learn.LogisticRegressor() logistic regression
tf.contrib.learn.DNNClassifier() DNN classifier
tf.contrib.learn.DynamicRnnEstimator() Rnn Estimator
tf.contrib.learn.KMeansClustering() K-Means Clusstering
tf.contrib.learn.LinearClassifier() linear classifier
tf.contrib.learn.LinearRegressor() linear regressor
tf.contrib.learn.extract_pandas_data() extract data from Pandas dataframe
tf.contrib.metrics.accuracy() accuracy
tf.contrib.metrics.auc_using_histogram() AUC
tf.contrib.metrics.confusion_matrix() confusion matrix
tf.contrib.metrics.streaming_mean_absolute_error() mean absolute error
tf.contrib.rnn.BasicLSTMCell() basic lstm cell
tf.contrib.rnn.BasicRNNCell() basic rnn cell

Placeholders and Variables:

tf.placeholder() defines placeholder
tf.Variable(tf.random_normal([3, 4], stddev=0.1) defines variable
tf.Variable(tf.zeros([50]), name=’x’) defines variable
tf.global_variables_initializer() initialize global variables
tf.local_variables_initializer() initialize local variables
with tf.device(“/cpu:0”): pin variable to CPU
  v = tf.Variable()
with tf.device(“/gpu:0”): pin variable to GPU
  v = tf.Variable()
sess = tf.Session() run session
with tf.Session() as session: run session(2)
saver=tf.train.Saver() Saving and restoring variables.

Working with Data:

tf.decode_csv() converts csv to tensors
tf.read_file() reads file
tf.write_file() writes to file
tf.train.batch() creates batches of tensors


Was the above useful? Please share with others on social media.

If you want to look for more information, check some free online courses available at   coursera.orgedx.org or udemy.com.

Recommended reading list:


Hands-On Machine Learning with Scikit-Learn and TensorFlow: Concepts, Tools, and Techniques to Build Intelligent Systems

Through a series of recent breakthroughs, deep learning has boosted the entire field of machine learning. Now, even programmers who know close to nothing about this technology can use simple, efficient tools to implement programs capable of learning from data. This practical book shows you how.

By using concrete examples, minimal theory, and two production-ready Python frameworks—scikit-learn and TensorFlow—author Aurélien Géron helps you gain an intuitive understanding of the concepts and tools for building intelligent systems. You’ll learn a range of techniques, starting with simple linear regression and progressing to deep neural networks. With exercises in each chapter to help you apply what you’ve learned, all you need is programming experience to get started.

Explore the machine learning landscape, particularly neural nets
Use scikit-learn to track an example machine-learning project end-to-end
Explore several training models, including support vector machines, decision trees, random forests, and ensemble methods
Use the TensorFlow library to build and train neural nets
Dive into neural net architectures, including convolutional nets, recurrent nets, and deep reinforcement learning
Learn techniques for training and scaling deep neural nets
Apply practical code examples without acquiring excessive machine learning theory or algorithm details
TensorFlow Machine Learning Cookbook

This guide starts with the fundamentals of the TensorFlow library which includes variables, matrices, and various data sources. Moving ahead, you will get hands-on experience with Linear Regression techniques with TensorFlow. The next chapters cover important high-level concepts such as neural networks, CNN, RNN, and NLP.

Once you are familiar and comfortable with the TensorFlow ecosystem, the last chapter will show you how to take it to production.

What you will learn
Become familiar with the basics of the TensorFlow machine learning library
Get to know Linear Regression techniques with TensorFlow
Learn SVMs with hands-on recipes
Implement neural networks and improve predictions
Apply NLP and sentiment analysis to your data
Master CNN and RNN through practical recipes
Take TensorFlow into production
Learning TensorFlow: A Guide to Building Deep Learning Systems

TensorFlow is currently the leading open-source software for deep learning, used by a rapidly growing number of practitioners working on computer vision, Natural Language Processing (NLP), speech recognition, and general predictive analytics. This book is an end-to-end guide to TensorFlow designed for data scientists, engineers, students and researchers.

With this book you will learn how to:

Get up and running with TensorFlow, rapidly and painlessly
Build and train popular deep learning models for computer vision and NLP
Apply your advanced understanding of the TensorFlow framework to build and adapt models for your specific needs
Train models at scale, and deploy TensorFlow in a production setting
TensorFlow for Machine Intelligence: A Hands-On Introduction to Learning Algorithms

TensorFlow, a popular library for machine learning, embraces the innovation and community-engagement of open source, but has the support, guidance, and stability of a large corporation. Because of its multitude of strengths, TensorFlow is appropriate for individuals and businesses ranging from startups to companies as large as, well, Google. TensorFlow is currently being used for natural language processing, artificial intelligence, computer vision, and predictive analytics. TensorFlow, open sourced to the public by Google in November 2015, was made to be flexible, efficient, extensible, and portable. Computers of any shape and size can run it, from smartphones all the way up to huge computing clusters. This book is for anyone who knows a little machine learning (or not) and who has heard about TensorFlow, but found the documentation too daunting to approach. It introduces the TensorFlow framework and the underlying machine learning concepts that are important to harness machine intelligence. After reading this book, you should have a deep understanding of the core TensorFlow API.
Machine Learning with TensorFlow

Being able to make near-real-time decisions is becoming increasingly crucial. To succeed, we need machine learning systems that can turn massive amounts of data into valuable insights. But when you're just starting out in the data science field, how do you get started creating machine learning applications? The answer is TensorFlow, a new open source machine learning library from Google. The TensorFlow library can take your high level designs and turn them into the low level mathematical operations required by machine learning algorithms.

Machine Learning with TensorFlow teaches readers about machine learning algorithms and how to implement solutions with TensorFlow. It starts with an overview of machine learning concepts and moves on to the essentials needed to begin using TensorFlow. Each chapter zooms into a prominent example of machine learning. Readers can cover them all to master the basics or skip around to cater to their needs. By the end of this book, readers will be able to solve classification, clustering, regression, and prediction problems in the real world.