-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsandbox.py
64 lines (47 loc) · 1.22 KB
/
sandbox.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import tensorflow as tf
# model parameters
w = tf.Variable([.3], tf.float32)
b = tf.Variable([-.3], tf.float32)
# inputs and outputs
x = tf.placeholder(tf.float32)
linear_model = w * x + b
y = tf.placeholder(tf.float32)
# loss
squared_delta = tf.square(linear_model - y)
loss = tf.reduce_sum(squared_delta)
# optimize
optimizer = tf.train.GradientDescentOptimizer(0.01)
train = optimizer.minimize(loss)
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)
for i in range (1000):
sess.run(train, {x:[1,2,3,4], y:[0,-1,-2,-3]})
print(sess.run([w,b]))
#print(sess.run(loss, {x:[1,2,3,4], y:[0,-1,-2,-3]}))
# example with multiplication and FileWriter to make a graph
"""
a = tf.constant(5.0)
b = tf.constant(6.0)
c = a * b
sess = tf.Session()
File_Writer = tf.summary.FileWriter('/Users/AkilHashmi/Documents/GitHub/tensorflowPractice/graph', sess.graph)
print(sess.run(c))
sess.close()
"""
# this will print all values about the node
"""
print(node1, node2)
"""
# manually open and close session
"""
sess = tf.Session()
print(sess.run([node1, node2]))
sess.close()
"""
# Alternative way to open (and auto close session)
"""
with tf.Session() as sess:
output = sess.run([node1, node2])
print(output)
"""