TensorFlow笔记:PlaceHolder(哲の王tensorflow视频笔记2)

来源:互联网 发布:nasa数据查询 编辑:程序博客网 时间:2024/06/06 03:02

ok,那继续上讲的视频 ,这次笔记主要记录placeholder,这是个常用的东西,有必要掌握清楚。

先再写一遍上次basic_operation的代码,这次稍作一点点改动

graph = tf.Graph()with graph.as_default():value1 = tf.placeholder(dtype = tf.int64)   #那placeholder至少要声明一下什么类型value2 = tf.Variable([3,4],dtype=tf.int64)   #这里因为是整数 会默认dtype=tf.int32  我们为了compatible要将其改为int64,因为另一个乘子是int64呀mul = value1 * value2with tf.Session(graph = graph) as mySess:tf.initialize_all_variables().run()holderValue = {value1:[1,2]}runResult = mySess.run(mul,feed_dict=holderValue)    #看到没有 placeholder的赋值过程是这样子的 print('乘法(value1,value2)=',runResult)


MENTION IT!!! 省内存 placeholder才是王道!!!

def load_from_remote():return [-x for x in range [100000]]   #那么加载相当庞大的数据,就要采取一次加载一部分的方法,需要用到placeholdercoding:法1:for i in range(0,100000,2):holdervalue = {value1:value[i:i+2]}    #分步函数法2:for partialValue in load_partial(value,2):holdervalue = {value1,partialValue}def load_partial(value,step):           #iterator 自定义的迭代器index = 0while step < len(value):yield value[index:index+step]  #yield让函数暂停index += stepreturn#返回出去



ok 本次两个注意点 

1.dict

2.一次加载一部分

0 0
原创粉丝点击