(self)
| 53 | ) |
| 54 | |
| 55 | def test_eager(self): |
| 56 | def mock_time(): |
| 57 | mock_time.time += 1 |
| 58 | return mock_time.time |
| 59 | |
| 60 | mock_time.time = 1556227801.875 |
| 61 | initial_time = mock_time.time |
| 62 | with mock.patch("time.time", mock_time): |
| 63 | self._initialize_model(writer=self.logdir) |
| 64 | self.model.fit( |
| 65 | x=tf.constant([(1,)]), |
| 66 | y=tf.constant([(2,)]), |
| 67 | callbacks=[self.callback], |
| 68 | ) |
| 69 | final_time = mock_time.time |
| 70 | |
| 71 | files = os.listdir(self.logdir) |
| 72 | self.assertEqual(len(files), 1, files) |
| 73 | events_file = os.path.join(self.logdir, files[0]) |
| 74 | plugin_data = [] |
| 75 | for event in tf.compat.v1.train.summary_iterator(events_file): |
| 76 | if event.WhichOneof("what") != "summary": |
| 77 | continue |
| 78 | self.assertEqual(len(event.summary.value), 1, event.summary.value) |
| 79 | value = event.summary.value[0] |
| 80 | self.assertEqual( |
| 81 | value.metadata.plugin_data.plugin_name, |
| 82 | metadata.PLUGIN_NAME, |
| 83 | ) |
| 84 | plugin_data.append(value.metadata.plugin_data.content) |
| 85 | |
| 86 | self.assertEqual(len(plugin_data), 2, plugin_data) |
| 87 | (start_plugin_data, end_plugin_data) = plugin_data |
| 88 | start_pb = metadata.parse_session_start_info_plugin_data( |
| 89 | start_plugin_data |
| 90 | ) |
| 91 | end_pb = metadata.parse_session_end_info_plugin_data(end_plugin_data) |
| 92 | |
| 93 | # We're not the only callers of `time.time`; Keras calls it |
| 94 | # internally an unspecified number of times, so we're not guaranteed |
| 95 | # to know the exact values. Instead, we perform relative checks... |
| 96 | self.assertGreater(start_pb.start_time_secs, initial_time) |
| 97 | self.assertLess(start_pb.start_time_secs, end_pb.end_time_secs) |
| 98 | self.assertLessEqual(start_pb.start_time_secs, final_time) |
| 99 | # ...and then stub out the times for proto equality checks below. |
| 100 | start_pb.start_time_secs = 1234.5 |
| 101 | end_pb.end_time_secs = 6789.0 |
| 102 | |
| 103 | expected_start_pb = plugin_data_pb2.SessionStartInfo() |
| 104 | text_format.Parse( |
| 105 | """ |
| 106 | start_time_secs: 1234.5 |
| 107 | group_name: "my_trial" |
| 108 | hparams { |
| 109 | key: "optimizer" |
| 110 | value { |
| 111 | string_value: "adam" |
| 112 | } |
nothing calls this directly
no test coverage detected