Skip to content

Commit 1066bdc

Browse files
author
Mofan Zhou
committed
create tensorflow4
0 parents  commit 1066bdc

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tensorflow/tensorflow4_example2.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import numpy as np
2+
import tensorflow as tf
3+
4+
# create data
5+
x_data = np.random.rand(100).astype(np.float32)
6+
y_data = x_data * 0.1 + 0.3
7+
8+
## create tensorflow structure start##
9+
Weights = tf.Variable(tf.random_uniform([1], -1.0, 1.0))
10+
biases = tf.Variable(tf.zeros([1]))
11+
y = Weights * x_data + biases
12+
13+
loss = tf.reduce_mean(tf.square(y-y_data))
14+
optimizer = tf.train.GradientDescentOptimizer(0.5)
15+
train = optimizer.minimize(loss)
16+
17+
init = tf.initialize_all_variables()
18+
## tenstflow structure end ##
19+
sess = tf.Session()
20+
sess.run(init)
21+
22+
for step in range(201):
23+
sess.run(train)
24+
if step % 20 == 0:
25+
print(step, sess.run(Weights), sess.run(biases))
26+
27+
28+

0 commit comments

Comments
 (0)