def test_summary_args(self): summary = _ScopedSummaryV2(self.test_subdirectory) summary.scalar("scalar", 1, "family") summary.image("image", 1, 3, "family") summary.histogram("histogram", 1, "family") summary.audio("audio", 1, 3, 3, "family") self.assertLen(summary.summary_tuples(), 4)
def test_summary_kwargs(self): summary = _ScopedSummaryV2(self.test_subdirectory) summary.scalar(name="scalar", tensor=1, family="family") summary.image(name="image", tensor=1, max_outputs=3, family="family") summary.histogram(name="histogram", values=1, family="family") summary.audio( name="audio", tensor=1, sample_rate=3, max_outputs=3, family="family") self.assertLen(summary.summary_tuples(), 4)
def test_summarizing_variable(self, scope): scoped_summary = _ScopedSummaryV2(self.test_subdirectory, scope=scope) c = tf.constant(42.0) v = tf.Variable(c) scoped_summary.scalar("summary", v) self.write_summaries(scoped_summary) events = self.read_single_event_from_eventfile(scoped_summary) values = events[0].summary.value self.assertLen(values, 1) value = values[0] self.assertEqual(value.tag, "summary") self.assertEqual(simple_value(value), 42.0)
def test_summary_name_conversion(self, scope): scoped_summary = _ScopedSummaryV2(self.test_subdirectory, scope=scope) c = tf.constant(3) scoped_summary.scalar("name with spaces", c) scoped_summary.scalar("name with many $#illegal^: characters!", c) scoped_summary.scalar("/name/with/leading/slash", c) self.write_summaries(scoped_summary) events = self.read_single_event_from_eventfile(scoped_summary) self.assertLen(events, 3) tags = [event.summary.value[0].tag for event in events] # Characters that were illegal in TF 1 are now valid in TF 2. self.assertIn("name with spaces", tags) self.assertIn("name with many $#illegal^: characters!", tags) self.assertIn("name/with/leading/slash", tags)
def test_histogram_summary(self, scope, skip_summary=False): with context.graph_mode(): scoped_summary = _ScopedSummaryV2( self.test_subdirectory, scope=scope, skip_summary=skip_summary) i = tf.ones((5, 4, 4, 3)) with tf.name_scope("outer"): scoped_summary.histogram("inner", i) self.write_summaries(scoped_summary) if skip_summary: return events = self.read_single_event_from_eventfile(scoped_summary) values = events[0].summary.value self.assertLen(values, 1) self.assertEqual("outer/inner", values[0].tag)
def test_scalar_summary(self, scope, skip_summary=False): with context.graph_mode(): scoped_summary = _ScopedSummaryV2( self.test_subdirectory, scope=scope, skip_summary=skip_summary) i = tf.constant(3) with tf.name_scope("outer"): scoped_summary.scalar("inner", i) self.write_summaries(scoped_summary) if skip_summary: return events = self.read_single_event_from_eventfile(scoped_summary) values = events[0].summary.value self.assertLen(values, 1) self.assertEqual(values[0].tag, "outer/inner") self.assertEqual(simple_value(values[0]), 3.0)
def test_current_scope(self, scope): with context.graph_mode(): scoped_summary = _ScopedSummaryV2(self.test_subdirectory, scope=scope) i = tf.constant(3) with tf.compat.v1.variable_scope("outer1"): with tf.compat.v1.variable_scope("outer2"): with scoped_summary.current_scope(): with tf.compat.v1.variable_scope("inner1"): scoped_summary.scalar("inner2/a/b/c", i) self.write_summaries(scoped_summary) events = self.read_single_event_from_eventfile(scoped_summary) values = events[0].summary.value self.assertLen(values, 1) self.assertEqual(values[0].tag, "inner1/inner2/a/b/c") self.assertEqual(simple_value(values[0]), 3.0)
def test_audio_summary(self, scope, skip_summary=False): with context.graph_mode(): scoped_summary = _ScopedSummaryV2( self.test_subdirectory, scope=scope, skip_summary=skip_summary) i = tf.ones((5, 3, 4)) with tf.name_scope("outer"): scoped_summary.audio("inner", i, sample_rate=2, max_outputs=3) self.write_summaries(scoped_summary) if skip_summary: return events = self.read_single_event_from_eventfile(scoped_summary) values = events[0].summary.value self.assertLen(values, 1) self.assertLen(values, 1) self.assertEqual(values[0].tag, "outer/inner")
def test_scope(self, scope): scoped_summary = _ScopedSummaryV2(self.test_subdirectory, scope=scope) self.assertEqual(scope, scoped_summary.scope)