我将两个参数传递给tensorflow中的my(loss)函数,它(我认为)应该是占位符的形式,因为它们随着不同的步骤而变化。我在训练时喂它们吃。 我的节目大纲如下。 我的问题是,他们是否能有效地接受我提供给他们的价值观? 如果你能看看下面的片段,告诉我我做得对吗? 顺便说一下,我没有发现任何错误或什么。在
tetha1_placeholder, tetha2_placeholder = tf.placeholder(tf.float32, name='tetha1plh'), tf.placeholder(tf.float32, name='tetha2plh')
hyperparams = {'tetha1': tetha1_placeholder,'tetha2':tetha2_placeholder}
[getting embeddings1,embeddings2, embeddings3 from my model]
loss = loss_function (embeddings1,embeddings1,embeddings3, hyperparams)
with sess.as_default():
while true:
step = sess.run(global_step, feed_dict=None)
t1, t2 = calculate_params(step)
feed_dict = {tetha1_placeholder:t1, tetha2_placeholder:t2}
error=sess.run([loss], feed_dict=feed_dict)
def loss_function (embeddings1,embeddings2,embeddings3, hyperparams):
pos_dist =hyperparams['tetha1'] * tf.reduce_sum(tf.square(tf.subtract(embeddings1, embeddings2)), 1)
neg_dist = hyperparams['tetha2'] *tf.reduce_sum(tf.square(tf.subtract(embeddings1, embeddings3)), 1)
loss = tf.reduce_mean(tf.add(pos_dist,neg_dist))
return loss
程序看起来是正确的。当您调用}将具有值
sess.run([loss], feed_dict=feed_dict)
时,loss_function()
中的张量hyperparams['tetha1']
将具有值t1
,loss_function()
中的张量{t2
。在另外,如果
t1
始终具有相同的形状,我建议在为tetha1_placeholder
构造tf.placeholder()
时传递该形状(类似于t2
和tetha2_placeholder
)。在相关问题 更多 >
编程相关推荐