python函数定义时参数相当于占位符_传递tensorflow占位符作为函数参数

我将两个参数传递给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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值