victoresque / pytorch-template

PyTorch deep learning projects made easy.
MIT License
4.7k stars 1.08k forks source link

Add early stop in base_trainer.py #32

Closed yjlolo closed 5 years ago

yjlolo commented 5 years ago

Thanks for your contribution, I have learned a lot from the template. I think it would be good to have early stop in base_trainer.py.

something like

def __init__(): 
    self.no_improve_count = 0 if self.config['trainer']['early_stop'] else None

def train()
    if self.no_improve_count:
        self.no_improve_count += 1
            if self.no_improve_count == self.early_stop:
            msg = "Metric named '{}' ".format(self.monitor)\
                        + "has not improved for {} epochs; stop training".format(self.early_stop)
            self.logger.info(msg)
            break
SunQpark commented 5 years ago

I think this is a good idea. I will try to implement this feature in my local repository, but it may take some time to do so.

SunQpark commented 5 years ago

I added this feature in PR #34. Would you test the early_stop option, @yjlolo?