TensorFlow基本操作及函数
来源:互联网 发布:上海乐蜀网络 编辑:程序博客网 时间:2024/05/16 12:29
- 基本结构
- placeholder和feed_dict
- 保存模型与读取模型trainSaver
基本结构
import tensorflow as tfa = tf.placeholder("float",[None,2]) # 占位符,"float"是64位的;tf.float32是32位的;b = tf.placeholder(tf.float32, [2,1 ])#任意行,20列的x。y = tf.matmul(a, b) #op节点;tf.matmul是点积,还有很多函数;sess = tf.Session()#建立会话print (sess.run(y, feed_dict={a: [[2,4],[4,1]],b:[[1],[2]]}))sess.close()sess1 = tf.InteractiveSession()#交互式的会话;print("\n",sess1.run(y, feed_dict={a: [[1,2]],b:[[1],[2.]]}))print("\n",y.eval(feed_dict={a: [[2,4],[4,1]],b:[[1],[2]]}))sess1.close()'''output:[[ 10.] [ 6.]] [[ 5.]] [[ 10.] [ 6.]]'''
.placeholder()和feed_dict()
tf.placeholder(dtype,shape=None,name=None)tf.Session.run(fetches, feed_dict=None, options=None, run=metadate=None)'''dtype是必须指定的数据格式,shape和name可以为空;当计算时,需要feed给它这个占位符的值;feed_dict就是一个赋值字典;'''a=tf.placeholder('float')b=tf.placeholder('float')c=tf.multiply(a,b)#以前是mul(),后来更新成multiply()了;with tf.Session() as sess: print(sess.run(c,feed_dict={a:2,b:3}))'''可以给非占位符的张量赋值,只要它是feedable的;'''tf.Graph.is_feedable(tensor)#判断它是不是feedable
保存模型与读取模型.train.Saver()
#保存saver = tf.train.Saver()saver.save(sess,"Model/model.ckpt")#读取#还是和训练前一样先定义完所有变量后:saver = tf.train.Saver()saver.restore(sess, "./Model/model.ckpt")#直接加载持久化的图,不需要先定义模型中保存的变量;saver = tf.train.import_meta_graph("Model/model.ckpt.meta")saver.restore(sess, "./Model/model.ckpt")#加载模型时给变量更名;#先定义好想更改的名字变量:saver = tf.train.Saver({"v1": u1, "v2": u2}) saver.restore(sess, "./Model/model.ckpt") #获取保存的模型中的变量ema = tf.train.ExponentialMovingAverage(0.99)print(ema.variables_to_restore())
阅读全文
0 0
- TensorFlow基本操作及函数
- TensorFlow 基本操作
- Tensorflow-基本操作基本知识
- 53、tensorflow基本操作
- TensorFlow基本操作(二)
- Tensorflow | 基本函数介绍
- scss基本使用及操作函数
- Python中函数定义及基本操作
- tensorflow实践-01:基本操作
- TensorFlow(一):基本操作
- Tensorflow安装及基本使用
- tensorflow的一些基本函数
- TensorFlow 基本变量定义,基本操作,矩阵基本操作
- tensorflow | 操作函数 和 数据类型
- tensorflow常用函数及概念
- tensorflow常用函数及概念
- tensorflow常用函数及概念
- Tensorflow系列之(一):Tensorflow的基本操作
- 计蒜客 课程规划(景驰无人驾驶1024编程邀请赛 D)
- 一分钟ECS上搭建云HBase Thriftserver
- 需要了解的相关知识
- QT安装问题
- 洛谷P1082 同余方程
- TensorFlow基本操作及函数
- spark 日常
- spring boot:Scheduling Tasks
- 爬格子呀6-4、6-5、6-9
- 软件评测师资源共享
- PHP学习-1
- Spring AOP基础
- 统计一段文字中每个字符出现的次数,并输出结果(包含字符及其出现次数)保存在一个适合的集合中。
- 程序员应该学的投资