tensorflow 1.x 实战教程(三)——fetch 与 feed

目标

本文旨在介绍 tensorflow 入门知识点及实战示例,希望各位新手同学能在学习之后熟练 tensorflow 相关操作

简单的 fetch 代码

import tensorflow as tf

a = tf.constant(1.0)
b = tf.constant(4.0)
c = tf.constant(7.0)
add = tf.add(tf.add(a, b), c)
mul = tf.multiply(tf.multiply(a, b), c)
with tf.Session() as sess:
    print(sess.run(add))
    print(sess.run(mul))
复制代码

输出结果

12.0
28.0
复制代码

简单的 feed 代码

import tensorflow as tf

n = tf.placeholder(tf.int8)
m = tf.placeholder(tf.int8)
r = tf.multiply(n,m)
with tf.Session() as sess:
    print(sess.run(r, feed_dict={n:3,m:4}))   
复制代码

输出结果

12    
复制代码

本文参考

本文参考:blog.csdn.net/qq_19672707…

猜你喜欢

转载自juejin.im/post/7085888095588974599
今日推荐