Checks if summary ops should run next epoch, logs scalar summaries.
(self, epoch, logs=None)
| 387 | # pylint: enable=protected-access |
| 388 | |
| 389 | def on_epoch_end(self, epoch, logs=None): |
| 390 | """Checks if summary ops should run next epoch, logs scalar summaries.""" |
| 391 | |
| 392 | # don't output batch_size and |
| 393 | # batch number as TensorBoard summaries |
| 394 | logs = {('epoch_' + k): v |
| 395 | for k, v in logs.items() |
| 396 | if k not in ['batch', 'size', 'num_steps']} |
| 397 | if self.update_freq == 'epoch': |
| 398 | step = epoch |
| 399 | else: |
| 400 | step = self._samples_seen |
| 401 | self._write_custom_summaries(step, logs) |
| 402 | |
| 403 | # pop the histogram summary op after each epoch |
| 404 | if self.histogram_freq: |
| 405 | # pylint: disable=protected-access |
| 406 | if self.merged in self.model.test_function.fetches: |
| 407 | self.model.test_function.fetches.remove(self.merged) |
| 408 | if self.merged in self.model.test_function.fetch_callbacks: |
| 409 | self.model.test_function.fetch_callbacks.pop(self.merged) |
| 410 | # pylint: enable=protected-access |
| 411 | |
| 412 | if self.embeddings_data is None and self.embeddings_freq: |
| 413 | raise ValueError('To visualize embeddings, embeddings_data must ' |
| 414 | 'be provided.') |
| 415 | |
| 416 | if self.embeddings_freq and self.embeddings_data is not None: |
| 417 | if epoch % self.embeddings_freq == 0: |
| 418 | # We need a second forward-pass here because we're passing |
| 419 | # the `embeddings_data` explicitly. This design allows to pass |
| 420 | # arbitrary data as `embeddings_data` and results from the fact |
| 421 | # that we need to know the size of the `tf.Variable`s which |
| 422 | # hold the embeddings in `set_model`. At this point, however, |
| 423 | # the `validation_data` is not yet set. |
| 424 | |
| 425 | embeddings_data = self.embeddings_data |
| 426 | n_samples = embeddings_data[0].shape[0] |
| 427 | i = 0 |
| 428 | sess = K.get_session() |
| 429 | while i < n_samples: |
| 430 | step = min(self.batch_size, n_samples - i) |
| 431 | batch = slice(i, i + step) |
| 432 | |
| 433 | if isinstance(self.model.input, list): |
| 434 | feed_dict = { |
| 435 | model_input: embeddings_data[idx][batch] |
| 436 | for idx, model_input in enumerate(self.model.input) |
| 437 | } |
| 438 | else: |
| 439 | feed_dict = {self.model.input: embeddings_data[0][batch]} |
| 440 | |
| 441 | feed_dict.update({self.batch_id: i, self.step: step}) |
| 442 | |
| 443 | if not isinstance(K.learning_phase(), int): |
| 444 | feed_dict[K.learning_phase()] = False |
| 445 | |
| 446 | sess.run(self.assign_embeddings, feed_dict=feed_dict) |
nothing calls this directly
no test coverage detected