Python 在tensorflow中,如何使用占位符';喂食前的s值?
TensorFlow新手,现在我需要在输入前使用占位符中的值,类似于:Python 在tensorflow中,如何使用占位符';喂食前的s值?,python,tensorflow,Python,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 = tens
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列,第一列和第二列分别是Mat_项和Mat_用户的索引,Mat_项Mat_用户是需要索引的变量。运行它绝对会抛出一个错误,因为条目索引和用户索引在馈送之前都是张量而不是数字。 所以我想知道Tensorflow能否实现这个需求? 任何建议都将不胜感激!:) ========================================================================= 除了我的问题:
Val
依赖于Tensor
中的某些列,就像第一列和第二列一样。因此,当我创建图形时,我会编写代码
Val = Mat_items[item_index, :]-Mat_users[user_index, :]
item\u index和user\u index是tensor的切片,它们也是类型tensor
。它会抛出错误。我不知道如何在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
上面的代码在构建图形时似乎很有效,即使使用少量数据集(批量大小约为1000,并且只有一批用于测试),构建图形大约需要78秒,我不确定这是否正常?您的问题似乎很模糊,但我想您的问题是如何将值放入占位符中。如果要从
Val
获取输出,必须使用输入补充tensor
,因为默认情况下它不包含任何值Val
还依赖于tensor
来计算其输出。您的输入必须与张量
的大小相同。(在本例中,假设您的输入是随机噪声input_tensor=numpy.random.uniform(-1,1,size=(None,3))
,其中None是您必须指定的值
因此,在开始会话后,执行
output=sess.run(Val,feed\u dict={tensor:input\u tensor})
而output
将是您的结果是的,Val依赖于张量。具体来说,Val依赖于张量的某些列中的值,因为这些列中的值是Val的索引。但是如果我创建像Val=Mat_items[item_index,:]-Mat_users[user_index,:]
这样的图形,我的问题会更清楚吗?