TensorFlow学习笔记之四——源码分析之基本操作
来源:互联网 发布:淘宝淘金币大转盘漏洞 编辑:程序博客网 时间:2024/06/06 22:48
例子源码地址:
https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/1%20-%20Introduction/basic_operations.py
根据网上的入门例子,一点点的熟悉代码和TensorFlow。对这个基本的例子,做一个注释,备忘之余分享给同样入门的初学者。
import tensorflow as tfa = tf.constant(2)b = tf.constant(3)
#把a,b定义为tensorflow的常量,并且赋值。
with tf.Session() as sess: print "a=2, b=3" print "Addition with constants: %i" % sess.run(a+b) print "Multiplication with constants: %i" % sess.run(a*b)
#使用Session的run()输出a+b和a*b的结果。使用with tf.Session() as sess这种用法,在sess.run()结束之后,不用调用sess.close()释放资源。
a = tf.placeholder(tf.int16)b = tf.placeholder(tf.int16)
#把a,b定义成为tf.int16类型的占位符,并没有放具体的数值进去。
add = tf.add(a, b)mul = tf.mul(a, b)
#在a,b两个占位符之上,定义了两个操作,add和mul。
with tf.Session() as sess: print "Addition with variables: %i" % sess.run(add, feed_dict={a: 2, b: 3}) print "Multiplication with variables: %i" % sess.run(mul, feed_dict={a: 2, b: 3})
#给a,b赋值,并且对他们进行前文定义的add和mul操作。
matrix1 = tf.constant([[3., 3.]])matrix2 = tf.constant([[2.],[2.]])product = tf.matmul(matrix1, matrix2)
#定义两个常量矩阵,并且为这两个矩阵定义了一个matmul操作product。
with tf.Session() as sess: result = sess.run(product) print result
#运行product操作,并且将结果result输出。
1 0
- TensorFlow学习笔记之四——源码分析之基本操作
- Tensorflow学习笔记参考—源码分析之最近算法
- TensorFlow学习笔记之五——源码分析之最近算法
- TensorFlow学习笔记之五——源码分析之最近算法
- TensorFlow学习笔记之源码分析(3)---- retrain.py
- 【学习笔记】TensorFlow 入门之基本使用
- TensorFlow学习笔记之源码分析(1)----最近算法nearest_neighbor
- TensorFlow学习笔记之源码分析(2)----手写数字识别mnist example
- spring源码学习之四 BeanDefinitionParserDelegate分析
- CAFFE源码学习笔记之四-device_alternate
- TensorFlow学习笔记(四):CNN之AlexNet网络
- TensorFlow学习笔记(四):手写数字识别之LSTM网络
- ORACLE学习笔记之oracle基本操作
- 学习笔记之NodeJs基本操作
- Python学习笔记之:文件基本操作
- 【Git】学习笔记之基本操作
- MySQL 学习笔记 之 数据库基本操作
- tensorflow学习笔记(一)——tensorflow基本使用
- jsp中request传递参数汉字乱码
- 线程安全
- Activity(一)
- HBase1.1.4搭建笔记
- 单例模式 Singleton Pattern
- TensorFlow学习笔记之四——源码分析之基本操作
- 如何在MySQL中设置外键约束以及外键的作用
- C/C++中一维与多维数组
- 图片轮播所遇到的问题
- 上传文件并读取excel总结
- 安卓动画
- Arduino携手LCD1602 向世界问好“hello World!”
- NavigationContorller跳转问题
- Spring对ORM的支持之集成Hibernate3