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


Python tensorflow.read_file方法代码示例

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


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

示例1: preprocess

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import read_file [as 别名]
def preprocess(self, filename):
    # Read examples from files in the filename queue.
    file_content = tf.read_file(filename)
    # Read JPEG or PNG or GIF image from file
    reshaped_image = tf.to_float(tf.image.decode_jpeg(file_content, channels=self.raw_size[2]))
    # Resize image to 256*256
    reshaped_image = tf.image.resize_images(reshaped_image, (self.raw_size[0], self.raw_size[1]))

    img_info = filename

    if self.is_training:
      reshaped_image = self._train_preprocess(reshaped_image)
    else:
      reshaped_image = self._test_preprocess(reshaped_image)

    # Subtract off the mean and divide by the variance of the pixels.
    reshaped_image = tf.image.per_image_standardization(reshaped_image)

    # Set the shapes of tensors.
    reshaped_image.set_shape(self.processed_size)

    return reshaped_image 
开发者ID:arashno,项目名称:tensorflow_multigpu_imagenet,代码行数:24,代码来源:data_loader.py

示例2: read_tensor_from_image_file

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import read_file [as 别名]
def read_tensor_from_image_file(frames, input_height=299, input_width=299, input_mean=0, input_std=255):
    input_name = "file_reader"
    frames = [(tf.read_file(frame, input_name), frame) for frame in frames]
    decoded_frames = []
    for frame in frames:
        file_name = frame[1]
        file_reader = frame[0]
        if file_name.endswith(".png"):
            image_reader = tf.image.decode_png(file_reader, channels=3, name="png_reader")
        elif file_name.endswith(".gif"):
            image_reader = tf.squeeze(tf.image.decode_gif(file_reader, name="gif_reader"))
        elif file_name.endswith(".bmp"):
            image_reader = tf.image.decode_bmp(file_reader, name="bmp_reader")
        else:
            image_reader = tf.image.decode_jpeg(file_reader, channels=3, name="jpeg_reader")
        decoded_frames.append(image_reader)
    float_caster = [tf.cast(image_reader, tf.float32) for image_reader in decoded_frames]
    float_caster = tf.stack(float_caster)
    resized = tf.image.resize_bilinear(float_caster, [input_height, input_width])
    normalized = tf.divide(tf.subtract(resized, [input_mean]), [input_std])
    sess = tf.Session()
    result = sess.run(normalized)
    return result 
开发者ID:hthuwal,项目名称:sign-language-gesture-recognition,代码行数:25,代码来源:predict_spatial.py

示例3: read_image_from_disc

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import read_file [as 别名]
def read_image_from_disc(image_path,shape=None,dtype=tf.uint8):
    """
    Create a queue to hoold the paths of files to be loaded, then create meta op to read and decode image
    Args:
        image_path: metaop with path of the image to be loaded
        shape: optional shape for the image
    Returns:
        meta_op with image_data
    """         
    image_raw = tf.read_file(image_path)
    if dtype==tf.uint8:
        image = tf.image.decode_image(image_raw)
    else:
        image = tf.image.decode_png(image_raw,dtype=dtype)
    if shape is None:
        image.set_shape([None,None,3])
    else:
        image.set_shape(shape)
    return tf.cast(image, dtype=tf.float32) 
开发者ID:CVLAB-Unibo,项目名称:Learning2AdaptForStereo,代码行数:21,代码来源:data_reader.py

示例4: parse_fn

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import read_file [as 别名]
def parse_fn(self, image_path, label_path):
    """Parse a single input sample
    """
    image = tf.read_file(image_path)
    image = tf.image.decode_png(image, channels=self.config.image_depth)

    if self.config.mode == "infer":
      image = tf.to_float(image)
      image = vgg_preprocessing._mean_image_subtraction(image)
      label = image[0]
      return image, label
    else:
      label = tf.read_file(label_path)
      label = tf.image.decode_png(label, channels=1)
      label = tf.cast(label, dtype=tf.int64)

      if self.augmenter:
        is_training = (self.config.mode == "train")
        return self.augmenter.augment(image, label,
                                      self.config.output_height,
                                      self.config.output_width,
                                      self.config.resize_side_min,
                                      self.config.resize_side_max,
                                      is_training=is_training,
                                      speed_mode=self.config.augmenter_speed_mode) 
开发者ID:lambdal,项目名称:lambda-deep-learning-demo,代码行数:27,代码来源:image_segmentation_csv_inputter.py

示例5: parse_fn

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import read_file [as 别名]
def parse_fn(self, image_path, label):
    """Parse a single input sample
    """
    image = tf.read_file(image_path)
    image = tf.image.decode_jpeg(image,
                                 channels=self.config.image_depth,
                                 dct_method="INTEGER_ACCURATE")

    if self.augmenter:
      is_training = (self.config.mode == "train")
      image = self.augmenter.augment(
        image,
        self.config.image_height,
        self.config.image_width,
        is_training=is_training,
        speed_mode=self.config.augmenter_speed_mode)

    label = tf.one_hot(label, depth=self.config.num_classes)

    return (image, label) 
开发者ID:lambdal,项目名称:lambda-deep-learning-demo,代码行数:22,代码来源:image_classification_csv_inputter.py

示例6: parse_fn

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import read_file [as 别名]
def parse_fn(self, image_path):
    """Parse a single input sample
    """
    image = tf.read_file(image_path)
    image = tf.image.decode_jpeg(image,
                                 channels=self.config.image_depth,
                                 dct_method="INTEGER_ACCURATE")

    if self.config.mode == "infer":
      image = tf.to_float(image)
      image = vgg_preprocessing._mean_image_subtraction(image)
    else:
      if self.augmenter:
        is_training = (self.config.mode == "train")
        image = self.augmenter.augment(
          image,
          self.config.image_height,
          self.config.image_width,
          self.config.resize_side_min,
          self.config.resize_side_max,
          is_training=is_training,
          speed_mode=self.config.augmenter_speed_mode)
    return (image,) 
开发者ID:lambdal,项目名称:lambda-deep-learning-demo,代码行数:25,代码来源:style_transfer_csv_inputter.py

示例7: parse_fn

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import read_file [as 别名]
def parse_fn(self, image_id, file_name, classes, boxes):
    """Parse a single input sample
    """
    image = tf.read_file(file_name)
    image = tf.image.decode_png(image, channels=3)
    image = tf.to_float(image)

    scale = [0, 0]
    translation = [0, 0]
    if self.augmenter:
      is_training = (self.config.mode == "train")
      image, classes, boxes, scale, translation = self.augmenter.augment(
        image,
        classes,
        boxes,
        self.config.resolution,
        is_training=is_training,
        speed_mode=False)

    return ([image_id], image, classes, boxes, scale, translation, [file_name]) 
开发者ID:lambdal,项目名称:lambda-deep-learning-demo,代码行数:22,代码来源:object_detection_mscoco_inputter.py

示例8: compute_style_feature

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import read_file [as 别名]
def compute_style_feature(self):
    style_image = tf.read_file(self.config.style_image_path)
    style_image = \
        tf.image.decode_jpeg(style_image,
                             channels=self.config.image_depth,
                             dct_method="INTEGER_ACCURATE")
    style_image = tf.to_float(style_image)
    style_image = vgg_preprocessing._mean_image_subtraction(style_image)
    style_image = tf.expand_dims(style_image, 0)

    (logits, features), self.feature_net_init_flag = self.feature_net(
      style_image, self.config.data_format,
      is_training=False, init_flag=self.feature_net_init_flag,
      ckpt_path=self.config.feature_net_path)

    self.style_features_target_op = {}
    for style_layer in self.style_layers:
      layer = features[style_layer]
      self.style_features_target_op[style_layer] = \
          self.compute_gram(layer, self.config.data_format)

    return self.style_features_target_op 
开发者ID:lambdal,项目名称:lambda-deep-learning-demo,代码行数:24,代码来源:style_transfer_modeler.py

示例9: _parse_function

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import read_file [as 别名]
def _parse_function(image, mask):
    image_string = tf.read_file(image)
    mask_string = tf.read_file(mask)
    if image_type == 'jpg':
        image_decoded = tf.image.decode_jpeg(image_string, 0)
        mask_decoded = tf.image.decode_jpeg(mask_string, 1)
    elif image_type == 'png':
        image_decoded = tf.image.decode_png(image_string, 0)
        mask_decoded = tf.image.decode_png(mask_string, 1)
    elif image_type == 'bmp':
        image_decoded = tf.image.decode_bmp(image_string, 0)
        mask_decoded = tf.image.decode_bmp(mask_string, 1)
    else:
        raise TypeError('==> Error: Only support jpg, png and bmp.')
        
    # already in 0~1
    image_decoded = tf.image.convert_image_dtype(image_decoded, tf.float32)
    mask_decoded = tf.image.convert_image_dtype(mask_decoded, tf.float32)
    
    return image_decoded, mask_decoded 
开发者ID:junqiangchen,项目名称:LiTS---Liver-Tumor-Segmentation-Challenge,代码行数:22,代码来源:dataset_input.py

示例10: CamVid_reader_seq

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import read_file [as 别名]
def CamVid_reader_seq(filename_queue, seq_length):
    image_seq_filenames = tf.split(axis=0,
                                   num_or_size_splits=seq_length,
                                   value=filename_queue[0])
    label_seq_filenames = tf.split(axis=0,
                                   num_or_size_splits=seq_length,
                                   value=filename_queue[1])

    image_seq = []
    label_seq = []
    for im ,la in zip(image_seq_filenames, label_seq_filenames):
        imageValue = tf.read_file(tf.squeeze(im))
        labelValue = tf.read_file(tf.squeeze(la))
        image_bytes = tf.image.decode_png(imageValue)
        label_bytes = tf.image.decode_png(labelValue)
        image = tf.cast(tf.reshape(image_bytes,
                                   (IMAGE_HEIGHT, IMAGE_WIDTH, IMAGE_DEPTH)), tf.float32)
        label = tf.cast(tf.reshape(label_bytes,
                                   (IMAGE_HEIGHT, IMAGE_WIDTH, 1)), tf.int64)
        image_seq.append(image)
        label_seq.append(label)
    return image_seq, label_seq 
开发者ID:mengli,项目名称:MachineLearning,代码行数:24,代码来源:kitti_segnet.py

示例11: load_inference

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import read_file [as 别名]
def load_inference(filenames, labels, batch_size, resize=(32,32)):

        # Single image estimation over multiple stochastic forward passes

        def _preprocess_inference(image_path, label, resize=(32,32)):
            # Preprocess individual images during inference
            image_path = tf.squeeze(image_path)
            image = tf.image.decode_png(tf.read_file(image_path))
            image = tf.image.convert_image_dtype(image, dtype=tf.float32)
            image = tf.image.per_image_standardization(image)
            image = tf.image.resize_images(image, size=resize)

            return image, label

        dataset = tf.data.Dataset.from_tensor_slices((filenames, labels))
        dataset = dataset.map(_preprocess_inference)
        dataset = dataset.batch(batch_size)
        
        return dataset 
开发者ID:Justin-Tan,项目名称:generative-compression,代码行数:21,代码来源:data.py

示例12: read_images_from_disk

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import read_file [as 别名]
def read_images_from_disk(input_queue, input_size, random_scale, random_mirror): # optional pre-processing arguments
    """Read one image and its corresponding mask with optional pre-processing.
    
    Args:
      input_queue: tf queue with paths to the image and its mask.
      input_size: a tuple with (height, width) values.
                  If not given, return images of original size.
      random_scale: whether to randomly scale the images prior
                    to random crop.
      random_mirror: whether to randomly mirror the images prior
                    to random crop.
      
    Returns:
      Two tensors: the decoded image and its mask.
    """

    img_contents = tf.read_file(input_queue[0])
    
    img = tf.image.decode_jpeg(img_contents, channels=3)
    img_r, img_g, img_b = tf.split(value=img, num_or_size_splits=3, axis=2)
    img = tf.cast(tf.concat([img_b, img_g, img_r], 2), dtype=tf.float32)
    # Extract mean.
    img -= IMG_MEAN

    return img 
开发者ID:Engineering-Course,项目名称:LIP_JPPNet,代码行数:27,代码来源:image_reader.py

示例13: read_from_disk

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import read_file [as 别名]
def read_from_disk(self,queue):
        index_t=queue[0]#tf.random_shuffle(self.input_list)[0]
        index_min=tf.reshape(tf.where(tf.less_equal(self.node,index_t)),[-1])
        node_min=self.node[index_min[-1]]
        node_max=self.node[index_min[-1]+1]
        interval_list=list(range(30,100))
        interval=tf.random_shuffle(interval_list)[0]
        index_d=[tf.cond(tf.greater(index_t-interval,node_min),lambda:index_t-interval,lambda:index_t+interval),tf.cond(tf.less(index_t+interval,node_max),lambda:index_t+interval,lambda:index_t-interval)]
        index_d=tf.random_shuffle(index_d)
        index_d=index_d[0]

        constant_t=tf.read_file(self.img_list[index_t])
        template=tf.image.decode_jpeg(constant_t, channels=3)
        template=template[:,:,::-1]
        constant_d=tf.read_file(self.img_list[index_d])
        detection=tf.image.decode_jpeg(constant_d, channels=3)
        detection=detection[:,:,::-1]

        template_label=self.label_list[index_t]
        detection_label=self.label_list[index_d]

        template_p,template_label_p,_,_=self.crop_resize(template,template_label,1)
        detection_p,detection_label_p,offset,ratio=self.crop_resize(detection,detection_label,2)

        return template_p,template_label_p,detection_p,detection_label_p,offset,ratio,detection,detection_label,index_t,index_d 
开发者ID:makalo,项目名称:Siamese-RPN-tensorflow,代码行数:27,代码来源:image_reader_cuda.py

示例14: dataset_reader

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import read_file [as 别名]
def dataset_reader(filename_queue): #prev name: CamVid_reader

    image_filename = filename_queue[0] #tensor of type string
    label_filename = filename_queue[1] #tensor of type string

    #get png encoded image
    imageValue = tf.read_file(image_filename)
    labelValue = tf.read_file(label_filename)

    #decodes a png image into a uint8 or uint16 tensor
    #returns a tensor of type dtype with shape [height, width, depth]
    image_bytes = tf.image.decode_png(imageValue)
    label_bytes = tf.image.decode_png(labelValue) #Labels are png, not jpeg

    image = tf.reshape(image_bytes, (FLAGS.image_h, FLAGS.image_w, FLAGS.image_c))
    label = tf.reshape(label_bytes, (FLAGS.image_h, FLAGS.image_w, 1))

    return image, label 
开发者ID:mathildor,项目名称:TF-SegNet,代码行数:20,代码来源:inputs.py

示例15: read_one_image

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import read_file [as 别名]
def read_one_image(filename):
    ''' This method is to show how to read image from a file into a tensor.
    The output is a tensor object.
    '''
    image_string = tf.read_file(filename)
    image_decoded = tf.image.decode_image(image_string)
    image = tf.cast(image_decoded, tf.float32) / 256.0
    return image 
开发者ID:wdxtub,项目名称:deep-learning-note,代码行数:10,代码来源:16_basic_kernels.py


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