LJK*_*JKS 7 python machine-learning neural-network tensorflow
问题是,是否只是改变learning_rate参数tf.train.AdamOptimizer实际上会导致行为的任何变化:假设代码如下所示:
myLearnRate = 0.001
...
output = tf.someDataFlowGraph
trainLoss = tf.losses.someLoss(output)
trainStep = tf.train.AdamOptimizer(learning_rate=myLearnRate).minimize(trainLoss)
with tf.Session() as session:
#first trainstep
session.run(trainStep, feed_dict = {input:someData, target:someTarget})
myLearnRate = myLearnRate * 0.1
#second trainstep
session.run(trainStep, feed_dict = {input:someData, target:someTarget})
Run Code Online (Sandbox Code Playgroud)
myLearnRate现在减少了trainStep吗?这是,只创建trainStep一次评估的节点:
trainStep = tf.train.AdamOptimizer(learning_rate=myLearnRate).minimize(trainLoss)
Run Code Online (Sandbox Code Playgroud)
或者是否每次评估session.run(train_step)?我怎么能AdamOptimizer在Tensorflow中检查我是否确实更改了Learnrate.
免责声明1:我知道手动更改LearnRate是不好的做法.
免责声明2:我知道有一个类似的问题,但它是通过输入张量来解决的,learnRate在每个trainStep(这里)更新.这让我对假设它只会用张量作为输入工作倾斜learning_rate的AdamOptimizer,但我也不是确信这一点,我也能理解它背后的原因.
简短的回答是,不,你的新学习率不适用.TF在您第一次运行时构建图形,并且在Python端更改某些内容不会转换为运行时图形中的更改.但是,您可以非常轻松地为图表提供新的学习率:
# Use a placeholder in the graph for your user-defined learning rate instead
learning_rate = tf.placeholder(tf.float32)
# ...
trainStep = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(trainLoss)
applied_rate = 0.001 # we will update this every training step
with tf.Session() as session:
#first trainstep, feeding our applied rate to the graph
session.run(trainStep, feed_dict = {input:someData,
target:someTarget,
learning_rate: applied_rate})
applied_rate *= 0.1 # update the rate we feed to the graph
#second trainstep
session.run(trainStep, feed_dict = {input:someData,
target:someTarget,
learning_rate: applied_rate})
Run Code Online (Sandbox Code Playgroud)
是的,优化器仅创建一次:
tf.train.AdamOptimizer(learning_rate=myLearnRate)
Run Code Online (Sandbox Code Playgroud)
它会记住通过的学习率(实际上,如果您传递一个浮点数,它将为它创建一个张量),并且您以后的更改myLearnRate不会影响它。
是的session.run(),如果您确实需要,可以创建一个占位符并将其传递给。但是,正如您所说,这很不常见,可能意味着您以错误的方式解决了原产地问题。
| 归档时间: |
|
| 查看次数: |
3302 次 |
| 最近记录: |