-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTensorFlow for deep learning
47 lines (34 loc) · 1.69 KB
/
TensorFlow for deep learning
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
TensorFlow provides multiple APIs. The lowest level API--TensorFlow Core-- provides you with complete programming control.
The higher level APIs are built on top of TensorFlow Core.
Tensor
----------------------------------------------
The central unit of data in TensorFlow is the tensor.
A tensor consists of a set of primitive values shaped into an array of any number of dimensions.
A tensor's rank is its number of dimensions.
example:
3 # a rank 0 tensor; a scalar with shape []
[1., 2., 3.] # a rank 1 tensor; a vector with shape [3]
[[1., 2., 3.], [4., 5., 6.]] # a rank 2 tensor; a matrix with shape [2, 3]
[[[1., 2., 3.]], [[7., 8., 9.]]] # a rank 3 tensor with shape [2, 1, 3]
Comutational Graph
------------------------------------------------------
You might think of TensorFlow Core programs as consisting of two discrete sections:
Building the computational graph.
Running the computational graph.
A computational graph is a series of TensorFlow operations arranged into a graph of nodes.
Each node takes zero or more tensors as inputs and produces a tensor as an output.
W
e can create two floating point Tensors node1 and node2 as follows:
node1 = tf.constant(3.0, dtype=tf.float32)
node2 = tf.constant(4.0) # also tf.float32 implicitly
print(node1, node2);
A session encapsulates the control and state of the TensorFlow runtime.
sess = tf.Session()
print(sess.run([node1, node2]))
a = tf.placeholder(tf.float32)
b = tf.placeholder(tf.float32)
adder_node = a + b # + provides a shortcut for tf.add(a, b)
print(sess.run(adder_node, {a: 3, b: 4.5}))
print(sess.run(adder_node, {a: [1, 3], b: [2, 4]}))
add_and_triple = adder_node * 3.
print(sess.run(add_and_triple, {a: 3, b: 4.5}))