File tree 2 files changed +54
-0
lines changed
tensorflowTUT/tf5_example2
2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change
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
+
Original file line number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments