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


Python tensorflow.FixedLengthRecordReader方法代碼示例

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


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

示例1: testOneEpoch

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import FixedLengthRecordReader [as 別名]
def testOneEpoch(self):
    files = self._CreateFiles()
    with self.test_session() as sess:
      reader = tf.FixedLengthRecordReader(
          header_bytes=self._header_bytes,
          record_bytes=self._record_bytes,
          footer_bytes=self._footer_bytes,
          name="test_reader")
      queue = tf.FIFOQueue(99, [tf.string], shapes=())
      key, value = reader.read(queue)

      queue.enqueue_many([files]).run()
      queue.close().run()
      for i in range(self._num_files):
        for j in range(self._num_records):
          k, v = sess.run([key, value])
          self.assertAllEqual("%s:%d" % (files[i], j), tf.compat.as_text(k))
          self.assertAllEqual(self._Record(i, j), v)

      with self.assertRaisesOpError("is closed and has insufficient elements "
                                    "\\(requested 1, current size 0\\)"):
        k, v = sess.run([key, value]) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:24,代碼來源:reader_ops_test.py

示例2: read

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import FixedLengthRecordReader [as 別名]
def read(self, filename_queue):
        """Reads and parses examples from CIFAR-10 data files."""

        # Read a record, getting filenames from the filename_queue. No header
        # or footer in the CIFAR-10 format, so we leave header_bytes and
        # footer_bytes at their default of 0.
        reader = tf.FixedLengthRecordReader(record_bytes=RECORD_BYTES)
        _, value = reader.read(filename_queue)

        # Convert from a string to a vector of uint8 that is RECORD_BYTES long.
        record_bytes = tf.decode_raw(value, tf.uint8)

        with tf.name_scope('read_label', values=[record_bytes]):
            # The first bytes represent the label, which we convert from uint8
            # to int64.
            label = tf.strided_slice(record_bytes, [0], [LABEL_BYTES], [1])
            label = tf.cast(label, tf.int64)

        with tf.name_scope('read_image', values=[record_bytes]):
            # The reamining bytes after the label represent the image, which we
            # reshape from [depth * height * width] to [depth, height, width].
            image = tf.strided_slice(
                record_bytes, [LABEL_BYTES], [RECORD_BYTES], [1])
            image = tf.reshape(image, [DEPTH, HEIGHT, WIDTH])

            # Convert from [depth, height, width] to [height, width, depth].
            image = tf.transpose(image, [1, 2, 0])

            # Convert from uint8 to float32.
            image = tf.cast(image, tf.float32)

        return Record(image, [HEIGHT, WIDTH, DEPTH], label) 
開發者ID:rusty1s,項目名稱:graph-based-image-classification,代碼行數:34,代碼來源:cifar_10.py

示例3: read_cifar_files

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import FixedLengthRecordReader [as 別名]
def read_cifar_files(filename_queue, distort_images = True):
    reader = tf.FixedLengthRecordReader(record_bytes=record_length)
    key, record_string = reader.read(filename_queue)
    record_bytes = tf.decode_raw(record_string, tf.uint8)
    image_label = tf.cast(tf.slice(record_bytes, [0], [1]), tf.int32)
  
    # Extract image
    image_extracted = tf.reshape(tf.slice(record_bytes, [1], [image_vec_length]),
                                 [num_channels, image_height, image_width])
    
    # Reshape image
    image_uint8image = tf.transpose(image_extracted, [1, 2, 0])
    reshaped_image = tf.cast(image_uint8image, tf.float32)
    # Randomly Crop image
    final_image = tf.image.resize_image_with_crop_or_pad(reshaped_image, crop_width, crop_height)
    
    if distort_images:
        # Randomly flip the image horizontally, change the brightness and contrast
        final_image = tf.image.random_flip_left_right(final_image)
        final_image = tf.image.random_brightness(final_image,max_delta=63)
        final_image = tf.image.random_contrast(final_image,lower=0.2, upper=1.8)

    # Normalize whitening
    final_image = tf.image.per_image_whitening(final_image)
    return(final_image, image_label)


# Create a CIFAR image pipeline from reader 
開發者ID:PacktPublishing,項目名稱:TensorFlow-Machine-Learning-Cookbook,代碼行數:30,代碼來源:cnn_cifar10.py

示例4: get_input_cifar10

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import FixedLengthRecordReader [as 別名]
def get_input_cifar10(filename_queue):
    # Dimensions of the images in the CIFAR-10 dataset.
    # See http://www.cs.toronto.edu/~kriz/cifar.html for a description of the
    # input format.
    label_bytes = 1     # 2 for CIFAR-100
    image_bytes = 32 * 32 * 3
    # Every record consists of a label followed by the image, with a
    # fixed number of bytes for each.
    record_bytes = label_bytes + image_bytes

    # Read a record, getting filenames from the filename_queue.
    reader = tf.FixedLengthRecordReader(record_bytes=record_bytes)
    key, value = reader.read(filename_queue)
    record = tf.decode_raw(value, tf.uint8)

    # The first bytes represent the label, which we convert from uint8->int32.
    label = tf.cast(record[0], tf.int32)

    # The remaining bytes after the label represent the image, which we reshape
    # from [depth * height * width] to [depth, height, width].
    # tf.strided_slice(record, [label_bytes], [label_bytes + image_bytes])
    image = tf.reshape(record[label_bytes:label_bytes+image_bytes], [3, 32, 32])
    image = tf.cast(image, tf.float32)/255.
    # Convert from [depth, height, width] to [height, width, depth].
    image = tf.transpose(image, [1, 2, 0])

    return image, label 
開發者ID:LMescheder,項目名稱:TheNumericsOfGANs,代碼行數:29,代碼來源:inputs.py

示例5: read_cifar10

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import FixedLengthRecordReader [as 別名]
def read_cifar10(model_params, filename_queue):
    class CIFAR10Record(object):
        pass

    result = CIFAR10Record()

    label_bytes = 1  # 2 for CIFAR-100
    result.height = IMAGE_SIZE
    result.width = IMAGE_SIZE
    result.depth = 3
    image_bytes = result.height * result.width * result.depth
    record_bytes = label_bytes + image_bytes

    reader = tf.FixedLengthRecordReader(record_bytes=record_bytes)
    result.key, value = reader.read(filename_queue)

    record_bytes = tf.decode_raw(value, tf.uint8)

    depth_major = tf.cast(tf.reshape(tf.slice(record_bytes, [label_bytes], [image_bytes]),
                                     [result.depth, result.height, result.width]), tf.float32)

    result.image = utils.process_image(tf.transpose(depth_major, [1, 2, 0]), model_params['mean_pixel']) / 255.0
    extended_image = 255 * tf.reshape(result.image, (1, result.height, result.width, result.depth))

    result.net = vgg_net(model_params["weights"], extended_image)
    content_feature = result.net[CONTENT_LAYER]
    result.content_features = content_feature
    return result 
開發者ID:shekkizh,項目名稱:TensorflowProjects,代碼行數:30,代碼來源:GenerativeNeuralStyle.py

示例6: read_cifar10

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import FixedLengthRecordReader [as 別名]
def read_cifar10(filename_queue):
    class CIFAR10Record(object):
        pass

    result = CIFAR10Record()

    label_bytes = 1
    result.height = IMAGE_SIZE
    result.width = IMAGE_SIZE
    result.depth = 3
    image_bytes = result.height * result.width * result.depth
    record_bytes = label_bytes + image_bytes

    reader = tf.FixedLengthRecordReader(record_bytes=record_bytes)
    result.key, value = reader.read(filename_queue)

    record_bytes = tf.decode_raw(value, tf.uint8)

    depth_major = tf.cast(tf.reshape(tf.slice(record_bytes, [label_bytes], [image_bytes]),
                                     [result.depth, result.height, result.width]), tf.float32)

    image = tf.transpose(depth_major, [1, 2, 0])
    # extended_image = tf.reshape(image, (result.height, result.width, result.depth))
    result.color_image = image
    print result.color_image.get_shape()
    print "Converting image to gray scale"
    result.gray_image = 0.21 * result.color_image[ :, :, 2] + 0.72 * result.color_image[ :, :,
                                                                       1] + 0.07 * result.color_image[ :, :, 0]
    result.gray_image = tf.expand_dims(result.gray_image, 2)
    print result.gray_image.get_shape()

    return result 
開發者ID:shekkizh,項目名稱:TensorflowProjects,代碼行數:34,代碼來源:ImageColoring.py

示例7: read_cifar10

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import FixedLengthRecordReader [as 別名]
def read_cifar10(filename_queue):
  """Reads and parses examples from CIFAR10 data files.

  Recommendation: if you want N-way read parallelism, call this function
  N times.  This will give you N independent Readers reading different
  files & positions within those files, which will give better mixing of
  examples.

  Args:
    filename_queue: A queue of strings with the filenames to read from.

  Returns:
    An object representing a single example, with the following fields:
      height: number of rows in the result (32)
      width: number of columns in the result (32)
      depth: number of color channels in the result (3)
      key: a scalar string Tensor describing the filename & record number
        for this example.
      label: an int32 Tensor with the label in the range 0..9.
      uint8image: a [height, width, depth] uint8 Tensor with the image data
  """

  class CIFAR10Record(object):
    pass
  result = CIFAR10Record()

  # Dimensions of the images in the CIFAR-10 dataset.
  # See http://www.cs.toronto.edu/~kriz/cifar.html for a description of the
  # input format.
  label_bytes = 1  # 2 for CIFAR-100
  result.height = 32
  result.width = 32
  result.depth = 3
  image_bytes = result.height * result.width * result.depth
  # Every record consists of a label followed by the image, with a
  # fixed number of bytes for each.
  record_bytes = label_bytes + image_bytes

  # Read a record, getting filenames from the filename_queue.  No
  # header or footer in the CIFAR-10 format, so we leave header_bytes
  # and footer_bytes at their default of 0.
  reader = tf.FixedLengthRecordReader(record_bytes=record_bytes)
  result.key, value = reader.read(filename_queue)

  # Convert from a string to a vector of uint8 that is record_bytes long.
  record_bytes = tf.decode_raw(value, tf.uint8)

  # The first bytes represent the label, which we convert from uint8->int32.
  result.label = tf.cast(
      tf.strided_slice(record_bytes, [0], [label_bytes]), tf.int32)

  # The remaining bytes after the label represent the image, which we reshape
  # from [depth * height * width] to [depth, height, width].
  depth_major = tf.reshape(
      tf.strided_slice(record_bytes, [label_bytes],
                       [label_bytes + image_bytes]),
      [result.depth, result.height, result.width])
  # Convert from [depth, height, width] to [height, width, depth].
  result.uint8image = tf.transpose(depth_major, [1, 2, 0])

  return result 
開發者ID:ringringyi,項目名稱:DOTA_models,代碼行數:63,代碼來源:cifar10_input.py

示例8: read_cifar10

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import FixedLengthRecordReader [as 別名]
def read_cifar10(filename_queue):
  """Reads and parses examples from CIFAR10 data files.

  Recommendation: if you want N-way read parallelism, call this function
  N times.  This will give you N independent Readers reading different
  files & positions within those files, which will give better mixing of
  examples.

  Args:
    filename_queue: A queue of strings with the filenames to read from.

  Returns:
    An object representing a single example, with the following fields:
      height: number of rows in the result (32)
      width: number of columns in the result (32)
      depth: number of color channels in the result (3)
      key: a scalar string Tensor describing the filename & record number
        for this example.
      label: an int32 Tensor with the label in the range 0..9.
      uint8image: a [height, width, depth] uint8 Tensor with the image data
  """

  class CIFAR10Record(object):
    pass
  result = CIFAR10Record()

  # Dimensions of the images in the CIFAR-10 dataset.
  # See http://www.cs.toronto.edu/~kriz/cifar.html for a description of the
  # input format.
  label_bytes = 1
  result.height = 32
  result.width = 32
  result.depth = 3
  image_bytes = result.height * result.width * result.depth
  # Every record consists of a label followed by the image, with a
  # fixed number of bytes for each.
  record_bytes = label_bytes + image_bytes

  # Read a record, getting filenames from the filename_queue.  No
  # header or footer in the CIFAR-10 format, so we leave header_bytes
  # and footer_bytes at their default of 0.
  reader = tf.FixedLengthRecordReader(record_bytes=record_bytes)
  result.key, value = reader.read(filename_queue)

  # Convert from a string to a vector of uint8 that is record_bytes long.
  record_bytes = tf.decode_raw(value, tf.uint8)

  # The first bytes represent the label, which we convert from uint8->int32.
  result.label = tf.cast(
      tf.strided_slice(record_bytes, [0], [label_bytes]), tf.int32)

  # The remaining bytes after the label represent the image, which we reshape
  # from [depth * height * width] to [depth, height, width].
  depth_major = tf.reshape(
      tf.strided_slice(record_bytes, [label_bytes],
                       [label_bytes + image_bytes]),
      [result.depth, result.height, result.width])
  # Convert from [depth, height, width] to [height, width, depth].
  result.uint8image = tf.transpose(depth_major, [1, 2, 0])

  return result 
開發者ID:wy1iu,項目名稱:SphereNet,代碼行數:63,代碼來源:cifar10plus_input.py

示例9: read_cifar10

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import FixedLengthRecordReader [as 別名]
def read_cifar10(filename_queue):
  """Reads and parses examples from CIFAR10 data files.

  Recommendation: if you want N-way read parallelism, call this function
  N times.  This will give you N independent Readers reading different
  files & positions within those files, which will give better mixing of
  examples.

  Args:
    filename_queue: A queue of strings with the filenames to read from.

  Returns:
    An object representing a single example, with the following fields:
      height: number of rows in the result (32)
      width: number of columns in the result (32)
      depth: number of color channels in the result (3)
      key: a scalar string Tensor describing the filename & record number
        for this example.
      label: an int32 Tensor with the label in the range 0..9.
      uint8image: a [height, width, depth] uint8 Tensor with the image data
  """

  class CIFAR10Record(object):
    pass
  result = CIFAR10Record()

  # Dimensions of the images in the CIFAR-10 dataset.
  # See http://www.cs.toronto.edu/~kriz/cifar.html for a description of the
  # input format.
  label_bytes = 1  # 2 for CIFAR-100
  result.height = 32
  result.width = 32
  result.depth = 3
  image_bytes = result.height * result.width * result.depth
  # Every record consists of a label followed by the image, with a
  # fixed number of bytes for each.
  record_bytes = label_bytes + image_bytes

  # Read a record, getting filenames from the filename_queue.  No
  # header or footer in the CIFAR-10 format, so we leave header_bytes
  # and footer_bytes at their default of 0.
  reader = tf.FixedLengthRecordReader(record_bytes=record_bytes)
  result.key, value = reader.read(filename_queue)

  # Convert from a string to a vector of uint8 that is record_bytes long.
  record_bytes = tf.decode_raw(value, tf.uint8)

  # The first bytes represent the label, which we convert from uint8->int32.
  result.label = tf.cast(
      tf.slice(record_bytes, [0], [label_bytes]), tf.int32)

  # The remaining bytes after the label represent the image, which we reshape
  # from [depth * height * width] to [depth, height, width].
  depth_major = tf.reshape(tf.slice(record_bytes, [label_bytes], [image_bytes]),
                           [result.depth, result.height, result.width])
  # Convert from [depth, height, width] to [height, width, depth].
  result.uint8image = tf.transpose(depth_major, [1, 2, 0])

  return result 
開發者ID:hohoins,項目名稱:ml,代碼行數:61,代碼來源:cifar10_input.py

示例10: read_cifar10

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import FixedLengthRecordReader [as 別名]
def read_cifar10(filename_queue):
    """Reads and parses examples from CIFAR10 data files.

    Recommendation: if you want N-way read parallelism, call this function
    N times.  This will give you N independent Readers reading different
    files & positions within those files, which will give better mixing of
    examples.

    Args:
    filename_queue: A queue of strings with the filenames to read from.

    Returns:
        An object representing a single example, with the following fields:
        height: number of rows in the result (32)
        width: number of columns in the result (32)
        depth: number of color channels in the result (3)
        key: a scalar string Tensor describing the filename & record number
            for this example.
        label: an int32 Tensor with the label in the range 0..9.
        uint8image: a [height, width, depth] uint8 Tensor with the image data
    """

    class CIFAR10Record(object):
        pass
    result = CIFAR10Record()

    label_bytes = 1
    result.height, result.width, result.depth = 32, 32, 3
    image_bytes = result.height * result.width * result.depth
    record_bytes = label_bytes + image_bytes

    reader = tf.FixedLengthRecordReader(record_bytes=record_bytes)
    result.key, value = reader.read(filename_queue)

    # Convert from a string to a vector of uint8 that is record_bytes long.
    record_bytes = tf.decode_raw(value, tf.uint8)

    # The first bytes represent the label, which we convert from uint8->int32.
    result.label = tf.cast(tf.strided_slice(record_bytes, [0], [label_bytes]), tf.int32)

    # The remaining bytes after the label represent the image, which we reshape
    # from [depth * height * width] to [depth, height, width].
    depth_major = tf.reshape(tf.strided_slice(record_bytes, [label_bytes],
                                              [label_bytes + image_bytes]),
                             [result.depth, result.height, result.width])
    # Convert from [depth, height, width] to [height, width, depth].
    result.uint8image = tf.transpose(depth_major, [1, 2, 0])

    return result 
開發者ID:da-molchanov,項目名稱:variance-networks,代碼行數:51,代碼來源:cifar10_input.py

示例11: read_cifar10

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import FixedLengthRecordReader [as 別名]
def read_cifar10(filename_queue):
    """Reads and parses examples from CIFAR10 data files.
      Recommendation: if you want N-way read parallelism, call this function
      N times.  This will give you N independent Readers reading different
      files & positions within those files, which will give better mixing of
      examples.
      Args:
        filename_queue: A queue of strings with the filenames to read from.
      Returns:
        An object representing a single example, with the following fields:
          height: number of rows in the result (32)
          width: number of columns in the result (32)
          depth: number of color channels in the result (3)
          key: a scalar string Tensor describing the filename & record number
            for this example.
          label: an int32 Tensor with the label in the range 0..9.
          uint8image: a [height, width, depth] uint8 Tensor with the image data
      """

    class CIFAR10Record(object):
        pass

    result = CIFAR10Record()

    # Dimensions of the images in the CIFAR-10 dataset.
    # See http://www.cs.toronto.edu/~kriz/cifar.html for a description of the
    # input format.
    label_bytes = 1  # 2 for CIFAR-100
    result.height = 32
    result.width = 32
    result.depth = 3
    image_bytes = result.height * result.width * result.depth
    # Every record consists of a label followed by the image, with a
    # fixed number of bytes for each.
    record_bytes = label_bytes + image_bytes

    # Read a record, getting filenames from the filename_queue.  No
    # header or footer in the CIFAR-10 format, so we leave header_bytes
    # and footer_bytes at their default of 0.
    reader = tf.FixedLengthRecordReader(record_bytes=record_bytes)
    result.key, value = reader.read(filename_queue)

    # Convert from a string to a vector of uint8 that is record_bytes long.
    record_bytes = tf.decode_raw(value, tf.uint8)

    # The first bytes represent the label, which we convert from uint8->int32.
    result.label = tf.cast(
        tf.slice(record_bytes, [0], [label_bytes]), tf.int32)

    # The remaining bytes after the label represent the image, which we reshape
    # from [depth * height * width] to [depth, height, width].
    result.uint8image = tf.reshape(tf.slice(record_bytes, [label_bytes], [image_bytes]),
                                   [result.depth, result.height, result.width])
    return result 
開發者ID:openai,項目名稱:iaf,代碼行數:56,代碼來源:cifar10_data.py

示例12: read_cifar10

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import FixedLengthRecordReader [as 別名]
def read_cifar10(config, filename_queue):
    """Reads and parses examples from CIFAR10 data files.

    Recommendation: if you want N-way read parallelism, call this function
    N times.  This will give you N independent Readers reading different
    files & positions within those files, which will give better mixing of
    examples.

    Args:
        filename_queue: A queue of strings with the filenames to read from.

    Returns:
        An object representing a single example, with the following fields:
            height: number of rows in the result (32)
            width: number of columns in the result (32)
            depth: number of color channels in the result (3)
            key: a scalar string Tensor describing the filename & record number
                 for this example.
            label: an int32 Tensor with the label in the range 0..9.
            uint8image: a [height, width, depth] uint8 Tensor with the image data
    """

    class CIFAR10Record(object):
        pass
    result = CIFAR10Record()

    # Dimensions of the images in the CIFAR-10 dataset.
    # See http://www.cs.toronto.edu/~kriz/cifar.html for a description of the
    # input format.
    label_bytes = 1  # 2 for CIFAR-100
    result.height = int(config.get('main', 'image_size'))
    result.width = int(config.get('main', 'image_size'))
    result.depth = int(config.get('main', 'num_channels'))
    image_bytes = result.height * result.width * result.depth
    # Every record consists of a label followed by the image, with a
    # fixed number of bytes for each.
    record_bytes = label_bytes + image_bytes

    # Read a record, getting filenames from the filename_queue.  No
    # header or footer in the CIFAR-10 format, so we leave header_bytes
    # and footer_bytes at their default of 0.
    reader = tf.FixedLengthRecordReader(record_bytes=record_bytes)
    result.key, value = reader.read(filename_queue)

    # Convert from a string to a vector of uint8 that is record_bytes long.
    record_bytes = tf.decode_raw(value, tf.uint8)

    # The first bytes represent the label, which we convert from uint8->int32.
    result.label = tf.cast(
        tf.slice(record_bytes, [0], [label_bytes]), tf.int32)

    # The remaining bytes after the label represent the image, which we reshape
    # from [depth * height * width] to [depth, height, width].
    depth_major = tf.reshape(tf.slice(record_bytes, [label_bytes], [image_bytes]),
                             [result.depth, result.height, result.width])
    # Convert from [depth, height, width] to [height, width, depth].
    result.uint8image = tf.transpose(depth_major, [1, 2, 0])
    return result 
開發者ID:cchio,項目名稱:deep-pwning,代碼行數:60,代碼來源:utils.py

示例13: read

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import FixedLengthRecordReader [as 別名]
def read(filename_queue):
  """Reads and parses examples from data files.

  Recommendation: if you want N-way read parallelism, call this function
  N times. This will give you N independent Readers reading different
  files & positions within those files, which will give better mixing of
  examples.

  Args:
    filename_queue: A queue of strings with the filenames to read from.

  Returns:
    An object representing a single example, with the following fields:
      height: number of rows in the result (IMAGE_HEIGHT)
      width: number of columns in the result (IMAGE_WIDTH)
      depth: number of color channels in the result (IMAGE_DEPTH)
      key: a scalar string Tensor describing the filename & record number
        for this example.
      label: an int32 Tensor with the label in the range 0..NUM_CLASSES.
      uint8image: a [height, width, depth] uint8 Tensor with the image data
  """

  class SpectrogramRecord(object):
    pass
  result = SpectrogramRecord()

  # Dimensions of the images in the dataset.
  # TODO
  # See http://www.cs.toronto.edu/~kriz/cifar.html for a description of the
  # input format.
  label_bytes = 1

  result.height = IMAGE_HEIGHT
  result.width = IMAGE_WIDTH
  result.depth = IMAGE_DEPTH

  image_bytes = result.height * result.width * result.depth
  # Every record consists of a label followed by the image, with a
  # fixed number of bytes for each.
  record_bytes = label_bytes + image_bytes

  # Read a record, getting filenames from the filename_queue.  No
  # header or footer in the format, so we leave header_bytes
  # and footer_bytes at their default of 0.
  reader = tf.FixedLengthRecordReader(record_bytes=record_bytes)
  result.key, value = reader.read(filename_queue)

  # Convert from a string to a vector of uint8 that is record_bytes long.
  record_bytes = tf.decode_raw(value, tf.uint8)

  # The first bytes represent the label, which we convert from uint8->int32.
  result.label = tf.cast(
      tf.slice(record_bytes, [0], [label_bytes]), tf.int32)

  # The remaining bytes after the label represent the image, which we reshape
  # from [height * width * depth] to [height, width, depth].
  result.uint8image = tf.reshape(tf.slice(record_bytes, [label_bytes], [image_bytes]),
                           [result.height, result.width, result.depth])

  return result 
開發者ID:twerkmeister,項目名稱:iLID,代碼行數:62,代碼來源:image_input.py

示例14: readFromFile

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import FixedLengthRecordReader [as 別名]
def readFromFile(filename_queue): #,metaname_queue):

  class DataRecord(object):
    pass
  result = DataRecord()

  # Count the bytes for each sample
  result.height = 256
  result.width = 256
  result.depth = 3
  result.dmap_height = 64
  result.dmap_width = 64
  dmap_bytes = result.dmap_height * result.dmap_width
  image_bytes = result.height * result.width * result.depth
  record_bytes = dmap_bytes + image_bytes + 1
  # 

  # Read a record
  data_reader = tf.FixedLengthRecordReader(record_bytes=record_bytes)
  result.key, data_value = data_reader.read(filename_queue)
  #
  

  # Convert from a string to a vector of uint8 that is record_bytes long.
  data_in_bytes = tf.decode_raw(data_value, tf.uint8)
  #meta_in_bytes = tf.decode_raw(meta_value, tf.int64)


  # 
  img = tf.reshape(
      tf.strided_slice(data_in_bytes, [0],
                       [0 + image_bytes]),
      [result.depth, result.height, result.width])
  result.image = tf.cast(tf.transpose(img, [1, 2, 0]), tf.float32) / 256

  # 
  dmap = tf.reshape(
      tf.strided_slice(data_in_bytes, [image_bytes], 
		       [image_bytes + dmap_bytes]),
      [1, result.dmap_height, result.dmap_width])
  result.dmap = tf.cast(tf.transpose(dmap, [1, 2, 0]), tf.float32) / 256 

  result.label = tf.cast(
      tf.strided_slice(data_in_bytes, [image_bytes + dmap_bytes], [image_bytes + dmap_bytes + 1]), tf.int32)
 
  return result 
開發者ID:yaojieliu,項目名稱:ECCV2018-FaceDeSpoofing,代碼行數:48,代碼來源:data_train.py

示例15: read_cifar10

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import FixedLengthRecordReader [as 別名]
def read_cifar10(filename_queue):
  """Reads and parses examples from CIFAR10 data files.
  Recommendation: if you want N-way read parallelism, call this function
  N times.  This will give you N independent Readers reading different
  files & positions within those files, which will give better mixing of
  examples.
  Args:
    filename_queue: A queue of strings with the filenames to read from.
  Returns:
    An object representing a single example, with the following fields:
      height: number of rows in the result (32)
      width: number of columns in the result (32)
      depth: number of color channels in the result (3)
      key: a scalar string Tensor describing the filename & record number
        for this example.
      label: an int32 Tensor with the label in the range 0..9.
      uint8image: a [height, width, depth] uint8 Tensor with the image data
  """

  class CIFAR10Record(object):
    pass
  result = CIFAR10Record()

  # Dimensions of the images in the CIFAR-10 dataset.
  # See http://www.cs.toronto.edu/~kriz/cifar.html for a description of the
  # input format.
  label_bytes = 1  # 2 for CIFAR-100
  result.height = 32
  result.width = 32
  result.depth = 3
  image_bytes = result.height * result.width * result.depth
  # Every record consists of a label followed by the image, with a
  # fixed number of bytes for each.
  record_bytes = label_bytes + image_bytes

  # Read a record, getting filenames from the filename_queue.  No
  # header or footer in the CIFAR-10 format, so we leave header_bytes
  # and footer_bytes at their default of 0.
  reader = tf.FixedLengthRecordReader(record_bytes=record_bytes)
  result.key, value = reader.read(filename_queue)

  # Convert from a string to a vector of uint8 that is record_bytes long.
  record_bytes = tf.decode_raw(value, tf.uint8)

  # The first bytes represent the label, which we convert from uint8->int32.
  result.label = tf.cast(
      tf.slice(record_bytes, [0], [label_bytes]), tf.int32)

  # The remaining bytes after the label represent the image, which we reshape
  # from [depth * height * width] to [depth, height, width].
  depth_major = tf.reshape(tf.slice(record_bytes, [label_bytes], [image_bytes]),
                           [result.depth, result.height, result.width])
  # Convert from [depth, height, width] to [height, width, depth].
  result.uint8image = tf.transpose(depth_major, [1, 2, 0])

  return result 
開發者ID:ProbabilisticNumerics,項目名稱:cabs,代碼行數:58,代碼來源:cifar10_adaptive_batchsize.py


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