Tensorflow学习精要版 - MNIST train and test your own images
发布时间
阅读量:
阅读量
初识
在Tensorflow框架中,Python语言所定义的Tensor对象本质上对应于numpy库中的ndarray数据结构。
# 创建一个变量, 初始化为标量 0.
state = tf.Variable(0, name="counter")
# 创建一个 op, 其作用是使 state 增加 1
one = tf.constant(1)
new_value = tf.add(state, one)
#赋值
update = tf.assign(state, new_value)
# 启动图, 运行 op
with tf.Session() as sess:
#初始化参数
tf.global_variables_initializer().run()
# 打印 'state' 的初始值
print sess.run(state)
# 运行 op, 更新 'state', 并打印 'state'
for _ in range(3):
sess.run(update)
print sess.run(state)
# 输出:
全部评论 (0)
还没有任何评论哟~
