cyberzhg / keras-lookahead Goto Github PK
View Code? Open in Web Editor NEWLookahead mechanism for optimizers in Keras.
Home Page: https://pypi.org/project/keras-lookahead/
License: MIT License
Lookahead mechanism for optimizers in Keras.
Home Page: https://pypi.org/project/keras-lookahead/
License: MIT License
Describe the Bug
I use tf.keras,Radam project is OK,but Lookahead goes wrong,detailed information is below:
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/backend.py in get_value(x)
2796 elif ops.inside_function():
2797 raise RuntimeError('Cannot get value inside Tensorflow graph function.')
-> 2798 return x.eval(session=get_session())
2799
2800
AttributeError: 'ReplicatedVariable' object has no attribute 'eval'
Version Info
Minimal Codes To Reproduce
from keras_lookahead import Lookahead
model.compile(loss='categorical_crossentropy',
optimizer = Lookahead('adam', sync_period=5, slow_step=0.5),
metrics=['accuracy'])
model.fit(X_train, X_train_label,
validation_data=(X_val, X_val_label),
epochs=100, batch_size=64,
shuffle=True,
callbacks=[early_stopping])
Optimizer weights are now stored in model.optimizer.optimizer
, and model.optimizer.weights==[]
- hence, default saving and loading methods will not work. Existing code can account for this as follows:
if "Lookahead" in str(model.optimizer):
optimizer = model.optimizer.optimizer
else:
optimizer = model.optimizer
optimizer.get_weights(...)
optimizer.set_weights(...)
NOTE: unsure if above accounts for all differences. Packing weights
into model.optimizer
directly will render this redundant.
Per my understanding, TF_KERAS=True
in backend.py imports keras
from tensorflow.python
- and, in optimizers.py, if TF_KERAS gets evaluated, and TF_KERAS=True
is set. Though TF_KERAS=False
by default, it always ends up =True
- so else
is never executed.
Is this accurate? (if so, why an if
-statement?) Lastly, does the code somehow depend on tensorflow.python.keras
as opposed to simply keras
? Thanks
Could you please extend your work to have a Lookahead optimizer for Tensorflow as well? Also it would be great if one could use your Tensorflow RAdam implementation with the TF version of the Lookahead optimizer.
Thank you for implementing this package btw!
How can I use TF.Keras?
Thanks a lot for this implementation.
0.6.0 is committed on GitHub, but not present on PyPi. It is useful for TF 2.0 and Keras 2.3 users. Do you plan to push it in a near future?
When used with RAdam, how to set the value of "sync_period", and "slow_step" ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.