Saves the model. Arguments: epoch: the epoch this iteration is in. logs: the `logs` dict passed in to `on_batch_end` or `on_epoch_end`.
(self, epoch, logs)
| 973 | self._training_state.back_up(epoch) |
| 974 | |
| 975 | def _save_model(self, epoch, logs): |
| 976 | """Saves the model. |
| 977 | |
| 978 | Arguments: |
| 979 | epoch: the epoch this iteration is in. |
| 980 | logs: the `logs` dict passed in to `on_batch_end` or `on_epoch_end`. |
| 981 | """ |
| 982 | logs = logs or {} |
| 983 | |
| 984 | if isinstance(self.save_freq, |
| 985 | int) or self.epochs_since_last_save >= self.period: |
| 986 | self.epochs_since_last_save = 0 |
| 987 | filepath = self._get_file_path(epoch, logs) |
| 988 | |
| 989 | if self.save_best_only: |
| 990 | current = logs.get(self.monitor) |
| 991 | if current is None: |
| 992 | logging.warning('Can save best model only with %s available, ' |
| 993 | 'skipping.', self.monitor) |
| 994 | else: |
| 995 | if self.monitor_op(current, self.best): |
| 996 | if self.verbose > 0: |
| 997 | print('\nEpoch %05d: %s improved from %0.5f to %0.5f,' |
| 998 | ' saving model to %s' % (epoch + 1, self.monitor, self.best, |
| 999 | current, filepath)) |
| 1000 | self.best = current |
| 1001 | if self.save_weights_only: |
| 1002 | self.model.save_weights(filepath, overwrite=True) |
| 1003 | else: |
| 1004 | self.model.save(filepath, overwrite=True) |
| 1005 | else: |
| 1006 | if self.verbose > 0: |
| 1007 | print('\nEpoch %05d: %s did not improve from %0.5f' % |
| 1008 | (epoch + 1, self.monitor, self.best)) |
| 1009 | else: |
| 1010 | if self.verbose > 0: |
| 1011 | print('\nEpoch %05d: saving model to %s' % (epoch + 1, filepath)) |
| 1012 | if self.save_weights_only: |
| 1013 | self.model.save_weights(filepath, overwrite=True) |
| 1014 | else: |
| 1015 | self.model.save(filepath, overwrite=True) |
| 1016 | |
| 1017 | self._maybe_remove_file() |
| 1018 | |
| 1019 | def _get_file_path(self, epoch, logs): |
| 1020 | """Returns the file path for checkpoint.""" |
no test coverage detected