在tensorflow中,如何在喂食前使用占位符的值?
新来TensorFlow,现在我需要喂奶前占位符使用的值,是这样的:在tensorflow中,如何在喂食前使用占位符的值?
tensor = tf.placeholder(tf.float32, [None, 3])
Mat_items = tf.Variable(tf.random_normal([10,10]))
Mat_users = tf.Variable(tf.random_normal([10,10]))
item_index = tensor[:, 0]
user_index = tensor[:, 1]
rating = tensor[:, 2]
Val = Mat_items[item_index, :]-Mat_users[user_index, :]
而张为N行的占位符3周的cols,第一栏和第二栏是指数Mat_items和Mat_users分别和Mat_itemsMat_users是需要被索引的变量。
运行它绝对会抛出一个错误,因为item_index,user_index都是张量而不是数字喂养前。 所以我想知道Tensorflow是否可以实现这种需求? 任何建议将不胜感激:) :)
===================================== ==================================== 除了我的问题:Val
取决于某些列在Tensor
就像第一列和第二列。所以,当我创建我的曲线,我的代码
Val = Mat_items[item_index, :]-Mat_users[user_index, :]
item_index和USER_INDEX是tensor
片,两者都是类型tensor
too.It将抛出error.I不知道如何实现TensorFlow这种需求。
============================================== =========================== 找到了解决办法:以上
tensor = tf.placeholder(tf.float32, [None, 3])
Mat_items = tf.Variable(tf.random_normal([10,10]))
Mat_users = tf.Variable(tf.random_normal([10,10]))
for each in range(batch_number):
item_ind, user_ind = tensor[each, 2], tensor[each, 1]
rating = tensor[each, 1]
Val = Mat_item[item_ind, 0]*Mat_user[user_ind, 0]*rating
代码似乎在构建图册成本工作即使使用litte数据集(批量大小约为1000,并且只有一个批次需要测试),也会花费太多时间,构建图形大约需要78秒,我不确定它是否正常?
你的问题似乎很模糊,但我想你的问题是如何将值放入占位符。如果您想从Val
获得输出,则必须使用输入来补充tensor
,因为它默认不包含任何值。 Val
也取决于tensor
以计算其输出。您的输入必须与tensor
的尺寸相同。 (在这种情况下,让我们假设你的输入是随机噪声input_tensor = numpy.random.uniform(-1, 1, size =(None, 3))
哪里都不是必须指定的值。
所以,你开始会话之后,执行 output = sess.run(Val, feed_dict = {tensor: input_tensor})
和output
将是你的结果
是,* Val *取决于* tensor *。具体而言,* Val *取决于* tensor *的某些列中的值,因为这些列中的值是* Val *的索引。但是,如果我创建了像'Val = Mat_items [item_index,:] - Mat_users [user_index,:]'会抛出错误,我的问题会更清楚吗? – FesianXu