Blog

TensorFlow Quick Reference Table – Cheat Sheet.

https://www.tensorflow.uk

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.uk

If you find it useful please share on social media.

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
sess.run()
sess.close()
with tf.Session() as session: run session(2)
     session.run()
saver=tf.train.Saver() Saving and restoring variables.
saver.save(sess,’file_name’)
saver.restore(sess,’file_name’)

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:

 

Data Science from Scratch: First Principles with Python

Data science libraries, frameworks, modules, and toolkits are great for doing data science, but they’re also a good way to dive into the discipline without actually understanding data science. In this book, you’ll learn how many of the most fundamental data science tools and algorithms work by implementing them from scratch.

If you have an aptitude for mathematics and some programming skills, author Joel Grus will help you get comfortable with the math and statistics at the core of data science, and with hacking skills you need to get started as a data scientist. Today’s messy glut of data holds answers to questions no one’s even thought to ask. This book provides you with the know-how to dig those answers out.

Get a crash course in Python
Learn the basics of linear algebra, statistics, and probability—and understand how and when they're used in data science
Collect, explore, clean, munge, and manipulate data
Dive into the fundamentals of machine learning
Implement models such as k-nearest Neighbors, Naive Bayes, linear and logistic regression, decision trees, neural networks, and clustering
Explore recommender systems, natural language processing, network analysis, MapReduce, and databases
Practical Statistics for Data Scientists: 50 Essential Concepts

Statistical methods are a key part of of data science, yet very few data scientists have any formal statistics training. Courses and books on basic statistics rarely cover the topic from a data science perspective. This practical guide explains how to apply various statistical methods to data science, tells you how to avoid their misuse, and gives you advice on what's important and what's not.

Many data science resources incorporate statistical methods but lack a deeper statistical perspective. If you’re familiar with the R programming language, and have some exposure to statistics, this quick reference bridges the gap in an accessible, readable format.

With this book, you’ll learn:

Why exploratory data analysis is a key preliminary step in data science
How random sampling can reduce bias and yield a higher quality dataset, even with big data
How the principles of experimental design yield definitive answers to questions
How to use regression to estimate outcomes and detect anomalies
Key classification techniques for predicting which categories a record belongs to
Statistical machine learning methods that “learn” from data
Unsupervised learning methods for extracting meaning from unlabeled data
Doing Data Science: Straight Talk from the Frontline

Now that people are aware that data can make the difference in an election or a business model, data science as an occupation is gaining ground. But how can you get started working in a wide-ranging, interdisciplinary field that’s so clouded in hype? This insightful book, based on Columbia University’s Introduction to Data Science class, tells you what you need to know.

In many of these chapter-long lectures, data scientists from companies such as Google, Microsoft, and eBay share new algorithms, methods, and models by presenting case studies and the code they use. If you’re familiar with linear algebra, probability, and statistics, and have programming experience, this book is an ideal introduction to data science.

Topics include:

Statistical inference, exploratory data analysis, and the data science process
Algorithms
Spam filters, Naive Bayes, and data wrangling
Logistic regression
Financial modeling
Recommendation engines and causality
Data visualization
Social networks and data journalism
Data engineering, MapReduce, Pregel, and Hadoop
The Data Science Handbook: Advice and Insights from 25 Amazing Data Scientists

The Data Science Handbook contains interviews with 25 of the world s best data scientists. We sat down with them, had in-depth conversations about their careers, personal stories, perspectives on data science and life advice. In The Data Science Handbook, you will find war stories from DJ Patil, US Chief Data Officer and one of the founders of the field. You ll learn industry veterans such as Kevin Novak and Riley Newman, who head the data science teams at Uber and Airbnb respectively. You ll also read about rising data scientists such as Clare Corthell, who crafted her own open source data science masters program. This book is perfect for aspiring or current data scientists to learn from the best. It s a reference book packed full of strategies, suggestions and recipes to launch and grow your own data science career.
Introduction to Machine Learning with Python: A Guide for Data Scientists

Machine learning has become an integral part of many commercial applications and research projects, but this field is not exclusive to large companies with extensive research teams. If you use Python, even as a beginner, this book will teach you practical ways to build your own machine learning solutions. With all the data available today, machine learning applications are limited only by your imagination.

You’ll learn the steps necessary to create a successful machine-learning application with Python and the scikit-learn library. Authors Andreas Müller and Sarah Guido focus on the practical aspects of using machine learning algorithms, rather than the math behind them. Familiarity with the NumPy and matplotlib libraries will help you get even more from this book.

With this book, you’ll learn:

Fundamental concepts and applications of machine learning
Advantages and shortcomings of widely used machine learning algorithms
How to represent data processed by machine learning, including which data aspects to focus on
Advanced methods for model evaluation and parameter tuning
The concept of pipelines for chaining models and encapsulating your workflow
Methods for working with text data, including text-specific processing techniques
Suggestions for improving your machine learning and data science skills

Leave a Reply

Your email address will not be published. Required fields are marked *