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


Python tensorflow.WholeFileReader方法代码示例

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


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

示例1: read_my_file_format

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import WholeFileReader [as 别名]
def read_my_file_format(filename_queue):
    image_reader = tf.WholeFileReader()
    _, image_data = image_reader.read(filename_queue)
    
    # Convert from a string to a vector of uint8 that is record_bytes long.
    record_bytes = tf.decode_raw(image_data, tf.uint8)
    
    # The first bytes represent the label, which we convert from uint8->float32.
    labels_ = tf.cast(tf.slice(record_bytes, [0], [LSPGlobals.TotalLabels]), tf.float32)
    
    # 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, [LSPGlobals.TotalLabels], [LSPGlobals.TotalImageBytes]),
                          [FLAGS.input_size, FLAGS.input_size, FLAGS.input_depth])
    # Convert from [depth, height, width] to [height, width, depth].
    #processed_example = tf.cast(tf.transpose(depth_major, [1, 2, 0]), tf.float32)
    

    return depth_major, labels_ 
开发者ID:samitok,项目名称:deeppose,代码行数:21,代码来源:TrainLSP.py

示例2: read_word_freq

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import WholeFileReader [as 别名]
def read_word_freq(filename):
    filename_queue = tf.train.string_input_producer([filename])
    reader = tf.WholeFileReader()
    key, value = reader.read(filename_queue)
    lines = tf.string_split([value], "\n")

    with tf.Session() as sess:
        # Start populating the filename queue.
        coord = tf.train.Coordinator()
        threads = tf.train.start_queue_runners(coord=coord)
        sess.run([lines])
        lines_eval = lines.eval()
        result = []
        for line in lines_eval.values:
            s = line.split()
            result.append((s[0], int(s[1])))
        coord.request_stop()
        coord.join(threads)
    return result 
开发者ID:koala-ai,项目名称:tensorflow_nlp,代码行数:21,代码来源:word2vec.py

示例3: testInfiniteEpochs

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import WholeFileReader [as 别名]
def testInfiniteEpochs(self):
    with self.test_session() as sess:
      reader = tf.WholeFileReader("test_reader")
      queue = tf.FIFOQueue(99, [tf.string], shapes=())
      enqueue = queue.enqueue_many([self._filenames])
      key, value = reader.read(queue)

      enqueue.run()
      self._ExpectRead(sess, key, value, 0)
      self._ExpectRead(sess, key, value, 1)
      enqueue.run()
      self._ExpectRead(sess, key, value, 2)
      self._ExpectRead(sess, key, value, 0)
      self._ExpectRead(sess, key, value, 1)
      enqueue.run()
      self._ExpectRead(sess, key, value, 2)
      self._ExpectRead(sess, key, value, 0) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:19,代码来源:reader_ops_test.py

示例4: _read_flow

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import WholeFileReader [as 别名]
def _read_flow(filenames, num_epochs=None):
    """Given a list of filenames, constructs a reader op for ground truth flow files."""
    filename_queue = tf.train.string_input_producer(filenames,
        shuffle=False, capacity=len(filenames), num_epochs=num_epochs)
    reader = tf.WholeFileReader()
    _, value = reader.read(filename_queue)
    value = tf.reshape(value, [1])
    value_width = tf.substr(value, 4, 4)
    value_height = tf.substr(value, 8, 4)
    width = tf.reshape(tf.decode_raw(value_width, out_type=tf.int32), [])
    height = tf.reshape(tf.decode_raw(value_height, out_type=tf.int32), [])

    value_flow = tf.substr(value, 12, 8 * width * height)
    flow = tf.decode_raw(value_flow, out_type=tf.float32)
    flow = tf.reshape(flow, [height, width, 2])
    mask = tf.to_float(tf.logical_and(flow[:, :, 0] < 1e9, flow[:, :, 1] < 1e9))
    mask = tf.reshape(mask, [height, width, 1])

    return flow, mask 
开发者ID:simonmeister,项目名称:UnFlow,代码行数:21,代码来源:input.py

示例5: _read_flow

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import WholeFileReader [as 别名]
def _read_flow(filenames, num_epochs=None):
    """Given a list of filenames, constructs a reader op for ground truth flow files."""
    filename_queue = tf.train.string_input_producer(filenames,
        shuffle=False, capacity=len(filenames), num_epochs=num_epochs)
    reader = tf.WholeFileReader()
    _, value = reader.read(filename_queue)
    value = tf.reshape(value, [1])
    value_width = tf.substr(value, 4, 4)
    value_height = tf.substr(value, 8, 4)
    width = tf.reshape(tf.decode_raw(value_width, out_type=tf.int32), [])
    height = tf.reshape(tf.decode_raw(value_height, out_type=tf.int32), [])

    value_flow = tf.substr(value, 12, 8 * 436 * 1024)
    flow = tf.decode_raw(value_flow, out_type=tf.float32)

    return tf.reshape(flow, [436, 1024, 2]) 
开发者ID:simonmeister,项目名称:UnFlow,代码行数:18,代码来源:input.py

示例6: _read_input

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import WholeFileReader [as 别名]
def _read_input(self, filename_queue):
        class DataRecord(object):
            pass

        reader = tf.WholeFileReader()
        key, value = reader.read(filename_queue)
        record = DataRecord()
        decoded_image = tf.image.decode_jpeg(value,
                                             channels=3)  # Assumption:Color images are read and are to be generated

        # decoded_image_4d = tf.expand_dims(decoded_image, 0)
        # resized_image = tf.image.resize_bilinear(decoded_image_4d, [self.target_image_size, self.target_image_size])
        # record.input_image = tf.squeeze(resized_image, squeeze_dims=[0])

        cropped_image = tf.cast(
            tf.image.crop_to_bounding_box(decoded_image, 55, 35, self.crop_image_size, self.crop_image_size),
            tf.float32)
        decoded_image_4d = tf.expand_dims(cropped_image, 0)
        resized_image = tf.image.resize_bilinear(decoded_image_4d, [self.resized_image_size, self.resized_image_size])
        record.input_image = tf.squeeze(resized_image, squeeze_dims=[0])
        return record 
开发者ID:shekkizh,项目名称:WassersteinGAN.tensorflow,代码行数:23,代码来源:GAN_models.py

示例7: load_images_from_idlist

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import WholeFileReader [as 别名]
def load_images_from_idlist(idlist, batch_size, num_preprocess_threads, min_queue_examples, shift_param = -128, rescale_param = 128, resized_image_size = [128, 128], shuffle = True):
  # Make a queue of file names including all the image files in the relative
  # image directory.
  filename_queue = tf.train.string_input_producer(idlist,
                                                  shuffle=shuffle)
  
  # Read an entire image file. If the images
  # are too large they could be split in advance to smaller files or use the Fixed
  # reader to split up the file.
  image_reader = tf.WholeFileReader()
  
  # Read a whole file from the queue, the first returned value in the tuple is the
  # filename which we are ignoring.
  _, image_file = image_reader.read(filename_queue)

  return _load_images(image_file, batch_size, num_preprocess_threads, min_queue_examples, shift_param, rescale_param, resized_image_size, shuffle) 
开发者ID:thomasneff,项目名称:Generative-Adversarial-Network-based-Synthesis-for-Supervised-Medical-Image-Segmentation,代码行数:18,代码来源:load_folder_images.py

示例8: load_images

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import WholeFileReader [as 别名]
def load_images(folder_path_match, batch_size, num_preprocess_threads, min_queue_examples, shift_param = -128, rescale_param = 128, resized_image_size = [128, 128], shuffle = True):
  # Make a queue of file names including all the image files in the relative
  # image directory.
  filename_queue = tf.train.string_input_producer(
    tf.train.match_filenames_once(folder_path_match),
    shuffle=shuffle)
  
  # Read an entire image file. If the images
  # are too large they could be split in advance to smaller files or use the Fixed
  # reader to split up the file.
  image_reader = tf.WholeFileReader()
  
  # Read a whole file from the queue, the first returned value in the tuple is the
  # filename which we are ignoring.
  _, image_file = image_reader.read(filename_queue)

  return _load_images(image_file, batch_size, num_preprocess_threads, min_queue_examples, shift_param, rescale_param, resized_image_size, shuffle) 
开发者ID:thomasneff,项目名称:Generative-Adversarial-Network-based-Synthesis-for-Supervised-Medical-Image-Segmentation,代码行数:19,代码来源:load_folder_images.py

示例9: get_input_image

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import WholeFileReader [as 别名]
def get_input_image(filename_queue, output_size, image_size, c_dim):
    # Read a record, getting filenames from the filename_queue.
    reader = tf.WholeFileReader()
    key, value = reader.read(filename_queue)
    image = tf.image.decode_image(value, channels=c_dim)
    image = tf.cast(image, tf.float32)/255.

    image_shape = tf.shape(image)
    image_height, image_width = image_shape[0], image_shape[1]
    offset_height = tf.cast((image_height - image_size)/2, tf.int32)
    offset_width = tf.cast((image_width - image_size)/2, tf.int32)
    image = tf.image.crop_to_bounding_box(
        image, offset_height, offset_width, image_size, image_size)
    image = tf.image.resize_images(image, [output_size, output_size])

    image.set_shape([output_size, output_size, c_dim])

    return image 
开发者ID:LMescheder,项目名称:TheNumericsOfGANs,代码行数:20,代码来源:inputs.py

示例10: load_batch_demosaic

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import WholeFileReader [as 别名]
def load_batch_demosaic(BURST_LENGTH, dataset_dir, batch_size=32, height=64, width=64, degamma=1., to_shift=1., upscale=1, jitter=1):

  filenames = [os.path.join(dataset_dir, f) for f in gfile.ListDirectory(dataset_dir)]
  filename_queue = tf.train.string_input_producer(filenames)

  mosaic = None
  while mosaic == None:
    _, image_file = tf.WholeFileReader().read(filename_queue)
    image = tf.image.decode_image(image_file)
    mosaic, demosaic, shift = make_stack_demosaic((tf.cast(image[0], tf.float32) / 255.)**degamma,
                                                  height, width, 128, BURST_LENGTH, to_shift, upscale, jitter)

  # Batch it up.
  mosaic, demosaic, shift = tf.train.shuffle_batch(
        [mosaic, demosaic, shift],
        batch_size=batch_size,
        num_threads=2,
        capacity=500 + 3 * batch_size,
        enqueue_many=True,
        min_after_dequeue=100)

  return mosaic, demosaic, shift 
开发者ID:google,项目名称:burst-denoising,代码行数:24,代码来源:kpn_data_provider.py

示例11: load_batch_hqjitter

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import WholeFileReader [as 别名]
def load_batch_hqjitter(dataset_dir, patches_per_img=32, min_queue=8, BURST_LENGTH=1, batch_size=32,
                        repeats=1, height=64, width=64, degamma=1.,
                        to_shift=1., upscale=1, jitter=1, smalljitter=1):

  filenames = [os.path.join(dataset_dir, f) for f in gfile.ListDirectory(dataset_dir)]
  filename_queue = tf.train.string_input_producer(filenames)

  _, image_file = tf.WholeFileReader().read(filename_queue)
  image = tf.image.decode_image(image_file)
  patches = make_stack_hqjitter((tf.cast(image[0], tf.float32) / 255.)**degamma,
                                                    height, width, patches_per_img, BURST_LENGTH, to_shift, upscale, jitter)
  unique = batch_size//repeats
  # Batch it up.
  patches  = tf.train.shuffle_batch(
        [patches],
        batch_size=unique,
        num_threads=2,
        capacity=min_queue + 3 * batch_size,
        enqueue_many=True,
        min_after_dequeue=min_queue)

  print('PATCHES =================',patches.get_shape().as_list())

  patches = make_batch_hqjitter(patches, BURST_LENGTH, batch_size, repeats, height, width, to_shift, upscale, jitter, smalljitter)
  return patches 
开发者ID:google,项目名称:burst-denoising,代码行数:27,代码来源:kpn_data_provider.py

示例12: load_batch_noised

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import WholeFileReader [as 别名]
def load_batch_noised(depth, dataset_dir, batch_size=32, height=64, width=64, degamma=1., sig_range=20.):

  filenames = [os.path.join(dataset_dir, f) for f in gfile.ListDirectory(dataset_dir)]
  filename_queue = tf.train.string_input_producer(filenames)

  noised_stack = None
  while noised_stack == None:
    _, image_file = tf.WholeFileReader().read(filename_queue)
    image = tf.image.decode_image(image_file)
    noised_stack, denoised_stack, sig_stack = make_stack_noised((tf.cast(image[0], tf.float32) / 255.)**degamma, height, width, depth, sig_range)

  # Batch it up.
  noised, denoised, sig = tf.train.shuffle_batch(
        [noised_stack, denoised_stack, sig_stack],
        batch_size=batch_size,
        num_threads=2,
        capacity=1024 + 3 * batch_size,
        enqueue_many=True,
        min_after_dequeue=500)

  return noised, denoised, sig 
开发者ID:google,项目名称:burst-denoising,代码行数:23,代码来源:kpn_data_provider.py

示例13: load_tensorflow_image

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import WholeFileReader [as 别名]
def load_tensorflow_image(self, channel_label: str,
                            image_name: str) -> lt.LabeledTensor:
    # All images will be cropped to this size.
    crop_size = 1024

    filename_op = tf.train.string_input_producer([self.data_path(image_name)])
    wfr = tf.WholeFileReader()
    _, encoded_png_op = wfr.read(filename_op)
    image_op = tf.image.decode_png(
        tf.reshape(encoded_png_op, shape=[]), channels=1, dtype=tf.uint16)
    image_op = image_op[:crop_size, :crop_size, :]
    image_op = tf.to_float(image_op) / np.iinfo(np.uint16).max
    image_op = tf.reshape(image_op, [1, 1024, 1024, 1])

    return lt.LabeledTensor(
        image_op, ['batch', 'row', 'column', ('channel', [channel_label])]) 
开发者ID:google,项目名称:in-silico-labeling,代码行数:18,代码来源:test_util.py

示例14: setUp

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import WholeFileReader [as 别名]
def setUp(self):
    super(ShapeTest, self).setUp()

    filename_op = tf.train.string_input_producer([
        os.path.join(os.environ['TEST_SRCDIR'],
                     'isl/testdata/research_logo.jpg')
    ])

    reader = tf.WholeFileReader()
    _, encoded_image_op = reader.read(filename_op)
    image_op = tf.image.decode_jpeg(encoded_image_op, channels=3)

    self.correct_shape_op = tf.identity(image_op)
    self.correct_shape_op.set_shape([250, 250, 3])
    self.correct_lt = lt.LabeledTensor(self.correct_shape_op,
                                       ['x', 'y', 'color'])

    self.incorrect_shape_op = tf.identity(image_op)
    self.incorrect_shape_op.set_shape([50, 50, 3])
    self.incorrect_lt = lt.LabeledTensor(self.incorrect_shape_op,
                                         ['x', 'y', 'color'])

    self.okay_lt = tensorcheck.shape(self.correct_lt)
    self.error_lt = tensorcheck.shape(self.incorrect_lt) 
开发者ID:google,项目名称:in-silico-labeling,代码行数:26,代码来源:tensorcheck_test.py

示例15: SingleFileReader

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import WholeFileReader [as 别名]
def SingleFileReader(filename, shape, rtype='tanh', ext='jpg'):    
    n, h, w, c = shape
    if ext == 'jpg' or ext == 'jpeg':
        decoder = tf.image.decode_jpeg
    elif ext == 'png':
        decoder = tf.image.decode_png
    else:
        raise ValueError('Unsupported file type: {:s}.'.format(ext) + 
            ' (only *.png and *.jpg are supported')

    filename_queue = tf.train.string_input_producer(filename, shuffle=False)
    reader = tf.WholeFileReader()
    key, value = reader.read(filename_queue)
    img = decoder(value, channels=c)
    img = tf.image.crop_to_bounding_box(img, 0, 0, h, w)
    img = tf.to_float(img)
    if rtype == 'tanh':
        img = tf.div(img, 127.5) - 1.

    imgs = tf.train.batch(
        [img],
        batch_size=n,
        capacity=1)
    return imgs, key 
开发者ID:JeremyCCHsu,项目名称:tf-vaegan,代码行数:26,代码来源:validate.py


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