SlideShare a Scribd company logo
Intro to Deep Learning and
TensorFlow
H2O Meetup 01/09/2019
Metis San Francisco
Oswald Campesato
ocampesato@yahoo.com
Highlights/Overview
 intro to AI/ML/DL/NNs
 Hidden layers/Initialization/Neurons per layer
 cost function/gradient descent/learning rate
 Dropout rate
 Activation function
 Linear Regression
 What are CNNs
 Filters/ReLU/MaxPooling
 Keras and CNNs
 TensorFlow 1.x
The Data/AI Landscape
Use Cases for Deep Learning
computer vision
speech recognition
image processing
bioinformatics
social network filtering
drug design
Recommendation systems
Bioinformatics
Mobile Advertising
Many others
NN 3 Hidden Layers: Classifier
NN: 2 Hidden Layers (Regression)
Titanic Dataset (portion)
Classification and Deep Learning
Euler’s Function (e: 2.71828. . .)
The sigmoid Activation Function
The tanh Activation Function
The ReLU Activation Function
The softmax Activation Function
Activation Functions in Python
import numpy as np
...
# Python sigmoid example:
z = 1/(1 + np.exp(-np.dot(W, x)))
...
# Python tanh example:
z = np.tanh(np.dot(W,x));
# Python ReLU example:
z = np.maximum(0, np.dot(W, x))
What’s the “Best” Activation Function?
Initially: sigmoid was popular
Then: tanh became popular
Now: RELU is preferred (better results)
Softmax: for FC (fully connected) layers
NB: sigmoid and tanh are used in LSTMs
Linear Regression
One of the simplest models in ML
Fits a line (y = m*x + b) to data in 2D
Finds best line by minimizing MSE:
m = slope of the best-fitting line
b = y-intercept of the best-fitting line
Which is Good for Linear Regression?
Linear Regression in 2D: example
Example #1: MSE = ?
Example #2: MSE = ?
Example #3 (Random Points)
Sample Cost Function #1 (MSE)
Linear Regression: example #1
One feature (independent variable):
X = number of square feet
Predicted value (dependent variable):
Y = cost of a house
A very “coarse grained” model
We can devise a much better model
Linear Regression: example #2
Multiple features:
X1 = # of square feet
X2 = # of bedrooms
X3 = # of bathrooms (dependency?)
X4 = age of house
X5 = cost of nearby houses
X6 = corner lot (or not): Boolean
a much better model (6 features)
Linear Multivariate Analysis
General form of multivariate equation:
Y = w1*x1 + w2*x2 + . . . + wn*xn + b
w1, w2, . . . , wn are numeric values
x1, x2, . . . , xn are variables (features)
Properties of variables:
Can be independent (NaĂŻve Bayes)
weak/strong dependencies can exist
Sample Cost Function #1 (MSE)
Sample Cost Function #2
Sample Cost Function #3
Types of Optimizers
SGD
rmsprop
Adagrad
Adam
Others
http://cs229.stanford.edu/notes/cs229-notes1.pdf
Deep Neural Network: summary
 input layer, multiple hidden layers, and output layer
 nonlinear processing via activation functions
 perform transformation and feature extraction
 gradient descent algorithm with back propagation
 each layer receives the output from previous layer
 results are comparable/superior to human experts
CNNs versus RNNs
CNNs (Convolutional NNs):
Good for image processing
2000: CNNs processed 10-20% of all checks
=> Approximately 60% of all NNs
RNNs (Recurrent NNs):
Good for NLP and audio
Used in hybrid networks
CNNs: Convolution, ReLU, and Max Pooling
CNNs: Convolution Calculations
https://docs.gimp.org/en/plug-in-convmatrix.html
CNNs: Convolution Matrices (examples)
Sharpen:
Blur:
CNNs: Convolution Matrices (examples)
Edge detect:
Emboss:
CNNs: Max Pooling Example
GANs: Generative Adversarial Networks
GANs: Generative Adversarial Networks
Make imperceptible changes to images
Can consistently defeat all NNs
Can have extremely high error rate
Some images create optical illusions
https://www.quora.com/What-are-the-pros-and-cons-
of-using-generative-adversarial-networks-a-type-of-
neural-network
GANs: Generative Adversarial Networks
Create your own GANs:
https://www.oreilly.com/learning/generative-adversarial-networks-for-
beginners
https://github.com/jonbruner/generative-adversarial-networks
GANs from MNIST:
http://edwardlib.org/tutorials/gan
GANs and Capsule networks?
CNN in Python/Keras (fragment)
 from keras.models import Sequential
 from keras.layers.core import Dense, Dropout, Activation
 from keras.layers.convolutional import Conv2D, MaxPooling2D
 from keras.optimizers import Adadelta
 input_shape = (3, 32, 32)
 nb_classes = 10
 model = Sequential()
 model.add(Conv2D(32,(3, 3),padding='same’,
input_shape=input_shape))
 model.add(Activation('relu'))
 model.add(Conv2D(32, (3, 3)))
 model.add(Activation('relu'))
 model.add(MaxPooling2D(pool_size=(2, 2)))
 model.add(Dropout(0.25))
What is TensorFlow?
An open source framework for ML and DL
A “computation” graph
Created by Google (released 11/2015)
Evolved from Google Brain
Linux and Mac OS X support (VM for Windows)
TF home page: https://www.tensorflow.org/
What is TensorFlow?
Support for Python, Java, C++
Desktop, server, mobile device (TensorFlow Lite)
CPU/GPU/TPU support
Visualization via TensorBoard
Can be embedded in Python scripts
Installation: pip install tensorflow
TensorFlow cluster:
https://www.tensorflow.org/deploy/distributed
TensorFlow Use Cases (Generic)
Image recognition
Computer vision
Voice/sound recognition
Time series analysis
Language detection
Language translation
Text-based processing
Handwriting Recognition
Aspects of TensorFlow
Graph: graph of operations (DAG)
Sessions: contains Graph(s)
lazy execution (default)
operations in parallel (default)
Nodes: operators/variables/constants
Edges: tensors
=> graphs are split into subgraphs and executed in
parallel (or multiple CPUs)
TensorFlow Graph Execution
Execute statements in a tf.Session() object
Invoke the “run” method of that object
“eager” execution is available (>= v1.4)
included in the mainline (v1.7)
Installation: pip install tensorflow
What is a Tensor?
TF tensors are n-dimensional arrays
TF tensors are very similar to numpy ndarrays
scalar number: a zeroth-order tensor
vector: a first-order tensor
matrix: a second-order tensor
3-dimensional array: a 3rd order tensor
https://dzone.com/articles/tensorflow-simplified-
examples
TensorFlow “primitive types”
tf.constant:
+ initialized immediately
+ immutable
tf.placeholder (a function):
+ initial value is not required
+ can have variable shape
+ assigned value via feed_dict at run time
+ receive data from “external” sources
TensorFlow “primitive types”
tf.Variable (a class):
+ initial value is required
+ updated during training
+ maintain state across calls to “run()”
+ in-memory buffer (saved/restored from disk)
+ can be shared in a distributed environment
+ they hold learned parameters of a model
TensorFlow: constants (immutable)
 import tensorflow as tf
 aconst = tf.constant(3.0)
 print(aconst)
# output: Tensor("Const:0", shape=(), dtype=float32)
 sess = tf.Session()
 print(sess.run(aconst))
# output: 3.0
 sess.close()
 # => there's a better way
TensorFlow: constants
import tensorflow as tf
aconst = tf.constant(3.0)
print(aconst)
Automatically close “sess”
with tf.Session() as sess:
 print(sess.run(aconst))
TensorFlow Arithmetic
import tensorflow as tf
a = tf.add(4, 2)
b = tf.subtract(8, 6)
c = tf.multiply(a, 3)
d = tf.div(a, 6)
with tf.Session() as sess:
print(sess.run(a)) # 6
print(sess.run(b)) # 2
print(sess.run(c)) # 18
print(sess.run(d)) # 1
TF placeholders and feed_dict
import tensorflow as tf
a = tf.placeholder("float")
b = tf.placeholder("float")
c = tf.multiply(a,b)
# initialize a and b:
feed_dict = {a:2, b:3}
# multiply a and b:
with tf.Session() as sess:
print(sess.run(c, feed_dict))
TensorFlow: Simple Equation
import tensorflow as tf
# W and x are 1d arrays
W = tf.constant([10,20], name='W')
X = tf.placeholder(tf.int32, name='x')
b = tf.placeholder(tf.int32, name='b')
Wx = tf.multiply(W, x, name='Wx')
y = tf.add(Wx, b, name='y') OR
y2 = tf.add(tf.multiply(W,x),b)
TensorFlow fetch/feed_dict
with tf.Session() as sess:
print("Result 1: Wx = ",
sess.run(Wx, feed_dict={x:[5,10]}))
print("Result 2: y = ",
sess.run(y,feed_dict={x:[5,10],b:[15,25]}))
 Result 1: Wx = [50 200]
 Result 2: y = [65 225]
Saving Graphs for TensorBoard
import tensorflow as tf
x = tf.constant(5,name="x")
y = tf.constant(8,name="y")
z = tf.Variable(2*x+3*y, name="z")
init = tf.global_variables_initializer()
with tf.Session() as session:
writer = tf.summary.FileWriter("./tf_logs",session.graph)
session.run(init)
print 'z = ',session.run(z) # => z = 34
# launch: tensorboard –logdir=./tf_logs
TensorFlow Eager Execution
An imperative interface to TF
Fast debugging & immediate run-time errors
Eager execution is “mainline” in v1.7 of TF
=> requires Python 3.x (not Python 2.x)
TensorFlow Eager Execution
integration with Python tools
Supports dynamic models + Python control flow
support for custom and higher-order gradients
Supports most TensorFlow operations
=> Default mode in TensorFlow 2.0 (2019)
https://research.googleblog.com/2017/10/eager-
execution-imperative-define-by.html
TensorFlow Eager Execution
import tensorflow as tf
import tensorflow.contrib.eager as tfe
tfe.enable_eager_execution()
x = [[2.]]
m = tf.matmul(x, x)
print(m)
# tf.Tensor([[4.]], shape=(1, 1), dtype=float32)
What is tensorflow.js?
 an ecosystem of JS tools for machine learning
 TensorFlow.js also includes a Layers API
 a library for building machine learning models
 tools to port TF SavedModels & Keras HDF5 models
 => https://js.tensorflow.org/
What is tensorflow.js?
 tensorflow.js evolved from deeplearn.js
 deeplearn.js is now called TensorFlow.js Core
 TensorFlow.js Core: a flexible low-level API
 TensorFlow.js Layers:
a high-level API similar to Keras
 TensorFlow.js Converter:
tools to import a TF SavedModel to TensorFlow.js
async keyword
keyword placed before JS functions
For functions that return a Promise
Trivial example:
async function f() {
return 1;
}
await keyword
Works only inside async JS functions
Trivial example:
let value = await mypromise;
async/await example
async function f() {
let promise = new Promise((resolve, reject) => {
setTimeout(() => resolve("done!"), 1000)
});
// wait till the promise resolves
let result = await promise
alert(result)
}
f()
Tensorflow.js Samples
1) tfjs-example.html (linear regression)
2) js.tensorflow.org (home page)
3) https://github.com/tensorflow/tfjs-examples-master
a)cd mnist-core
b) yarn
c) yarn watch
Deep Learning and Art/”Stuff”
“Convolutional Blending” images:
=> 19-layer Convolutional Neural Network
www.deepart.io
https://www.fastcodesign.com/90124942/this-google-
engineer-taught-an-algorithm-to-make-train-footage-
and-its-hypnotic
About Me: Recent Books
1) TensorFlow Pocket Primer (WIP: TR?)
2) Python for TensorFlow (WIP: TR?)
3) C Programming Pocket Primer (2019)
4) RegEx Pocket Primer (2018)
5) Data Cleaning Pocket Primer (2018)
6) Angular Pocket Primer (2017)
7) Android Pocket Primer (2017)
8) CSS3 Pocket Primer (2016)
9) SVG Pocket Primer (2016)
10) Python Pocket Primer (2015)
11) D3 Pocket Primer (2015)
12) HTML5 Mobile Pocket Primer (2014)
13) jQuery Pocket Primer (2013)
What I do (Training)
Instructor at UCSC (Santa Clara):
Machine Learning Introduction (01/18/2019)
Deep Learning with TensorFlow (02/02/2019)
Deep Learning with Keras (ETA 04/2019)
Deep Learning with TensorFlow (ETA 05/2019)
Reinforcement Learning Intro (ETA 05/2019)
Deep Learning with TF 2 (ETA 07/2019)
Introduction to NLP (ETA 07/2019)
Adv DL & Deep RL (Survey) (ETA 07/2019)
UCSC link:
https://www.ucsc-extension.edu/certificate-program/offering/deep-
learning-and-artificial-intelligence-tensorflow
=> Android for Beginners (multi-day workshops)

More Related Content

What's hot (20)

PDF
TensorFlow and Keras: An Overview
Poo Kuan Hoong
 
PPTX
Introduction to CNN
Shuai Zhang
 
PDF
Deep learning - A Visual Introduction
Lukas Masuch
 
PPTX
What is TensorFlow? | Introduction to TensorFlow | TensorFlow Tutorial For Be...
Simplilearn
 
PDF
Tensorflow presentation
Ahmed rebai
 
PPTX
1.Introduction to deep learning
KONGU ENGINEERING COLLEGE
 
PDF
Deep Learning - Convolutional Neural Networks
Christian Perone
 
PDF
Introduction To TensorFlow
Spotle.ai
 
PDF
Introduction to TensorFlow
Matthias Feys
 
PPTX
Introduction to Deep learning
leopauly
 
PPTX
What is Deep Learning?
NVIDIA
 
PDF
Variational Autoencoder
Mark Chang
 
PDF
An Introduction to Deep Learning
Poo Kuan Hoong
 
PPTX
What Is Deep Learning? | Introduction to Deep Learning | Deep Learning Tutori...
Simplilearn
 
PDF
Generative adversarial networks
남주 김
 
PPTX
Recurrent Neural Network (RNN) | RNN LSTM Tutorial | Deep Learning Course | S...
Simplilearn
 
PPTX
CNN Machine learning DeepLearning
Abhishek Sharma
 
PPTX
Introduction to Keras
John Ramey
 
PDF
Autoencoders
CloudxLab
 
TensorFlow and Keras: An Overview
Poo Kuan Hoong
 
Introduction to CNN
Shuai Zhang
 
Deep learning - A Visual Introduction
Lukas Masuch
 
What is TensorFlow? | Introduction to TensorFlow | TensorFlow Tutorial For Be...
Simplilearn
 
Tensorflow presentation
Ahmed rebai
 
1.Introduction to deep learning
KONGU ENGINEERING COLLEGE
 
Deep Learning - Convolutional Neural Networks
Christian Perone
 
Introduction To TensorFlow
Spotle.ai
 
Introduction to TensorFlow
Matthias Feys
 
Introduction to Deep learning
leopauly
 
What is Deep Learning?
NVIDIA
 
Variational Autoencoder
Mark Chang
 
An Introduction to Deep Learning
Poo Kuan Hoong
 
What Is Deep Learning? | Introduction to Deep Learning | Deep Learning Tutori...
Simplilearn
 
Generative adversarial networks
남주 김
 
Recurrent Neural Network (RNN) | RNN LSTM Tutorial | Deep Learning Course | S...
Simplilearn
 
CNN Machine learning DeepLearning
Abhishek Sharma
 
Introduction to Keras
John Ramey
 
Autoencoders
CloudxLab
 

Similar to Introduction to Deep Learning, Keras, and TensorFlow (20)

PPTX
H2 o berkeleydltf
Oswald Campesato
 
PPTX
Introduction to Deep Learning and TensorFlow
Oswald Campesato
 
PPTX
Intro to Deep Learning, TensorFlow, and tensorflow.js
Oswald Campesato
 
PPTX
TensorFlow in Your Browser
Oswald Campesato
 
PPTX
Deep Learning in Your Browser
Oswald Campesato
 
PPTX
Deep Learning and TensorFlow
Oswald Campesato
 
PPTX
Deep Learning in your Browser: powered by WebGL
Oswald Campesato
 
PPTX
Deep Learning, Scala, and Spark
Oswald Campesato
 
PPTX
Deep Learning, Keras, and TensorFlow
Oswald Campesato
 
PPTX
Deep Learning and TensorFlow
Oswald Campesato
 
PPTX
Introduction to Deep Learning and Tensorflow
Oswald Campesato
 
PPTX
C++ and Deep Learning
Oswald Campesato
 
PPTX
Scala and Deep Learning
Oswald Campesato
 
PDF
TensorFlow Tutorial.pdf
Antonio Espinosa
 
PDF
TensorFlow example for AI Ukraine2016
Andrii Babii
 
PPTX
Introduction to Deep Learning
Oswald Campesato
 
PDF
Google TensorFlow Tutorial
台灣資料科學年會
 
PPTX
Deep Learning: R with Keras and TensorFlow
Oswald Campesato
 
PDF
Machine Learning with TensorFlow 2
Sarah Stemmler
 
PDF
DyCode Engineering - Machine Learning with TensorFlow
Alwin Arrasyid
 
H2 o berkeleydltf
Oswald Campesato
 
Introduction to Deep Learning and TensorFlow
Oswald Campesato
 
Intro to Deep Learning, TensorFlow, and tensorflow.js
Oswald Campesato
 
TensorFlow in Your Browser
Oswald Campesato
 
Deep Learning in Your Browser
Oswald Campesato
 
Deep Learning and TensorFlow
Oswald Campesato
 
Deep Learning in your Browser: powered by WebGL
Oswald Campesato
 
Deep Learning, Scala, and Spark
Oswald Campesato
 
Deep Learning, Keras, and TensorFlow
Oswald Campesato
 
Deep Learning and TensorFlow
Oswald Campesato
 
Introduction to Deep Learning and Tensorflow
Oswald Campesato
 
C++ and Deep Learning
Oswald Campesato
 
Scala and Deep Learning
Oswald Campesato
 
TensorFlow Tutorial.pdf
Antonio Espinosa
 
TensorFlow example for AI Ukraine2016
Andrii Babii
 
Introduction to Deep Learning
Oswald Campesato
 
Deep Learning: R with Keras and TensorFlow
Oswald Campesato
 
Machine Learning with TensorFlow 2
Sarah Stemmler
 
DyCode Engineering - Machine Learning with TensorFlow
Alwin Arrasyid
 
Ad

More from Sri Ambati (20)

PDF
H2O Label Genie Starter Track - Support Presentation
Sri Ambati
 
PDF
H2O.ai Agents : From Theory to Practice - Support Presentation
Sri Ambati
 
PDF
H2O Generative AI Starter Track - Support Presentation Slides.pdf
Sri Ambati
 
PDF
H2O Gen AI Ecosystem Overview - Level 1 - Slide Deck
Sri Ambati
 
PDF
An In-depth Exploration of Enterprise h2oGPTe Slide Deck
Sri Ambati
 
PDF
Intro to Enterprise h2oGPTe Presentation Slides
Sri Ambati
 
PDF
Enterprise h2o GPTe Learning Path Slide Deck
Sri Ambati
 
PDF
H2O Wave Course Starter - Presentation Slides
Sri Ambati
 
PDF
Large Language Models (LLMs) - Level 3 Slides
Sri Ambati
 
PDF
Data Science and Machine Learning Platforms (2024) Slides
Sri Ambati
 
PDF
Data Prep for H2O Driverless AI - Slides
Sri Ambati
 
PDF
H2O Cloud AI Developer Services - Slides (2024)
Sri Ambati
 
PDF
LLM Learning Path Level 2 - Presentation Slides
Sri Ambati
 
PDF
LLM Learning Path Level 1 - Presentation Slides
Sri Ambati
 
PDF
Hydrogen Torch - Starter Course - Presentation Slides
Sri Ambati
 
PDF
Presentation Resources - H2O Gen AI Ecosystem Overview - Level 2
Sri Ambati
 
PDF
H2O Driverless AI Starter Course - Slides and Assignments
Sri Ambati
 
PPTX
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
PDF
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
Sri Ambati
 
PPTX
Generative AI Masterclass - Model Risk Management.pptx
Sri Ambati
 
H2O Label Genie Starter Track - Support Presentation
Sri Ambati
 
H2O.ai Agents : From Theory to Practice - Support Presentation
Sri Ambati
 
H2O Generative AI Starter Track - Support Presentation Slides.pdf
Sri Ambati
 
H2O Gen AI Ecosystem Overview - Level 1 - Slide Deck
Sri Ambati
 
An In-depth Exploration of Enterprise h2oGPTe Slide Deck
Sri Ambati
 
Intro to Enterprise h2oGPTe Presentation Slides
Sri Ambati
 
Enterprise h2o GPTe Learning Path Slide Deck
Sri Ambati
 
H2O Wave Course Starter - Presentation Slides
Sri Ambati
 
Large Language Models (LLMs) - Level 3 Slides
Sri Ambati
 
Data Science and Machine Learning Platforms (2024) Slides
Sri Ambati
 
Data Prep for H2O Driverless AI - Slides
Sri Ambati
 
H2O Cloud AI Developer Services - Slides (2024)
Sri Ambati
 
LLM Learning Path Level 2 - Presentation Slides
Sri Ambati
 
LLM Learning Path Level 1 - Presentation Slides
Sri Ambati
 
Hydrogen Torch - Starter Course - Presentation Slides
Sri Ambati
 
Presentation Resources - H2O Gen AI Ecosystem Overview - Level 2
Sri Ambati
 
H2O Driverless AI Starter Course - Slides and Assignments
Sri Ambati
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
Sri Ambati
 
Generative AI Masterclass - Model Risk Management.pptx
Sri Ambati
 
Ad

Recently uploaded (20)

PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 

Introduction to Deep Learning, Keras, and TensorFlow

  • 1. Intro to Deep Learning and TensorFlow H2O Meetup 01/09/2019 Metis San Francisco Oswald Campesato [email protected]
  • 2. Highlights/Overview  intro to AI/ML/DL/NNs  Hidden layers/Initialization/Neurons per layer  cost function/gradient descent/learning rate  Dropout rate  Activation function  Linear Regression  What are CNNs  Filters/ReLU/MaxPooling  Keras and CNNs  TensorFlow 1.x
  • 4. Use Cases for Deep Learning computer vision speech recognition image processing bioinformatics social network filtering drug design Recommendation systems Bioinformatics Mobile Advertising Many others
  • 5. NN 3 Hidden Layers: Classifier
  • 6. NN: 2 Hidden Layers (Regression)
  • 14. Activation Functions in Python import numpy as np ... # Python sigmoid example: z = 1/(1 + np.exp(-np.dot(W, x))) ... # Python tanh example: z = np.tanh(np.dot(W,x)); # Python ReLU example: z = np.maximum(0, np.dot(W, x))
  • 15. What’s the “Best” Activation Function? Initially: sigmoid was popular Then: tanh became popular Now: RELU is preferred (better results) Softmax: for FC (fully connected) layers NB: sigmoid and tanh are used in LSTMs
  • 16. Linear Regression One of the simplest models in ML Fits a line (y = m*x + b) to data in 2D Finds best line by minimizing MSE: m = slope of the best-fitting line b = y-intercept of the best-fitting line
  • 17. Which is Good for Linear Regression?
  • 18. Linear Regression in 2D: example
  • 23. Linear Regression: example #1 One feature (independent variable): X = number of square feet Predicted value (dependent variable): Y = cost of a house A very “coarse grained” model We can devise a much better model
  • 24. Linear Regression: example #2 Multiple features: X1 = # of square feet X2 = # of bedrooms X3 = # of bathrooms (dependency?) X4 = age of house X5 = cost of nearby houses X6 = corner lot (or not): Boolean a much better model (6 features)
  • 25. Linear Multivariate Analysis General form of multivariate equation: Y = w1*x1 + w2*x2 + . . . + wn*xn + b w1, w2, . . . , wn are numeric values x1, x2, . . . , xn are variables (features) Properties of variables: Can be independent (NaĂŻve Bayes) weak/strong dependencies can exist
  • 30. Deep Neural Network: summary  input layer, multiple hidden layers, and output layer  nonlinear processing via activation functions  perform transformation and feature extraction  gradient descent algorithm with back propagation  each layer receives the output from previous layer  results are comparable/superior to human experts
  • 31. CNNs versus RNNs CNNs (Convolutional NNs): Good for image processing 2000: CNNs processed 10-20% of all checks => Approximately 60% of all NNs RNNs (Recurrent NNs): Good for NLP and audio Used in hybrid networks
  • 32. CNNs: Convolution, ReLU, and Max Pooling
  • 34. CNNs: Convolution Matrices (examples) Sharpen: Blur:
  • 35. CNNs: Convolution Matrices (examples) Edge detect: Emboss:
  • 36. CNNs: Max Pooling Example
  • 38. GANs: Generative Adversarial Networks Make imperceptible changes to images Can consistently defeat all NNs Can have extremely high error rate Some images create optical illusions https://www.quora.com/What-are-the-pros-and-cons- of-using-generative-adversarial-networks-a-type-of- neural-network
  • 39. GANs: Generative Adversarial Networks Create your own GANs: https://www.oreilly.com/learning/generative-adversarial-networks-for- beginners https://github.com/jonbruner/generative-adversarial-networks GANs from MNIST: http://edwardlib.org/tutorials/gan GANs and Capsule networks?
  • 40. CNN in Python/Keras (fragment)  from keras.models import Sequential  from keras.layers.core import Dense, Dropout, Activation  from keras.layers.convolutional import Conv2D, MaxPooling2D  from keras.optimizers import Adadelta  input_shape = (3, 32, 32)  nb_classes = 10  model = Sequential()  model.add(Conv2D(32,(3, 3),padding='same’, input_shape=input_shape))  model.add(Activation('relu'))  model.add(Conv2D(32, (3, 3)))  model.add(Activation('relu'))  model.add(MaxPooling2D(pool_size=(2, 2)))  model.add(Dropout(0.25))
  • 41. What is TensorFlow? An open source framework for ML and DL A “computation” graph Created by Google (released 11/2015) Evolved from Google Brain Linux and Mac OS X support (VM for Windows) TF home page: https://www.tensorflow.org/
  • 42. What is TensorFlow? Support for Python, Java, C++ Desktop, server, mobile device (TensorFlow Lite) CPU/GPU/TPU support Visualization via TensorBoard Can be embedded in Python scripts Installation: pip install tensorflow TensorFlow cluster: https://www.tensorflow.org/deploy/distributed
  • 43. TensorFlow Use Cases (Generic) Image recognition Computer vision Voice/sound recognition Time series analysis Language detection Language translation Text-based processing Handwriting Recognition
  • 44. Aspects of TensorFlow Graph: graph of operations (DAG) Sessions: contains Graph(s) lazy execution (default) operations in parallel (default) Nodes: operators/variables/constants Edges: tensors => graphs are split into subgraphs and executed in parallel (or multiple CPUs)
  • 45. TensorFlow Graph Execution Execute statements in a tf.Session() object Invoke the “run” method of that object “eager” execution is available (>= v1.4) included in the mainline (v1.7) Installation: pip install tensorflow
  • 46. What is a Tensor? TF tensors are n-dimensional arrays TF tensors are very similar to numpy ndarrays scalar number: a zeroth-order tensor vector: a first-order tensor matrix: a second-order tensor 3-dimensional array: a 3rd order tensor https://dzone.com/articles/tensorflow-simplified- examples
  • 47. TensorFlow “primitive types” tf.constant: + initialized immediately + immutable tf.placeholder (a function): + initial value is not required + can have variable shape + assigned value via feed_dict at run time + receive data from “external” sources
  • 48. TensorFlow “primitive types” tf.Variable (a class): + initial value is required + updated during training + maintain state across calls to “run()” + in-memory buffer (saved/restored from disk) + can be shared in a distributed environment + they hold learned parameters of a model
  • 49. TensorFlow: constants (immutable)  import tensorflow as tf  aconst = tf.constant(3.0)  print(aconst) # output: Tensor("Const:0", shape=(), dtype=float32)  sess = tf.Session()  print(sess.run(aconst)) # output: 3.0  sess.close()  # => there's a better way
  • 50. TensorFlow: constants import tensorflow as tf aconst = tf.constant(3.0) print(aconst) Automatically close “sess” with tf.Session() as sess:  print(sess.run(aconst))
  • 51. TensorFlow Arithmetic import tensorflow as tf a = tf.add(4, 2) b = tf.subtract(8, 6) c = tf.multiply(a, 3) d = tf.div(a, 6) with tf.Session() as sess: print(sess.run(a)) # 6 print(sess.run(b)) # 2 print(sess.run(c)) # 18 print(sess.run(d)) # 1
  • 52. TF placeholders and feed_dict import tensorflow as tf a = tf.placeholder("float") b = tf.placeholder("float") c = tf.multiply(a,b) # initialize a and b: feed_dict = {a:2, b:3} # multiply a and b: with tf.Session() as sess: print(sess.run(c, feed_dict))
  • 53. TensorFlow: Simple Equation import tensorflow as tf # W and x are 1d arrays W = tf.constant([10,20], name='W') X = tf.placeholder(tf.int32, name='x') b = tf.placeholder(tf.int32, name='b') Wx = tf.multiply(W, x, name='Wx') y = tf.add(Wx, b, name='y') OR y2 = tf.add(tf.multiply(W,x),b)
  • 54. TensorFlow fetch/feed_dict with tf.Session() as sess: print("Result 1: Wx = ", sess.run(Wx, feed_dict={x:[5,10]})) print("Result 2: y = ", sess.run(y,feed_dict={x:[5,10],b:[15,25]}))  Result 1: Wx = [50 200]  Result 2: y = [65 225]
  • 55. Saving Graphs for TensorBoard import tensorflow as tf x = tf.constant(5,name="x") y = tf.constant(8,name="y") z = tf.Variable(2*x+3*y, name="z") init = tf.global_variables_initializer() with tf.Session() as session: writer = tf.summary.FileWriter("./tf_logs",session.graph) session.run(init) print 'z = ',session.run(z) # => z = 34 # launch: tensorboard –logdir=./tf_logs
  • 56. TensorFlow Eager Execution An imperative interface to TF Fast debugging & immediate run-time errors Eager execution is “mainline” in v1.7 of TF => requires Python 3.x (not Python 2.x)
  • 57. TensorFlow Eager Execution integration with Python tools Supports dynamic models + Python control flow support for custom and higher-order gradients Supports most TensorFlow operations => Default mode in TensorFlow 2.0 (2019) https://research.googleblog.com/2017/10/eager- execution-imperative-define-by.html
  • 58. TensorFlow Eager Execution import tensorflow as tf import tensorflow.contrib.eager as tfe tfe.enable_eager_execution() x = [[2.]] m = tf.matmul(x, x) print(m) # tf.Tensor([[4.]], shape=(1, 1), dtype=float32)
  • 59. What is tensorflow.js?  an ecosystem of JS tools for machine learning  TensorFlow.js also includes a Layers API  a library for building machine learning models  tools to port TF SavedModels & Keras HDF5 models  => https://js.tensorflow.org/
  • 60. What is tensorflow.js?  tensorflow.js evolved from deeplearn.js  deeplearn.js is now called TensorFlow.js Core  TensorFlow.js Core: a flexible low-level API  TensorFlow.js Layers: a high-level API similar to Keras  TensorFlow.js Converter: tools to import a TF SavedModel to TensorFlow.js
  • 61. async keyword keyword placed before JS functions For functions that return a Promise Trivial example: async function f() { return 1; }
  • 62. await keyword Works only inside async JS functions Trivial example: let value = await mypromise;
  • 63. async/await example async function f() { let promise = new Promise((resolve, reject) => { setTimeout(() => resolve("done!"), 1000) }); // wait till the promise resolves let result = await promise alert(result) } f()
  • 64. Tensorflow.js Samples 1) tfjs-example.html (linear regression) 2) js.tensorflow.org (home page) 3) https://github.com/tensorflow/tfjs-examples-master a)cd mnist-core b) yarn c) yarn watch
  • 65. Deep Learning and Art/”Stuff” “Convolutional Blending” images: => 19-layer Convolutional Neural Network www.deepart.io https://www.fastcodesign.com/90124942/this-google- engineer-taught-an-algorithm-to-make-train-footage- and-its-hypnotic
  • 66. About Me: Recent Books 1) TensorFlow Pocket Primer (WIP: TR?) 2) Python for TensorFlow (WIP: TR?) 3) C Programming Pocket Primer (2019) 4) RegEx Pocket Primer (2018) 5) Data Cleaning Pocket Primer (2018) 6) Angular Pocket Primer (2017) 7) Android Pocket Primer (2017) 8) CSS3 Pocket Primer (2016) 9) SVG Pocket Primer (2016) 10) Python Pocket Primer (2015) 11) D3 Pocket Primer (2015) 12) HTML5 Mobile Pocket Primer (2014) 13) jQuery Pocket Primer (2013)
  • 67. What I do (Training) Instructor at UCSC (Santa Clara): Machine Learning Introduction (01/18/2019) Deep Learning with TensorFlow (02/02/2019) Deep Learning with Keras (ETA 04/2019) Deep Learning with TensorFlow (ETA 05/2019) Reinforcement Learning Intro (ETA 05/2019) Deep Learning with TF 2 (ETA 07/2019) Introduction to NLP (ETA 07/2019) Adv DL & Deep RL (Survey) (ETA 07/2019) UCSC link: https://www.ucsc-extension.edu/certificate-program/offering/deep- learning-and-artificial-intelligence-tensorflow => Android for Beginners (multi-day workshops)