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


Python event_pb2.Event方法代码示例

本文整理汇总了Python中tensorflow.core.util.event_pb2.Event方法的典型用法代码示例。如果您正苦于以下问题:Python event_pb2.Event方法的具体用法?Python event_pb2.Event怎么用?Python event_pb2.Event使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorflow.core.util.event_pb2的用法示例。


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

示例1: setup_logger

# 需要导入模块: from tensorflow.core.util import event_pb2 [as 别名]
# 或者: from tensorflow.core.util.event_pb2 import Event [as 别名]
def setup_logger(out_dir="results", exp_name="test", output_formats=None):
    timestamp = utils.make_timestamp()
    exp_name = exp_name.replace("/", "_")  # environment names can contain /'s
    filename = "{}-{}".format(timestamp, exp_name)[0:255]  # Linux has filename limit of 255
    out_dir = osp.join(out_dir, filename)
    os.makedirs(out_dir, exist_ok=True)

    logger.configure(folder=osp.join(out_dir, "rl"), format_strs=["tensorboard", "stdout"])
    logger_instance = logger.Logger.CURRENT

    if output_formats is not None:
        logger_instance.output_formats += output_formats

    for fmt in logger_instance.output_formats:
        if isinstance(fmt, logger.TensorBoardOutputFormat):
            writer = fmt.writer
            layout = tb_layout()
            event = event_pb2.Event(summary=layout)
            writer.WriteEvent(event)
            writer.Flush()

    return out_dir, logger_instance 
开发者ID:HumanCompatibleAI,项目名称:adversarial-policies,代码行数:24,代码来源:logger.py

示例2: load_tensor_from_event_file

# 需要导入模块: from tensorflow.core.util import event_pb2 [as 别名]
# 或者: from tensorflow.core.util.event_pb2 import Event [as 别名]
def load_tensor_from_event_file(event_file_path):
  """Load a tensor from an event file.

  Assumes that the event file contains a `Event` protobuf and the `Event`
  protobuf contains a `Tensor` value.

  Args:
    event_file_path: (`str`) path to the event file.

  Returns:
    The tensor value loaded from the event file, as a `numpy.ndarray`. For
    uninitialized Tensors, returns `None`. For Tensors of data types that
    cannot be converted to `numpy.ndarray` (e.g., `tf.resource`), return
    `None`.
  """

  event = event_pb2.Event()
  with gfile.Open(event_file_path, "rb") as f:
    event.ParseFromString(f.read())
    return load_tensor_from_event(event) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:22,代码来源:debug_data.py

示例3: add_summary

# 需要导入模块: from tensorflow.core.util import event_pb2 [as 别名]
# 或者: from tensorflow.core.util.event_pb2 import Event [as 别名]
def add_summary(self, summary, global_step=None):
    """Adds a `Summary` protocol buffer to the event file.

    This method wraps the provided summary in an `Event` protocol buffer
    and adds it to the event file.

    You can pass the result of evaluating any summary op, using
    @{tf.Session.run} or
    @{tf.Tensor.eval}, to this
    function. Alternatively, you can pass a `tf.Summary` protocol
    buffer that you populate with your own data. The latter is
    commonly done to report evaluation results in event files.

    Args:
      summary: A `Summary` protocol buffer, optionally serialized as a string.
      global_step: Number. Optional global step value to record with the
        summary.
    """
    if isinstance(summary, bytes):
      summ = summary_pb2.Summary()
      summ.ParseFromString(summary)
      summary = summ
    event = event_pb2.Event(summary=summary)
    self._add_event(event, global_step) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:26,代码来源:writer.py

示例4: add_meta_graph

# 需要导入模块: from tensorflow.core.util import event_pb2 [as 别名]
# 或者: from tensorflow.core.util.event_pb2 import Event [as 别名]
def add_meta_graph(self, meta_graph_def, global_step=None):
    """Adds a `MetaGraphDef` to the event file.

    The `MetaGraphDef` allows running the given graph via
    `saver.import_meta_graph()`.

    Args:
      meta_graph_def: A `MetaGraphDef` object, often as returned by
        `saver.export_meta_graph()`.
      global_step: Number. Optional global step counter to record with the
        graph.

    Raises:
      TypeError: If both `meta_graph_def` is not an instance of `MetaGraphDef`.
    """
    if not isinstance(meta_graph_def, meta_graph_pb2.MetaGraphDef):
      raise TypeError("meta_graph_def must be type MetaGraphDef, saw type: %s" %
                      type(meta_graph_def))
    meta_graph_bytes = meta_graph_def.SerializeToString()
    event = event_pb2.Event(meta_graph_def=meta_graph_bytes)
    self._add_event(event, global_step) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:23,代码来源:writer.py

示例5: Load

# 需要导入模块: from tensorflow.core.util import event_pb2 [as 别名]
# 或者: from tensorflow.core.util.event_pb2 import Event [as 别名]
def Load(self):
    """Loads all new values from disk.

    Calling Load multiple times in a row will not 'drop' events as long as the
    return value is not iterated over.

    Yields:
      All values that were written to disk that have not been yielded yet.
    """
    while True:
      try:
        with errors.raise_exception_on_not_ok_status() as status:
          self._reader.GetNext(status)
      except (errors.DataLossError, errors.OutOfRangeError):
        # We ignore partial read exceptions, because a record may be truncated.
        # PyRecordReader holds the offset prior to the failed read, so retrying
        # will succeed.
        break
      event = event_pb2.Event()
      event.ParseFromString(self._reader.record())
      yield event
    logging.debug('No more events in %s', self._file_path) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:24,代码来源:event_file_loader.py

示例6: add_summary

# 需要导入模块: from tensorflow.core.util import event_pb2 [as 别名]
# 或者: from tensorflow.core.util.event_pb2 import Event [as 别名]
def add_summary(self, summary, global_step=None):
    """Adds a `Summary` protocol buffer to the event file.

    This method wraps the provided summary in an `Event` protocol buffer
    and adds it to the event file.

    You can pass the result of evaluating any summary op, using
    [`Session.run()`](client.md#Session.run) or
    [`Tensor.eval()`](framework.md#Tensor.eval), to this
    function. Alternatively, you can pass a `tf.Summary` protocol
    buffer that you populate with your own data. The latter is
    commonly done to report evaluation results in event files.

    Args:
      summary: A `Summary` protocol buffer, optionally serialized as a string.
      global_step: Number. Optional global step value to record with the
        summary.
    """
    if isinstance(summary, bytes):
      summ = summary_pb2.Summary()
      summ.ParseFromString(summary)
      summary = summ
    event = event_pb2.Event(summary=summary)
    self._add_event(event, global_step) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:26,代码来源:writer.py

示例7: add_run_metadata

# 需要导入模块: from tensorflow.core.util import event_pb2 [as 别名]
# 或者: from tensorflow.core.util.event_pb2 import Event [as 别名]
def add_run_metadata(self, run_metadata, tag, global_step=None):
    """Adds a metadata information for a single session.run() call.

    Args:
      run_metadata: A `RunMetadata` protobuf object.
      tag: The tag name for this metadata.
      global_step: Number. Optional global step counter to record with the
        StepStats.

    Raises:
      ValueError: If the provided tag was already used for this type of event.
    """
    if tag in self._session_run_tags:
      raise ValueError("The provided tag was already used for this event type")
    self._session_run_tags[tag] = True

    tagged_metadata = event_pb2.TaggedRunMetadata()
    tagged_metadata.tag = tag
    # Store the `RunMetadata` object as bytes in order to have postponed
    # (lazy) deserialization when used later.
    tagged_metadata.run_metadata = run_metadata.SerializeToString()
    event = event_pb2.Event(tagged_run_metadata=tagged_metadata)
    self._add_event(event, global_step) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:25,代码来源:writer.py

示例8: event_to_record

# 需要导入模块: from tensorflow.core.util import event_pb2 [as 别名]
# 或者: from tensorflow.core.util.event_pb2 import Event [as 别名]
def event_to_record(event):
    """
    Convert an event protobuf to a TFRecord

    Arguments:
        event (Event): Event Protobuf to write in TFRecord format

    Returns:
        TFRecord formatted bytestring
    """

    event_str = serialize_protobuf(event)
    header = struct.pack('Q', len(event_str))
    record = [header,
              struct.pack('I', masked_crc32c(header)),
              event_str,
              struct.pack('I', masked_crc32c(event_str))]

    return b"".join(record) 
开发者ID:NervanaSystems,项目名称:ngraph-python,代码行数:21,代码来源:record_writer.py

示例9: add_meta_graph

# 需要导入模块: from tensorflow.core.util import event_pb2 [as 别名]
# 或者: from tensorflow.core.util.event_pb2 import Event [as 别名]
def add_meta_graph(self, meta_graph_def, global_step=None):
    """Adds a `MetaGraphDef` to the event file.

    The `MetaGraphDef` allows running the given graph via
    `saver.import_meta_graph()`.

    Args:
      meta_graph_def: A `MetaGraphDef` object, often as retured by
        `saver.export_meta_graph()`.
      global_step: Number. Optional global step counter to record with the
        graph.

    Raises:
      TypeError: If both `meta_graph_def` is not an instance of `MetaGraphDef`.
    """
    if not isinstance(meta_graph_def, meta_graph_pb2.MetaGraphDef):
      raise TypeError("meta_graph_def must be type MetaGraphDef, saw type: %s"
                      % type(meta_graph_def))
    meta_graph_bytes = meta_graph_def.SerializeToString()
    event = event_pb2.Event(meta_graph_def=meta_graph_bytes)
    self._add_event(event, global_step) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:23,代码来源:writer.py

示例10: log_key_value

# 需要导入模块: from tensorflow.core.util import event_pb2 [as 别名]
# 或者: from tensorflow.core.util.event_pb2 import Event [as 别名]
def log_key_value(self, key, value, step=None):
        def summary_val(k, v):
            kwargs = {'tag': k, 'simple_value': float(v)}
            return tf.Summary.Value(**kwargs)

        summary = tf.Summary(value=[summary_val(key, value)])
        event = event_pb2.Event(wall_time=time.time(), summary=summary)
        # Use a separate step counter for each key
        if key not in self.key_steps:
            self.key_steps[key] = 0
        if step is not None:
            self.key_steps[key] = step
        event.step = self.key_steps[key]
        self.writer.WriteEvent(event)
        self.writer.Flush()
        self.key_steps[key] += 1 
开发者ID:mrahtz,项目名称:easy-tf-log,代码行数:18,代码来源:easy_tf_log.py

示例11: __init__

# 需要导入模块: from tensorflow.core.util import event_pb2 [as 别名]
# 或者: from tensorflow.core.util.event_pb2 import Event [as 别名]
def __init__(self, logdir, flush_secs=2, is_dummy=False, dummy_time=None):
        self._name_to_tf_name = {}
        self._tf_names = set()
        self.is_dummy = is_dummy
        self.logdir = logdir
        self.flush_secs = flush_secs  # TODO
        self._writer = None
        self._dummy_time = dummy_time
        if is_dummy:
            self.dummy_log = defaultdict(list)
        else:
            if not os.path.exists(self.logdir):
                os.makedirs(self.logdir)
            hostname = socket.gethostname()
            filename = os.path.join(
                self.logdir, 'events.out.tfevents.{}.{}'.format(
                    int(self._time()), hostname))
            self._writer = open(filename, 'wb')
            self._write_event(event_pb2.Event(
                wall_time=self._time(), step=0, file_version='brain.Event:2')) 
开发者ID:TeamHG-Memex,项目名称:tensorboard_logger,代码行数:22,代码来源:tensorboard_logger.py

示例12: write_values

# 需要导入模块: from tensorflow.core.util import event_pb2 [as 别名]
# 或者: from tensorflow.core.util.event_pb2 import Event [as 别名]
def write_values(self, key2val):
        summary = tf.Summary(value=[tf.Summary.Value(tag=k, simple_value=float(v))
            for (k, v) in key2val.items()])
        event = event_pb2.Event(wall_time=time.time(), summary=summary)
        event.step = self.step # is there any reason why you'd want to specify the step?
        self.evwriter.WriteEvent(event)
        self.evwriter.Flush()
        self.step += 1 
开发者ID:openai,项目名称:evolution-strategies-starter,代码行数:10,代码来源:tabular_logger.py

示例13: load_tensor_from_event

# 需要导入模块: from tensorflow.core.util import event_pb2 [as 别名]
# 或者: from tensorflow.core.util.event_pb2 import Event [as 别名]
def load_tensor_from_event(event):
  """Load a tensor from an Event proto.

  Args:
    event: The Event proto, assumed to hold a tensor value in its
        summary.value[0] field.

  Returns:
    The tensor value loaded from the event file, as a `numpy.ndarray`, if
    representation of the tensor value by a `numpy.ndarray` is possible.
    For uninitialized Tensors, returns `None`. For Tensors of data types that
    cannot be represented as `numpy.ndarray` (e.g., `tf.resource`), return
    the `TensorProto` protobuf object without converting it to a
    `numpy.ndarray`.
  """

  tensor_proto = event.summary.value[0].tensor
  if tensor_proto.tensor_content or tensor_proto.string_val:
    # Initialized tensor.
    if tensor_proto.dtype == types_pb2.DT_RESOURCE:
      tensor_value = InconvertibleTensorProto(tensor_proto)
    else:
      try:
        tensor_value = tensor_util.MakeNdarray(tensor_proto)
      except KeyError:
        tensor_value = InconvertibleTensorProto(tensor_proto)
  else:
    # Uninitialized tensor or tensor of unconvertible data type.
    tensor_value = InconvertibleTensorProto(tensor_proto, False)

  return tensor_value 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:33,代码来源:debug_data.py

示例14: _load_graph_def_from_event_file

# 需要导入模块: from tensorflow.core.util import event_pb2 [as 别名]
# 或者: from tensorflow.core.util.event_pb2 import Event [as 别名]
def _load_graph_def_from_event_file(event_file_path):
  event = event_pb2.Event()
  with gfile.Open(event_file_path, "rb") as f:
    event.ParseFromString(f.read())

  return graph_pb2.GraphDef.FromString(event.graph_def) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:8,代码来源:debug_data.py

示例15: _load_log_message_from_event_file

# 需要导入模块: from tensorflow.core.util import event_pb2 [as 别名]
# 或者: from tensorflow.core.util.event_pb2 import Event [as 别名]
def _load_log_message_from_event_file(event_file_path):
  event = event_pb2.Event()
  with gfile.Open(event_file_path, "rb") as f:
    event.ParseFromString(f.read())

  return event.log_message.message 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:8,代码来源:debug_data.py


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