根据TENSORFLOW中的if语句使用不同的优化器 [英] Use different optimizers depending on a if statement in TENSORFLOW

查看:229
本文介绍了根据TENSORFLOW中的if语句使用不同的优化器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试通过两个训练步骤来实现神经网络.首先,我想减少loss_first_part函数,然后我想减少loss_second_part.

I'm currently trying to implement a neural network with two training steps. First i want to reduce the loss_first_part function and then i want to reduce the loss_second_part.

tf.global_variable_initializer().run()

for epoch in range(nb_epochs)
    if epoch < 10 : 
       train_step = optimizer.minimize(loss_first_part)
    else :
       train_step = optimizer.minimize(loss_second_part)

问题是初始化程序应在optimizer.minimize调用之后定义.确实我有以下错误Attempting to use unintialized value betal_power.

The problem is that the initializer should be defined after the optimizer.minimize call. Indeed i've the following error Attempting to use unintialized value betal_power.

考虑到我希望优化器依赖于时代,我该如何解决此问题...

How can i fix this problem considering that i want my optimizer to depend on the epoch...

非常感谢您的帮助!

推荐答案

我发现了!很简单...

I've found ! So simple...

train_step1 = optimizer.minimize(loss_first_part)
train_step2 = optimizer.minimize(loss_second_part)
tf.global_variable_initializer().run()

if ... :
   sess.run(train_step1)
else :
   sess.run(train_step2)

这篇关于根据TENSORFLOW中的if语句使用不同的优化器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆