當前位置: 首頁>>代碼示例>>Python>>正文


Python pywrap_tensorflow.PyRecordReader_New方法代碼示例

本文整理匯總了Python中tensorflow.python.pywrap_tensorflow.PyRecordReader_New方法的典型用法代碼示例。如果您正苦於以下問題:Python pywrap_tensorflow.PyRecordReader_New方法的具體用法?Python pywrap_tensorflow.PyRecordReader_New怎麽用?Python pywrap_tensorflow.PyRecordReader_New使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tensorflow.python.pywrap_tensorflow的用法示例。


在下文中一共展示了pywrap_tensorflow.PyRecordReader_New方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: tf_record_iterator

# 需要導入模塊: from tensorflow.python import pywrap_tensorflow [as 別名]
# 或者: from tensorflow.python.pywrap_tensorflow import PyRecordReader_New [as 別名]
def tf_record_iterator(path, options=None):
  """An iterator that read the records from a TFRecords file.

  Args:
    path: The path to the TFRecords file.
    options: (optional) A TFRecordOptions object.

  Yields:
    Strings.

  Raises:
    IOError: If `path` cannot be opened for reading.
  """
  compression_type = TFRecordOptions.get_compression_type_string(options)
  with errors.raise_exception_on_not_ok_status() as status:
    reader = pywrap_tensorflow.PyRecordReader_New(
        compat.as_bytes(path), 0, compat.as_bytes(compression_type), status)

  if reader is None:
    raise IOError("Could not open %s." % path)
  while True:
    try:
      with errors.raise_exception_on_not_ok_status() as status:
        reader.GetNext(status)
    except errors.OutOfRangeError:
      break
    yield reader.record()
  reader.Close() 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:30,代碼來源:tf_record.py

示例2: __init__

# 需要導入模塊: from tensorflow.python import pywrap_tensorflow [as 別名]
# 或者: from tensorflow.python.pywrap_tensorflow import PyRecordReader_New [as 別名]
def __init__(self, file_path):
    if file_path is None:
      raise ValueError('A file path is required')
    file_path = resource_loader.readahead_file_path(file_path)
    logging.debug('Opening a record reader pointing at %s', file_path)
    with errors.raise_exception_on_not_ok_status() as status:
      self._reader = pywrap_tensorflow.PyRecordReader_New(
          compat.as_bytes(file_path), 0, compat.as_bytes(''), status)
    # Store it for logging purposes.
    self._file_path = file_path
    if not self._reader:
      raise IOError('Failed to open a record reader pointing to %s' % file_path) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:14,代碼來源:event_file_loader.py

示例3: _make_tf_record_iterator

# 需要導入模塊: from tensorflow.python import pywrap_tensorflow [as 別名]
# 或者: from tensorflow.python.pywrap_tensorflow import PyRecordReader_New [as 別名]
def _make_tf_record_iterator(file_path):
    """Returns an iterator over TF records for the given tfrecord file."""
    # If we don't have TF at all, use the stub implementation.
    if tf.__version__ == "stub":
        # TODO(#1711): Reshape stub implementation to fit tf_record_iterator API
        # rather than needlessly emulating the old PyRecordReader_New API.
        logger.debug("Opening a stub record reader pointing at %s", file_path)
        return _PyRecordReaderIterator(
            tf.pywrap_tensorflow.PyRecordReader_New, file_path
        )
    # If PyRecordReader exists, use it, otherwise use tf_record_iterator().
    # Check old first, then new, since tf_record_iterator existed previously but
    # only gained the semantics we need at the time PyRecordReader was removed.
    #
    # TODO(#1711): Eventually remove PyRecordReader fallback once we can drop
    # support for TF 2.1 and prior, and find a non-deprecated replacement for
    # tf.compat.v1.io.tf_record_iterator.
    try:
        from tensorflow.python import pywrap_tensorflow

        py_record_reader_new = pywrap_tensorflow.PyRecordReader_New
    except (ImportError, AttributeError):
        py_record_reader_new = None
    if py_record_reader_new:
        logger.debug("Opening a PyRecordReader pointing at %s", file_path)
        return _PyRecordReaderIterator(py_record_reader_new, file_path)
    else:
        logger.debug("Opening a tf_record_iterator pointing at %s", file_path)
        # TODO(#1711): Find non-deprecated replacement for tf_record_iterator.
        with _silence_deprecation_warnings():
            return tf.compat.v1.io.tf_record_iterator(file_path) 
開發者ID:tensorflow,項目名稱:tensorboard,代碼行數:33,代碼來源:event_file_loader.py

示例4: __init__

# 需要導入模塊: from tensorflow.python import pywrap_tensorflow [as 別名]
# 或者: from tensorflow.python.pywrap_tensorflow import PyRecordReader_New [as 別名]
def __init__(self, py_record_reader_new, file_path):
        """Constructs a _PyRecordReaderIterator for the given file path.

        Args:
          py_record_reader_new: pywrap_tensorflow.PyRecordReader_New
          file_path: file path of the tfrecord file to read
        """
        with tf.compat.v1.errors.raise_exception_on_not_ok_status() as status:
            self._reader = py_record_reader_new(
                tf.compat.as_bytes(file_path), 0, tf.compat.as_bytes(""), status
            )
        if not self._reader:
            raise IOError(
                "Failed to open a record reader pointing to %s" % file_path
            ) 
開發者ID:tensorflow,項目名稱:tensorboard,代碼行數:17,代碼來源:event_file_loader.py


注:本文中的tensorflow.python.pywrap_tensorflow.PyRecordReader_New方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。