Skip to content

Commit d0b560d

Browse files
author
Mofan Zhou
committed
create tf5
1 parent 8e6fc23 commit d0b560d

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# View more python learning tutorial on my Youtube and Youku channel!!!
2+
3+
# Youtube video tutorial: https://www.youtube.com/channel/UCdyjiB5H8Pu7aDTNVXTTpcg
4+
# Youku video tutorial: http://i.youku.com/pythontutorial
5+
6+
import tensorflow as tf
7+
import numpy as np
8+
9+
# create data
10+
x_data = np.random.rand(100).astype(np.float32)
11+
y_data = x_data*0.1 + 0.3
12+
13+
### create tensorflow structure start ###
14+
15+
### create tensorflow structure end ###
16+
# Very important
17+
18+
for step in range(201):
19+
pass
20+
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# View more python learning tutorial on my Youtube and Youku channel!!!
2+
3+
# Youtube video tutorial: https://www.youtube.com/channel/UCdyjiB5H8Pu7aDTNVXTTpcg
4+
# Youku video tutorial: http://i.youku.com/pythontutorial
5+
6+
import tensorflow as tf
7+
import numpy as np
8+
9+
# create data
10+
x_data = np.random.rand(100).astype(np.float32)
11+
y_data = x_data*0.1 + 0.3
12+
13+
### create tensorflow structure start ###
14+
Weights = tf.Variable(tf.random_uniform([1], -1.0, 1.0))
15+
biases = tf.Variable(tf.zeros([1]))
16+
17+
y = Weights*x_data + biases
18+
19+
loss = tf.reduce_mean(tf.square(y-y_data))
20+
optimizer = tf.train.GradientDescentOptimizer(0.5)
21+
train = optimizer.minimize(loss)
22+
23+
init = tf.initialize_all_variables()
24+
### create tensorflow structure end ###
25+
26+
sess = tf.Session()
27+
sess.run(init) # Very important
28+
29+
for step in range(201):
30+
sess.run(train)
31+
if step % 20 == 0:
32+
print(step, sess.run(Weights), sess.run(biases))
33+
34+

0 commit comments

Comments
 (0)