码迷,mamicode.com
首页 > 其他好文 > 详细

tf_upgrade_v2.exe实验

时间:2019-11-13 16:02:19      阅读:85      评论:0      收藏:0      [点我收藏+]

标签:min   nump   run   tar   loss   div   ast   variables   对比   

实验前

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
###create tensorflow structure start###
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)
###create tensorflow structure end###
train = optimizer.minimize(loss)
init = tf.initialize_all_variables()
sess = tf.Session()
sess.run(init)
for step in range(201):
    sess.run(train)
    if step % 20 == 0:
        print(step, sess.run(Weights), sess.run(biases))

实验后:

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
###create tensorflow structure start###
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(input_tensor=tf.square(y-y_data))
optimizer = tf.compat.v1.train.GradientDescentOptimizer(0.5)
###create tensorflow structure end###
train = optimizer.minimize(loss)
init = tf.compat.v1.initialize_all_variables()
sess = tf.compat.v1.Session()
sess.run(init)
for step in range(201):
    sess.run(train)
    if step % 20 == 0:
        print(step, sess.run(Weights), sess.run(biases))

代码对比可看出代码前后的变化

tf_upgrade_v2.exe实验

标签:min   nump   run   tar   loss   div   ast   variables   对比   

原文地址:https://www.cnblogs.com/2008nmj/p/11849957.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!