| 1175 | """ |
| 1176 | |
| 1177 | def __init__(self, |
| 1178 | monitor='val_loss', |
| 1179 | min_delta=0, |
| 1180 | patience=0, |
| 1181 | verbose=0, |
| 1182 | mode='auto', |
| 1183 | baseline=None, |
| 1184 | restore_best_weights=False): |
| 1185 | super(EarlyStopping, self).__init__() |
| 1186 | |
| 1187 | self.monitor = monitor |
| 1188 | self.patience = patience |
| 1189 | self.verbose = verbose |
| 1190 | self.baseline = baseline |
| 1191 | self.min_delta = abs(min_delta) |
| 1192 | self.wait = 0 |
| 1193 | self.stopped_epoch = 0 |
| 1194 | self.restore_best_weights = restore_best_weights |
| 1195 | self.best_weights = None |
| 1196 | |
| 1197 | if mode not in ['auto', 'min', 'max']: |
| 1198 | logging.warning('EarlyStopping mode %s is unknown, ' |
| 1199 | 'fallback to auto mode.', mode) |
| 1200 | mode = 'auto' |
| 1201 | |
| 1202 | if mode == 'min': |
| 1203 | self.monitor_op = np.less |
| 1204 | elif mode == 'max': |
| 1205 | self.monitor_op = np.greater |
| 1206 | else: |
| 1207 | if 'acc' in self.monitor: |
| 1208 | self.monitor_op = np.greater |
| 1209 | else: |
| 1210 | self.monitor_op = np.less |
| 1211 | |
| 1212 | if self.monitor_op == np.greater: |
| 1213 | self.min_delta *= 1 |
| 1214 | else: |
| 1215 | self.min_delta *= -1 |
| 1216 | |
| 1217 | def on_train_begin(self, logs=None): |
| 1218 | # Allow instances to be re-used |