Michael2397

tensorflow第一个例子

import tensorflow as tf
import numpy as np

# create data
x_data = np.random.rand(100).astype(np.float32)
y_data = x_data*0.1 + 0.3
Weights = tf.Variable(tf.random_uniform([1], -1.0, 1.0))
biases = tf.Variable(tf.zeros([1]))

y = Weights*x_data + biases
loss = tf.reduce_mean(tf.square(y-y_data))
optimizer = tf.train.GradientDescentOptimizer(0.5)
train = optimizer.minimize(loss)
init = tf.global_variables_initializer()  # 替换成这样就好
sess = tf.Session()
sess.run(init)          # Very important

for step in range(201):
    sess.run(train)
    if step % 20 == 0:
        print(step, sess.run(Weights), sess.run(biases))

 

分类:

技术点:

相关文章:

  • 2021-07-12
  • 2021-05-07
  • 2021-04-24
  • 2021-04-16
  • 2021-05-15
  • 2021-10-04
  • 2021-07-30
  • 2021-10-23
猜你喜欢
  • 2021-12-01
  • 2021-07-21
  • 2022-02-09
  • 2022-02-09
  • 2022-02-09
  • 2022-01-11
相关资源
相似解决方案