在训练期间启用和禁用变量学习 [英] Enable and disable learning of a variable during training

查看:27
本文介绍了在训练期间启用和禁用变量学习的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在训练期间开始或停止学习变量.虽然Variable的构造函数有一个trainable参数,但是这个参数在构造之后是不能改变的.

I want to either start or stop the learning of a variable during training. Although Variable's constructor has a trainable parameter, this parameter cannot be changed after construction.

为了达到这个效果,我目前的解决方案是在我想改变一个变量的可训练状态时保存模型,使用设置为所需可训练状态的变量重建网络,并重新加载权重.

To achieve this effect, my current solution is to save the model at the point I want to change the trainable status of a variable, reconstruct the network with the variables set to the desired trainable status, and reload the weights.

有没有更简单的方法来以编程方式改变训练对变量的影响?

Is there a less cumbersome way to change the effect of training on a variable programmatically?

推荐答案

从 TF 1.8 开始,现在可以通过将自定义学习率乘数设置为可以动态设置为 0 或 1 的变量来轻松完成,从而有效地打开或关闭变量的训练.

Since TF 1.8 this can now be done easily by setting a custom learning rate multiplier to variables that can be dynamically set to 0 or 1, effectively switching on or off the training of the variable.

此处详细了解自定义学习率乘数.

More on custom learning rate multipliers here.

这篇关于在训练期间启用和禁用变量学习的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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