示例#1
0
 def test_image_summary_with_family(self, scope):
   scoped_summary = _TPUScopedSummary(self.test_subdirectory, scope=scope)
   i = tf.ones((5, 2, 3, 1))
   with tf.name_scope("outer"):
     scoped_summary.image("inner", i, max_outputs=3, family="family")
   self.write_summaries(scoped_summary)
   events = self.read_single_event_from_eventfile(scoped_summary)
   values = events[0].summary.value
   self.assertLen(values, 3)
   tags = sorted(v.tag for v in values)
   expected = sorted(
       "family/outer/family/inner/image/{}".format(i) for i in range(3))
   self.assertEqual(tags, expected)
 def test_summary_name_conversion(self, scope):
   scoped_summary = _TPUScopedSummary(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]
   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):
   scoped_summary = _TPUScopedSummary(
       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(values[0].tag, "outer/inner")
示例#4
0
 def test_current_scope(self, scope):
   scoped_summary = _TPUScopedSummary(self.test_subdirectory, scope=scope)
   i = tf.constant(3)
   with tf.variable_scope("outer1"):
     with tf.variable_scope("outer2"):
       with scoped_summary.current_scope():
         with tf.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(values[0].simple_value, 3.0)
示例#5
0
 def test_scalar_summary(self, scope, skip_summary=False):
   scoped_summary = _TPUScopedSummary(
       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(values[0].simple_value, 3.0)
示例#6
0
 def test_histogram_summary_with_family(self, scope):
     scoped_summary = _TPUScopedSummary(self.test_subdirectory,
                                        scope=scope,
                                        global_step=10)
     with self.test_session() as s:
         i = tf.ones((5, 4, 4, 3))
         with tf.name_scope("outer"):
             scoped_summary.histogram("inner", i, family="family")
         s.run(tf.contrib.summary.summary_writer_initializer_op())
         s.run(scoped_summary.merge_all())
         s.run(scoped_summary.flush())
     events = self.read_single_event_from_eventfile(scoped_summary)
     values = events[0].summary.value
     self.assertLen(values, 1)
     self.assertEqual(values[0].tag, "family/outer/family/inner")
示例#7
0
 def test_audio_summary(self, scope, skip_summary=False):
   scoped_summary = _TPUScopedSummary(
       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, 0.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, 3)
   tags = sorted(v.tag for v in values)
   expected = sorted("outer/inner/audio/{}".format(i) for i in range(3))
   self.assertEqual(tags, expected)
示例#8
0
 def test_summary_name_conversion(self, scope):
     scoped_summary = _TPUScopedSummary(self.test_subdirectory,
                                        scope=scope,
                                        global_step=10)
     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)
     with self.test_session() as sess:
         sess.run(tf.contrib.summary.summary_writer_initializer_op())
         sess.run(scoped_summary.merge_all())
         sess.run(scoped_summary.flush())
     events = self.read_single_event_from_eventfile(scoped_summary)
     self.assertLen(events, 3)
     tags = [event.summary.value[0].tag for event in events]
     self.assertIn("name_with_spaces", tags)
     self.assertIn("name_with_many___illegal___characters_", tags)
     self.assertIn("name/with/leading/slash", tags)
示例#9
0
 def test_current_scope(self, scope):
     scoped_summary = _TPUScopedSummary(self.test_subdirectory,
                                        scope=scope,
                                        global_step=10)
     i = tf.constant(3)
     with tf.variable_scope("outer1"):
         with tf.variable_scope("outer2"):
             with scoped_summary.current_scope():
                 with tf.variable_scope("inner1"):
                     scoped_summary.scalar("inner2/a/b/c", i)
     with self.test_session() as s:
         s.run(tf.contrib.summary.summary_writer_initializer_op())
         s.run(scoped_summary.merge_all())
         s.run(scoped_summary.flush())
     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(values[0].simple_value, 3.0)
示例#10
0
 def test_summarizing_variable(self, scope):
     scoped_summary = _TPUScopedSummary(self.test_subdirectory,
                                        scope=scope,
                                        global_step=10)
     with self.test_session() as s:
         c = tf.constant(42.0)
         v = tf.Variable(c)
         scoped_summary.scalar("summary", v)
         init = tf.global_variables_initializer()
         s.run(init)
         s.run(tf.contrib.summary.summary_writer_initializer_op())
         s.run(scoped_summary.merge_all())
         s.run(scoped_summary.flush())
     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(value.simple_value, 42.0)
示例#11
0
 def test_scalar_summary(self, scope, skip_summary=False):
     scoped_summary = _TPUScopedSummary(self.test_subdirectory,
                                        scope=scope,
                                        skip_summary=skip_summary,
                                        global_step=10)
     with self.test_session() as s:
         i = tf.constant(3)
         with tf.name_scope("outer"):
             scoped_summary.scalar("inner", i)
         s.run(tf.contrib.summary.summary_writer_initializer_op())
         s.run(scoped_summary.merge_all())
         s.run(scoped_summary.flush())
     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(values[0].simple_value, 3.0)
示例#12
0
  def test_scalar_summary_with_family(self, scope):
    scoped_summary = _TPUScopedSummary(self.test_subdirectory, scope=scope)
    i = tf.constant(7)
    with tf.name_scope("outer"):
      scoped_summary.scalar("inner", i, family="family")
      scoped_summary.scalar("inner", i, family="family")
    self.write_summaries(scoped_summary)
    events = self.read_single_event_from_eventfile(scoped_summary)
    self.assertLen(events[0].summary.value, 1)
    self.assertLen(events[1].summary.value, 1)

    self.assertEqual(
        {
            "family/outer/family/inner": 7.0,
            "family/outer/family/inner_1": 7.0
        }, {
            event.summary.value[0].tag: event.summary.value[0].simple_value
            for event in events
        })
示例#13
0
 def test_audio_summary(self, scope, skip_summary=False):
     scoped_summary = _TPUScopedSummary(self.test_subdirectory,
                                        scope=scope,
                                        skip_summary=skip_summary,
                                        global_step=10)
     with self.test_session() as s:
         i = tf.ones((5, 3, 4))
         with tf.name_scope("outer"):
             scoped_summary.audio("inner", i, 0.2, max_outputs=3)
         s.run(tf.contrib.summary.summary_writer_initializer_op())
         s.run(scoped_summary.merge_all())
         s.run(scoped_summary.flush())
     if skip_summary:
         return
     events = self.read_single_event_from_eventfile(scoped_summary)
     values = events[0].summary.value
     self.assertLen(values, 3)
     tags = sorted(v.tag for v in values)
     expected = sorted("outer/inner/audio/{}".format(i) for i in range(3))
     self.assertEqual(tags, expected)
示例#14
0
 def test_image_summary_with_family(self, scope):
     scoped_summary = _TPUScopedSummary(self.test_subdirectory,
                                        scope=scope,
                                        global_step=10)
     with self.test_session() as s:
         i = tf.ones((5, 2, 3, 1))
         with tf.name_scope("outer"):
             scoped_summary.image("inner",
                                  i,
                                  max_outputs=3,
                                  family="family")
         s.run(tf.contrib.summary.summary_writer_initializer_op())
         s.run(scoped_summary.merge_all())
         s.run(scoped_summary.flush())
     events = self.read_single_event_from_eventfile(scoped_summary)
     values = events[0].summary.value
     self.assertLen(values, 3)
     tags = sorted(v.tag for v in values)
     expected = sorted("family/outer/family/inner/image/{}".format(i)
                       for i in range(3))
     self.assertEqual(tags, expected)
示例#15
0
    def test_scalar_summary_with_family(self, scope):
        scoped_summary = _TPUScopedSummary(self.test_subdirectory,
                                           scope=scope,
                                           global_step=10)
        with self.test_session() as s:
            i = tf.constant(7)
            with tf.name_scope("outer"):
                scoped_summary.scalar("inner", i, family="family")
                scoped_summary.scalar("inner", i, family="family")
            s.run(tf.contrib.summary.summary_writer_initializer_op())
            s.run(scoped_summary.merge_all())
            s.run(scoped_summary.flush())
        events = self.read_single_event_from_eventfile(scoped_summary)
        self.assertLen(events[0].summary.value, 1)
        self.assertLen(events[1].summary.value, 1)

        self.assertEqual(
            {
                "family/outer/family/inner": 7.0,
                "family/outer/family/inner_1": 7.0
            }, {
                event.summary.value[0].tag: event.summary.value[0].simple_value
                for event in events
            })
示例#16
0
 def test_scope(self, scope):
     scoped_summary = _TPUScopedSummary(self.test_subdirectory,
                                        scope=scope,
                                        global_step=10)
     self.assertEqual(scope, scoped_summary.scope)