| 828 | """ |
| 829 | |
| 830 | def __init__(self, |
| 831 | filepath, |
| 832 | monitor='val_loss', |
| 833 | verbose=0, |
| 834 | save_best_only=False, |
| 835 | save_weights_only=False, |
| 836 | mode='auto', |
| 837 | save_freq='epoch', |
| 838 | **kwargs): |
| 839 | super(ModelCheckpoint, self).__init__() |
| 840 | self.monitor = monitor |
| 841 | self.verbose = verbose |
| 842 | self.filepath = filepath |
| 843 | self.save_best_only = save_best_only |
| 844 | self.save_weights_only = save_weights_only |
| 845 | self.save_freq = save_freq |
| 846 | self.epochs_since_last_save = 0 |
| 847 | self._samples_seen_since_last_saving = 0 |
| 848 | |
| 849 | # Deprecated field `load_weights_on_restart` is for loading the checkpoint |
| 850 | # file from `filepath` at the start of `model.fit()` |
| 851 | # TODO(rchao): Remove the arg during next breaking release. |
| 852 | if 'load_weights_on_restart' in kwargs: |
| 853 | self.load_weights_on_restart = kwargs['load_weights_on_restart'] |
| 854 | logging.warning('`load_weights_on_restart` argument is deprecated. ' |
| 855 | 'Please use `model.load_weights()` for loading weights ' |
| 856 | 'before the start of `model.fit()`.') |
| 857 | else: |
| 858 | self.load_weights_on_restart = False |
| 859 | |
| 860 | # Deprecated field `period` is for the number of epochs between which |
| 861 | # the model is saved. |
| 862 | if 'period' in kwargs: |
| 863 | self.period = kwargs['period'] |
| 864 | logging.warning('`period` argument is deprecated. Please use `save_freq` ' |
| 865 | 'to specify the frequency in number of samples seen.') |
| 866 | else: |
| 867 | self.period = 1 |
| 868 | |
| 869 | if mode not in ['auto', 'min', 'max']: |
| 870 | logging.warning('ModelCheckpoint mode %s is unknown, ' |
| 871 | 'fallback to auto mode.', mode) |
| 872 | mode = 'auto' |
| 873 | |
| 874 | if mode == 'min': |
| 875 | self.monitor_op = np.less |
| 876 | self.best = np.Inf |
| 877 | elif mode == 'max': |
| 878 | self.monitor_op = np.greater |
| 879 | self.best = -np.Inf |
| 880 | else: |
| 881 | if 'acc' in self.monitor or self.monitor.startswith('fmeasure'): |
| 882 | self.monitor_op = np.greater |
| 883 | self.best = -np.Inf |
| 884 | else: |
| 885 | self.monitor_op = np.less |
| 886 | self.best = np.Inf |
| 887 | |