tf.placeholder
发布时间:2020-12-14 21:52:31 所属栏目:大数据 来源:网络整理
导读:tf.placeholder tf.placeholder( ? ? dtype, ? ? shape=None, ? ? name=None ) Inserts a placeholder for a tensor that will be always fed. Important : This tensor will produce an error if evaluated. Its value must be fed using the? feed_dict ?o
tf.placeholdertf.placeholder( Inserts a placeholder for a tensor that will be always fed. Important: This tensor will produce an error if evaluated. Its value must be fed using the? 在构建graph的过程中,tensor是没有实际数据的,只是表达计算过程,那么通过placeholder函数对tensor变量进行占位表示。然后在Session执行过程中,通过feed_dict对占位的tensor进行feed值 Args:
Returns:A? Raises:
? 1 import tensorflow as tf 2 import numpy as np 3 4 5 x = tf.placeholder(tf.float32,shape=(1024,1024)) 6 y = tf.matmul(x,x) 7 8 with tf.Session() as sess: 9 #print(sess.run(y)) # ERROR: will fail because x was not fed. 10 rand_array = np.random.rand(1024,1024) 11 print(sess.run(y,feed_dict={x: rand_array})) # Will succeed. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |