Coder Social home page Coder Social logo

cyberzhg / keras-lookahead Goto Github PK

View Code? Open in Web Editor NEW
50.0 7.0 10.0 32 KB

Lookahead mechanism for optimizers in Keras.

Home Page: https://pypi.org/project/keras-lookahead/

License: MIT License

Python 98.41% Shell 1.59%
keras optimizers lookahead

keras-lookahead's Introduction

keras-lookahead's People

Contributors

cyberzhg avatar romainbrault avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

keras-lookahead's Issues

AttributeError: 'ReplicatedVariable' object has no attribute 'eval'

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

  • The version I used is: <tensorflow 1.13.1>

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])

Saving & loading optimizer state

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.

Meaning of "TF_KERAS"?

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

Extension to Tensorflow Optimizers

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!

Push 0.6.0 on PyPi

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.