Can I access what was once `tf.get_global_step()` from within a custom Keras layer?

醉酒当歌 提交于 2020-05-15 08:42:09

问题


I'm implementing a custom Layer with the Keras API (working with TF2.0-beta). I want to use the epoch number in my calculation in order to decay a parameter over time (meaning - in the call() method).

I'm used to tf.get_global_step() but understand that TF deprecated all global scopes, and definitely for a good reason.

If I had the model instance, I could use model.optimizer.iterations, but I'm not sure how I get the instance of my parent model when I'm implementing a Layer.

Do I have any way to do that or the only way is to let the layer expose a Callback that will update the parameter I want to decay? Other ideas? Ideally something that wouldn't make the user of the layer aware of that inner detail (that's why I don't like the Callback approach - user has to add them to the model).

来源:https://stackoverflow.com/questions/56621663/can-i-access-what-was-once-tf-get-global-step-from-within-a-custom-keras-lay

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!