01 - Lecture Slide - Overview of Tensorflow
01 - Lecture Slide - Overview of Tensorflow
1
Thanks Danijar Hafner for the logo!
2
Agenda
Welcome
Overview of TensorFlow
3
What’s TensorFlow™?
4
Launched Nov 2015
5
Why TensorFlow?
● Many machine learning libraries
6
Why TensorFlow?
● Flexibility + Scalability
Originally developed by Google as a single infrastructure for machine learning
in both production and research
7
Why TensorFlow?
● Flexibility + Scalability
● Popularity
8
Companies using TensorFlow
9
Demand for tutorials on TensorFlow
10
Some cool projects using
TensorFlow
11
Classify skin cancer
Dermatologist-level classification of skin cancer with deep neural networks (Esteva et al., Nature 2017) 12
WaveNet: Text to Speech
It takes several hours to synthesize 1 second!
Image Style Transfer Using Convolutional Neural Networks (Gatys et al., 2016)
15
Tensorflow adaptation by Cameroon Smith (cysmith@github)
I hope that this class will give you
the tool to build cool projects like
those!
16
Goals
● Understand TF’s computation graph approach
● Explore TF’s built-in functions and classes
● Learn how to build and structure models best suited for a deep learning
project
17
CS20
18
Staff
19
Logistics
● Piazza: piazza.com/stanford/winter2018/cs20
● Staff email: [email protected]
● Students mailing list: cs20-win1718-students
● Guests mailing list: cs20-win1718-guests
20
Grading
● Assignments (3)
● Participation
● Check in
21
Resources
● The official documentations
● TensorFlow’s official sample models
● StackOverflow should be your first port of call in case of bug
● Books
○ Aurélien Géron’s Hands-On Machine Learning with Scikit-Learn and TensorFlow (O’Reilly,
March 2017)
○ François Chollet’s Deep Learning with Python (Manning Publications, November 2017)
○ Nishant Shukla’s Machine Learning with TensorFlow (Manning Publications, January 2018)
○ Lieder et al.’s Learning TensorFlow A Guide to Building Deep Learning Systems (O’Reilly,
August 2017)
22
Permission Number
Link
23
Many of you are ahead of me in
academia so I probably need more
of your help than you do mine
24
Getting Started
25
import tensorflow as tf
26
Graphs and Sessions
27
Data Flow Graphs
31
What’s a tensor?
An n-dimensional array
and so on
32
Data Flow Graphs
33
Data Flow Graphs
Why x, y?
34
Data Flow Graphs
a = tf.add(3, 5)
3
Nodes: operators, variables, and constants
Edges: tensors 5 a
35
Data Flow Graphs
a = tf.add(3, 5)
3
Nodes: operators, variables, and constants
Edges: tensors 5 a
36
Data Flow Graphs
import tensorflow as tf
a = tf.add(3, 5)
print(a)
3
5 a
37
How to get the value of a?
38
How to get the value of a?
The session will look at the graph, trying to think: hmm, how can I get the value of a,
then it computes all the nodes that leads to a. 39
How to get the value of a?
The session will look at the graph, trying to think: hmm, how can I get the value of a,
then it computes all the nodes that leads to a. 40
How to get the value of a?
41
tf.Session()
42
tf.Session()
Session will also allocate memory to store the current values of variables.
43
More graph
Visualized by TensorBoard
x = 2
y = 3
op1 = tf.add(x, y)
op2 = tf.multiply(x, y)
op3 = tf.pow(op2, op1)
with tf.Session() as sess:
op3 = sess.run(op3)
44
Subgraphs
x = 2
y = 3 useless pow_op
add_op = tf.add(x, y)
mul_op = tf.multiply(x, y)
useless = tf.multiply(x, add_op)
pow_op = tf.pow(add_op, mul_op)
with tf.Session() as sess:
z = sess.run(pow_op)
add_op mul_op
45
Subgraphs
x = 2
y = 3 useless pow_op
add_op = tf.add(x, y)
mul_op = tf.multiply(x, y)
useless = tf.multiply(x, add_op)
pow_op = tf.pow(add_op, mul_op)
with tf.Session() as sess:
z, not_useless = sess.run([pow_op,
useless]) add_op mul_op
tf.Session.run(fetches,
feed_dict=None,
options=None,
run_metadata=None)
46
fetches is a list of tensors whose values you want
Subgraphs
Possible to break graphs into
several chunks and run them
parallelly across multiple CPUs,
GPUs, TPUs, or other devices
Example: AlexNet
# Creates a graph.
with tf.device('/gpu:2'):
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], name='b')
c = tf.multiply(a, b)
48
What if I want to build more
than one graph?
49
You can
but you don’t need more than one graph
The session runs the default graph
50
But what if I really want to?
51
URGH, NO
52
BUG ALERT!
● Multiple graphs require multiple sessions, each will try to use all
available resources by default
● Can't pass data between them without passing them through
python/numpy, which doesn't work in distributed
● It’s better to have disconnected subgraphs within one graph
53
I insist ...
54
tf.Graph()
create a graph:
g = tf.Graph()
55
tf.Graph()
to add operators to a graph, set it as default:
g = tf.Graph()
with g.as_default():
x = tf.add(3, 5)
sess = tf.Session(graph=g)
with tf.Session() as sess:
sess.run(x)
56
tf.Graph()
To handle the default graph:
g = tf.get_default_graph()
57
tf.Graph()
Do not mix default graph and user created graphs
g = tf.Graph()
58
tf.Graph()
Do not mix default graph and user created graphs
g1 = tf.get_default_graph()
g2 = tf.Graph()
59
60
Why graphs
61
Why graphs
62
Why graphs
63
Why graphs
Data pipeline
Feedback: [email protected]
Thanks!
65