| 1882 | self._reset() |
| 1883 | |
| 1884 | def on_epoch_end(self, epoch, logs=None): |
| 1885 | logs = logs or {} |
| 1886 | logs['lr'] = K.get_value(self.model.optimizer.lr) |
| 1887 | current = logs.get(self.monitor) |
| 1888 | if current is None: |
| 1889 | logging.warning('Reduce LR on plateau conditioned on metric `%s` ' |
| 1890 | 'which is not available. Available metrics are: %s', |
| 1891 | self.monitor, ','.join(list(logs.keys()))) |
| 1892 | |
| 1893 | else: |
| 1894 | if self.in_cooldown(): |
| 1895 | self.cooldown_counter -= 1 |
| 1896 | self.wait = 0 |
| 1897 | |
| 1898 | if self.monitor_op(current, self.best): |
| 1899 | self.best = current |
| 1900 | self.wait = 0 |
| 1901 | elif not self.in_cooldown(): |
| 1902 | self.wait += 1 |
| 1903 | if self.wait >= self.patience: |
| 1904 | old_lr = float(K.get_value(self.model.optimizer.lr)) |
| 1905 | if old_lr > self.min_lr: |
| 1906 | new_lr = old_lr * self.factor |
| 1907 | new_lr = max(new_lr, self.min_lr) |
| 1908 | K.set_value(self.model.optimizer.lr, new_lr) |
| 1909 | if self.verbose > 0: |
| 1910 | print('\nEpoch %05d: ReduceLROnPlateau reducing learning ' |
| 1911 | 'rate to %s.' % (epoch + 1, new_lr)) |
| 1912 | self.cooldown_counter = self.cooldown |
| 1913 | self.wait = 0 |
| 1914 | |
| 1915 | def in_cooldown(self): |
| 1916 | return self.cooldown_counter > 0 |