Giter Site home page Giter Site logo

Rectified Adam about ktrain HOT 5 CLOSED

amaiya avatar amaiya commented on June 15, 2024
Rectified Adam

from ktrain.

Comments (5)

amaiya avatar amaiya commented on June 15, 2024

Since ktrain currently allows you to use any "Adam-like" optimizer, this is already supported. Once you load a model (either by building it yourself or loading one of ktrain's pre-canned model), simply call model.compile and supply RectifiedAdam as the optimizer. Since RectifiedAdam uses the same hyperparameters as Adam (beta_1 and beta_2), the 1cycle and triangular learning rate policies with cyclical momentum should still work correctly.

For an example, see this Google Colab notebook that uses ktrain with Recified Adam.

from ktrain.

xaerincl avatar xaerincl commented on June 15, 2024

Does the model have to be a sequential one like in your example?

Im using a pre trained mobilenetv2 from keras and training it with radam and autofit with no problem but when i do this:

loss, acc = learner.model.evaluate_generator(learner.val_data)
i get this error:
ValueError: steps=None is only valid for a generator based on the keras.utils.Sequence class. Please specify steps or use the keras.utils.Sequence class.

So what im doing is using some values for steps(like 1 or 10) but they get differents results for final loss and final accuracy.

from ktrain.

amaiya avatar amaiya commented on June 15, 2024

No, the model does not have to be Sequential. It can be any Keras model.

There's a strange issue with Keras where DirectoryFrameIterator is considered an instance of Sequence in some environments (e.g., Python on Ubuntu 18.04), but not in other environments (conda Python on Google Colab, Kaggle). As a result, the steps argument to evaluate_generator and predict_generator is required on Google Colab and Kaggle, but not in, say, your typical local Ubuntu 18.04 installation.

The following workaround should get learner.model.evaluate_generator to work correctly for you (assuming your validation data is in the form of a DirectoryIterator):

learner.model.evaluate_generator(learner.val_data, steps=len(learner.val_data))

The value len(learner.val_data) should return the number of steps or batches in the validation set. I tested the above on Google Colab and it works.

As an aside, I would also recommend upgrading ktrain to the latest version to ensure latest bug fixes are obtained.

from ktrain.

xaerincl avatar xaerincl commented on June 15, 2024

Thanks! that works

Last question: Any plan to add discriminative learning rates similar to the slice function of fast ai?

from ktrain.

amaiya avatar amaiya commented on June 15, 2024

Great. Adding discriminative learning rates to ktrain is under consideration. But, it's currently at a lower priority compared to other planned features, since the significance of the impact is unclear to me right now. I know that with pretrained BERT models, at least, discriminative learning rates seem to have minimal impact.

from ktrain.

Related Issues (20)

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.