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

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 * value2
with 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]]   #那么加载相当庞大的数据,就要采取一次加载一部分的方法,需要用到placeholder
coding:
法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 = 0
	while step < len(value):
		yield value[index:index+step]  #yield让函数暂停
		index += step
	return				#返回出去



ok 本次两个注意点 

1.dict

2.一次加载一部分

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值