当前位置: 首页>>代码示例>>Python>>正文


Python summary_ops_v2.create_file_writer_v2函数代码示例

本文整理汇总了Python中tensorflow.python.ops.summary_ops_v2.create_file_writer_v2函数的典型用法代码示例。如果您正苦于以下问题:Python create_file_writer_v2函数的具体用法?Python create_file_writer_v2怎么用?Python create_file_writer_v2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了create_file_writer_v2函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testNoSharing

  def testNoSharing(self):
    # Two writers with the same logdir should not share state.
    logdir = self.get_temp_dir()
    with context.eager_mode():
      writer1 = summary_ops.create_file_writer_v2(logdir)
      with writer1.as_default():
        summary_ops.write('tag', 1, step=1)
      event_files = gfile.Glob(os.path.join(logdir, '*'))
      self.assertEqual(1, len(event_files))
      file1 = event_files[0]

      writer2 = summary_ops.create_file_writer_v2(logdir)
      with writer2.as_default():
        summary_ops.write('tag', 1, step=2)
      event_files = gfile.Glob(os.path.join(logdir, '*'))
      self.assertEqual(2, len(event_files))
      event_files.remove(file1)
      file2 = event_files[0]

      # Extra writes to ensure interleaved usage works.
      with writer1.as_default():
        summary_ops.write('tag', 1, step=1)
      with writer2.as_default():
        summary_ops.write('tag', 1, step=2)

    events = iter(events_from_file(file1))
    self.assertEqual('brain.Event:2', next(events).file_version)
    self.assertEqual(1, next(events).step)
    self.assertEqual(1, next(events).step)
    self.assertRaises(StopIteration, lambda: next(events))
    events = iter(events_from_file(file2))
    self.assertEqual('brain.Event:2', next(events).file_version)
    self.assertEqual(2, next(events).step)
    self.assertEqual(2, next(events).step)
    self.assertRaises(StopIteration, lambda: next(events))
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:35,代码来源:summary_ops_test.py

示例2: testCreate_graphTensorArgument_raisesError

 def testCreate_graphTensorArgument_raisesError(self):
   logdir = self.get_temp_dir()
   with context.graph_mode():
     logdir_tensor = constant_op.constant(logdir)
   with context.eager_mode():
     with self.assertRaisesRegex(
         ValueError, 'Invalid graph Tensor argument.*logdir'):
       summary_ops.create_file_writer_v2(logdir_tensor)
   self.assertEmpty(gfile.Glob(os.path.join(logdir, '*')))
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:9,代码来源:summary_ops_test.py

示例3: testCreate_immediateSetAsDefault_retainsReference

 def testCreate_immediateSetAsDefault_retainsReference(self):
   logdir = self.get_temp_dir()
   try:
     with context.eager_mode():
       summary_ops.create_file_writer_v2(logdir).set_as_default()
       summary_ops.flush()
   finally:
     # Ensure we clean up no matter how the test executes.
     context.context().summary_writer_resource = None
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:9,代码来源:summary_ops_test.py

示例4: testAllV2SummaryOps

 def testAllV2SummaryOps(self):
   logdir = self.get_temp_dir()
   def define_ops():
     result = []
     # TF 2.0 summary ops
     result.append(summary_ops.write('write', 1, step=0))
     result.append(summary_ops.write_raw_pb(b'', step=0, name='raw_pb'))
     # TF 1.x tf.contrib.summary ops
     result.append(summary_ops.generic('tensor', 1, step=1))
     result.append(summary_ops.scalar('scalar', 2.0, step=1))
     result.append(summary_ops.histogram('histogram', [1.0], step=1))
     result.append(summary_ops.image('image', [[[[1.0]]]], step=1))
     result.append(summary_ops.audio('audio', [[1.0]], 1.0, 1, step=1))
     return result
   with context.graph_mode():
     ops_without_writer = define_ops()
     with summary_ops.create_file_writer_v2(logdir).as_default():
       with summary_ops.record_if(True):
         ops_recording_on = define_ops()
       with summary_ops.record_if(False):
         ops_recording_off = define_ops()
     # We should be collecting all ops defined with a default writer present,
     # regardless of whether recording was set on or off, but not those defined
     # without a writer at all.
     del ops_without_writer
     expected_ops = ops_recording_on + ops_recording_off
     self.assertCountEqual(expected_ops, summary_ops.all_v2_summary_ops())
开发者ID:aritratony,项目名称:tensorflow,代码行数:27,代码来源:summary_ops_test.py

示例5: testWriteRawPb_invalidValue

 def testWriteRawPb_invalidValue(self):
   logdir = self.get_temp_dir()
   with context.eager_mode():
     with summary_ops.create_file_writer_v2(logdir).as_default():
       with self.assertRaisesRegex(
           errors.DataLossError,
           'Bad tf.compat.v1.Summary binary proto tensor string'):
         summary_ops.write_raw_pb('notaproto', step=12)
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:8,代码来源:summary_ops_test.py

示例6: testWrite_stringTensor

 def testWrite_stringTensor(self):
   logdir = self.get_temp_dir()
   with context.eager_mode():
     with summary_ops.create_file_writer_v2(logdir).as_default():
       summary_ops.write('tag', [b'foo', b'bar'], step=12)
   events = events_from_logdir(logdir)
   value = events[1].summary.value[0]
   self.assertAllEqual([b'foo', b'bar'], to_numpy(value))
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:8,代码来源:summary_ops_test.py

示例7: testWrite_ndarray

 def testWrite_ndarray(self):
   logdir = self.get_temp_dir()
   with context.eager_mode():
     with summary_ops.create_file_writer_v2(logdir).as_default():
       summary_ops.write('tag', [[1, 2], [3, 4]], step=12)
   events = events_from_logdir(logdir)
   value = events[1].summary.value[0]
   self.assertAllEqual([[1, 2], [3, 4]], to_numpy(value))
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:8,代码来源:summary_ops_test.py

示例8: testWrite_tensor

 def testWrite_tensor(self):
   logdir = self.get_temp_dir()
   with context.eager_mode():
     t = constant_op.constant([[1, 2], [3, 4]])
     with summary_ops.create_file_writer_v2(logdir).as_default():
       summary_ops.write('tag', t, step=12)
     expected = t.numpy()
   events = events_from_logdir(logdir)
   value = events[1].summary.value[0]
   self.assertAllEqual(expected, to_numpy(value))
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:10,代码来源:summary_ops_test.py

示例9: testWrite

 def testWrite(self):
   logdir = self.get_temp_dir()
   with context.eager_mode():
     with summary_ops.create_file_writer_v2(logdir).as_default():
       output = summary_ops.write('tag', 42, step=12)
       self.assertTrue(output.numpy())
   events = events_from_logdir(logdir)
   self.assertEqual(2, len(events))
   self.assertEqual(12, events[1].step)
   value = events[1].summary.value[0]
   self.assertEqual('tag', value.tag)
   self.assertEqual(42, to_numpy(value))
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:12,代码来源:summary_ops_test.py

示例10: testWriteRawPb

 def testWriteRawPb(self):
   logdir = self.get_temp_dir()
   pb = summary_pb2.Summary()
   pb.value.add().simple_value = 42.0
   with context.eager_mode():
     with summary_ops.create_file_writer_v2(logdir).as_default():
       output = summary_ops.write_raw_pb(pb.SerializeToString(), step=12)
       self.assertTrue(output.numpy())
   events = events_from_logdir(logdir)
   self.assertEqual(2, len(events))
   self.assertEqual(12, events[1].step)
   self.assertProtoEquals(pb, events[1].summary)
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:12,代码来源:summary_ops_test.py

示例11: testMaxQueue

 def testMaxQueue(self):
   logdir = self.get_temp_dir()
   with context.eager_mode():
     with summary_ops.create_file_writer_v2(
         logdir, max_queue=1, flush_millis=999999).as_default():
       get_total = lambda: len(events_from_logdir(logdir))
       # Note: First tf.Event is always file_version.
       self.assertEqual(1, get_total())
       summary_ops.write('tag', 1, step=0)
       self.assertEqual(1, get_total())
       # Should flush after second summary since max_queue = 1
       summary_ops.write('tag', 1, step=0)
       self.assertEqual(3, get_total())
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:13,代码来源:summary_ops_test.py

示例12: testWrite_recordIf_constant

 def testWrite_recordIf_constant(self):
   logdir = self.get_temp_dir()
   with context.eager_mode():
     with summary_ops.create_file_writer_v2(logdir).as_default():
       self.assertTrue(summary_ops.write('default', 1, step=0))
       with summary_ops.record_if(True):
         self.assertTrue(summary_ops.write('set_on', 1, step=0))
       with summary_ops.record_if(False):
         self.assertFalse(summary_ops.write('set_off', 1, step=0))
   events = events_from_logdir(logdir)
   self.assertEqual(3, len(events))
   self.assertEqual('default', events[1].summary.value[0].tag)
   self.assertEqual('set_on', events[2].summary.value[0].tag)
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:13,代码来源:summary_ops_test.py

示例13: testClose_preventsLaterUse

 def testClose_preventsLaterUse(self):
   logdir = self.get_temp_dir()
   with context.eager_mode():
     writer = summary_ops.create_file_writer_v2(logdir)
     writer.close()
     writer.close()  # redundant close() is a no-op
     writer.flush()  # redundant flush() is a no-op
     with self.assertRaisesRegex(RuntimeError, 'already closed'):
       writer.init()
     with self.assertRaisesRegex(RuntimeError, 'already closed'):
       with writer.as_default():
         self.fail('should not get here')
     with self.assertRaisesRegex(RuntimeError, 'already closed'):
       writer.set_as_default()
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:14,代码来源:summary_ops_test.py

示例14: testWrite_metadata

 def testWrite_metadata(self):
   logdir = self.get_temp_dir()
   metadata = summary_pb2.SummaryMetadata()
   metadata.plugin_data.plugin_name = 'foo'
   with context.eager_mode():
     with summary_ops.create_file_writer_v2(logdir).as_default():
       summary_ops.write('obj', 0, 0, metadata=metadata)
       summary_ops.write('bytes', 0, 0, metadata=metadata.SerializeToString())
       m = constant_op.constant(metadata.SerializeToString())
       summary_ops.write('string_tensor', 0, 0, metadata=m)
   events = events_from_logdir(logdir)
   self.assertEqual(4, len(events))
   self.assertEqual(metadata, events[1].summary.value[0].metadata)
   self.assertEqual(metadata, events[2].summary.value[0].metadata)
   self.assertEqual(metadata, events[3].summary.value[0].metadata)
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:15,代码来源:summary_ops_test.py

示例15: testCreate_withInitAndClose

 def testCreate_withInitAndClose(self):
   logdir = self.get_temp_dir()
   with context.eager_mode():
     writer = summary_ops.create_file_writer_v2(
         logdir, max_queue=1000, flush_millis=1000000)
     get_total = lambda: len(events_from_logdir(logdir))
     self.assertEqual(1, get_total())  # file_version Event
     # Calling init() again while writer is open has no effect
     writer.init()
     self.assertEqual(1, get_total())
     with writer.as_default():
       summary_ops.write('tag', 1, step=0)
       self.assertEqual(1, get_total())
       # Calling .close() should do an implicit flush
       writer.close()
       self.assertEqual(2, get_total())
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:16,代码来源:summary_ops_test.py


注:本文中的tensorflow.python.ops.summary_ops_v2.create_file_writer_v2函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。