Git Product home page Git Product logo

Comments (9)

cancan101 avatar cancan101 commented on August 21, 2024

Additionally, the current EarlyStopping copies the weights from the best best seen back into the network if patience is exceeded. I do not think it copies these weights if max_epochs is exceeded but I think that would be the correct action to perform.

from nolearn.

felixlaumon avatar felixlaumon commented on August 21, 2024

I think It will be a good idea to add a threshold too, so it won't get stuck on minor improvement.

from nolearn.

cancan101 avatar cancan101 commented on August 21, 2024

We also want to make sure to deal with the issues I outlined in #32.

from nolearn.

cancan101 avatar cancan101 commented on August 21, 2024

This is what I am using now:

class EarlyStopping(object):
    def __init__(self, patience=100):
        self.patience = patience
        self.best_valid = np.inf
        self.best_valid_epoch = 0
        self.best_weights = None

    def __call__(self, nn, train_history):
        current_valid = train_history[-1]['valid_loss']
        current_epoch = train_history[-1]['epoch']
        if current_valid < self.best_valid:
            self.best_valid = current_valid
            self.best_valid_epoch = current_epoch
            self.best_weights = nn.get_all_params_values()  # updated
        elif self.best_valid_epoch + self.patience < current_epoch:
            if nn.verbose:
                print("Early stopping.")
                print("Best valid loss was {:.6f} at epoch {}.".format(
                    self.best_valid, self.best_valid_epoch))
            nn.load_weights_from(self.best_weights)
            if nn.verbose:
                print("Weights set.")
            raise StopIteration()

    def load_best_weights(self, nn, train_history):
        nn.load_weights_from(self.best_weights)

from nolearn.

pengpaiSH avatar pengpaiSH commented on August 21, 2024

@cancan101, you are definitely an expert in this field. Would you mind taking a minute look issue 46: #46 ? Thank you.

from nolearn.

ternaus avatar ternaus commented on August 21, 2024

I am getting an error:

Loading weights from a list of parameter values is no longer supported. Please send me something like the return value of 'net.get_all_param_values()' instead.

from nolearn.

dnouri avatar dnouri commented on August 21, 2024

@ternaus Change this line:

self.best_weights = [w.get_value() for w in nn.get_all_params()]

to

self.best_weights = nn.get_all_params_values()

from nolearn.

cancan101 avatar cancan101 commented on August 21, 2024

Related to #155.

from nolearn.

dnouri avatar dnouri commented on August 21, 2024

EarlyStopping is part of nolearn-utils. Suggest you use the implementation from there.

from nolearn.

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.