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


Python tensorflow.decode_raw方法代码示例

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


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

示例1: read_from_tfrecord

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import decode_raw [as 别名]
def read_from_tfrecord(filenames):
    tfrecord_file_queue = tf.train.string_input_producer(filenames, name='queue')
    reader = tf.TFRecordReader()
    _, tfrecord_serialized = reader.read(tfrecord_file_queue)

    tfrecord_features = tf.parse_single_example(tfrecord_serialized, features={
        'label': tf.FixedLenFeature([],tf.int64),
        'shape': tf.FixedLenFeature([],tf.string),
        'image': tf.FixedLenFeature([],tf.string),
    }, name='features')

    image = tf.decode_raw(tfrecord_features['image'], tf.uint8)
    shape = tf.decode_raw(tfrecord_features['shape'], tf.int32)

    image = tf.reshape(image, shape)
    label = tfrecord_features['label']
    return label, shape, image 
开发者ID:wdxtub,项目名称:deep-learning-note,代码行数:19,代码来源:18_basic_tfrecord.py

示例2: read_and_decode

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import decode_raw [as 别名]
def read_and_decode(filename_queue):
    reader = tf.TFRecordReader()
    _, serialized_example = reader.read(filename_queue)
    features = tf.parse_single_example(
        serialized_example,
      # Defaults are not specified since both keys are required.
        features={
            'image_raw': tf.FixedLenFeature([], tf.string),
        })

    image = tf.decode_raw(features['image_raw'], tf.uint8)
    image = tf.reshape(image, [227, 227, 6])

  # Convert from [0, 255] -> [-0.5, 0.5] floats.
    image = tf.cast(image, tf.float32) * (1. / 255) - 0.5
    return tf.split(image, 2, 2) # 3rd dimension two parts 
开发者ID:yiling-chen,项目名称:view-finding-network,代码行数:18,代码来源:vfn_train.py

示例3: read_and_decode_aug

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import decode_raw [as 别名]
def read_and_decode_aug(filename_queue):
    reader = tf.TFRecordReader()
    _, serialized_example = reader.read(filename_queue)
    features = tf.parse_single_example(
        serialized_example,
      # Defaults are not specified since both keys are required.
        features={
            'image_raw': tf.FixedLenFeature([], tf.string),
        })

    image = tf.decode_raw(features['image_raw'], tf.uint8)
    image = tf.image.random_flip_left_right(tf.reshape(image, [227, 227, 6]))
  # Convert from [0, 255] -> [-0.5, 0.5] floats.
    image = tf.cast(image, tf.float32) * (1. / 255) - 0.5
    image = tf.image.random_brightness(image, 0.01)
    image = tf.image.random_contrast(image, 0.95, 1.05)
    return tf.split(image, 2, 2) # 3rd dimension two parts 
开发者ID:yiling-chen,项目名称:view-finding-network,代码行数:19,代码来源:vfn_train.py

示例4: parse_fn

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import decode_raw [as 别名]
def parse_fn(self, serialized_example):
        features={
            'image/id_name': tf.FixedLenFeature([], tf.string),
            'image/height' : tf.FixedLenFeature([], tf.int64),
            'image/width'  : tf.FixedLenFeature([], tf.int64),
            'image/encoded': tf.FixedLenFeature([], tf.string),
        }
        for name in self.feature_list:
            features[name] = tf.FixedLenFeature([], tf.int64)

        example = tf.parse_single_example(serialized_example, features=features)
        image = tf.decode_raw(example['image/encoded'], tf.uint8)
        raw_height = tf.cast(example['image/height'], tf.int32)
        raw_width = tf.cast(example['image/width'], tf.int32)
        image = tf.reshape(image, [raw_height, raw_width, 3])
        image = tf.image.resize_images(image, size=[self.height, self.width])
        # from IPython import embed; embed(); exit()

        feature_val_list = [tf.cast(example[name], tf.float32) for name in self.feature_list]
        return image, feature_val_list 
开发者ID:Prinsphield,项目名称:DNA-GAN,代码行数:22,代码来源:dataset.py

示例5: parse_fun

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import decode_raw [as 别名]
def parse_fun(serialized_example):
    """ Data parsing function.
    """
    features = tf.parse_single_example(serialized_example,
                                       features={'image': tf.FixedLenFeature([], tf.string),
                                                 'label': tf.FixedLenFeature([], tf.int64),
                                                 'height': tf.FixedLenFeature([], tf.int64),
                                                 'width': tf.FixedLenFeature([], tf.int64),
                                                 'depth': tf.FixedLenFeature([], tf.int64)})
    height = tf.cast(features['height'], tf.int32)
    width = tf.cast(features['width'], tf.int32)
    depth = tf.cast(features['depth'], tf.int32)
    image = tf.decode_raw(features['image'], tf.float32)
    image = tf.reshape(image, shape=[height * width * depth])
    image.set_shape([28 * 28 * 1])
    image = tf.cast(image, tf.float32) * (1. / 255)
    label = tf.cast(features['label'], tf.int32)
    features = {'images': image, 'labels': label}
    return(features) 
开发者ID:naturomics,项目名称:CapsLayer,代码行数:21,代码来源:reader.py

示例6: _extract_features_batch

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import decode_raw [as 别名]
def _extract_features_batch(self, serialized_batch):
        features = tf.parse_example(
            serialized_batch,
            features={'images': tf.FixedLenFeature([], tf.string),
                'imagepaths': tf.FixedLenFeature([], tf.string),
                'labels': tf.VarLenFeature(tf.int64),
                 })

        bs = features['images'].shape[0]
        images = tf.decode_raw(features['images'], tf.uint8)
        w, h = tuple(CFG.ARCH.INPUT_SIZE)
        images = tf.cast(x=images, dtype=tf.float32)
        #images = tf.subtract(tf.divide(images, 128.0), 1.0)
        images = tf.reshape(images, [bs, h, -1, CFG.ARCH.INPUT_CHANNELS])

        labels = features['labels']
        labels = tf.cast(labels, tf.int32)

        imagepaths = features['imagepaths']

        return images, labels, imagepaths 
开发者ID:Mingtzge,项目名称:2019-CCF-BDCI-OCR-MCZJ-OCR-IdentificationIDElement,代码行数:23,代码来源:read_tfrecord.py

示例7: parse_color_data

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import decode_raw [as 别名]
def parse_color_data(example_proto):
    features = {"img_raw": tf.FixedLenFeature([], tf.string),
                "label": tf.FixedLenFeature([], tf.string),
                "width": tf.FixedLenFeature([], tf.int64),
                "height": tf.FixedLenFeature([], tf.int64)}
    parsed_features = tf.parse_single_example(example_proto, features)
    img = parsed_features["img_raw"]
    img = tf.decode_raw(img, tf.uint8)
    width = parsed_features["width"]
    height = parsed_features["height"]
    img = tf.reshape(img, [height, width, 3])
    img = tf.cast(img, tf.float32) * (1. / 255.) - 0.5
    label = parsed_features["label"]
    label = tf.decode_raw(label, tf.float32)

    return img, label 
开发者ID:xggIoU,项目名称:centernet_tensorflow_wilderface_voc,代码行数:18,代码来源:train.py

示例8: read_and_decode

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import decode_raw [as 别名]
def read_and_decode(filename_queue):
  reader = tf.TFRecordReader()
  _, serialized_example = reader.read(filename_queue)

  features = tf.parse_single_example(
      serialized_example,
      features={
          'image_raw': tf.FixedLenFeature([], tf.string),
          'label': tf.FixedLenFeature([], tf.int64),
      })

  image = tf.decode_raw(features['image_raw'], tf.uint8)
  image.set_shape([784])
  image = tf.cast(image, tf.float32) * (1. / 255)
  label = tf.cast(features['label'], tf.int32)

  return image, label 
开发者ID:GoogleCloudPlatform,项目名称:cloudml-dist-mnist-example,代码行数:19,代码来源:model.py

示例9: decode_pred

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import decode_raw [as 别名]
def decode_pred(serialized_example):
	"""Parses prediction data from the given `serialized_example`."""

	features = tf.parse_single_example(
					serialized_example,
					features={
						'T1':tf.FixedLenFeature([],tf.string),
						'T2':tf.FixedLenFeature([], tf.string)
					})

	patch_shape = [conf.patch_size, conf.patch_size, conf.patch_size]

	# Convert from a scalar string tensor
	image_T1 = tf.decode_raw(features['T1'], tf.int16)
	image_T1 = tf.reshape(image_T1, patch_shape)
	image_T2 = tf.decode_raw(features['T2'], tf.int16)
	image_T2 = tf.reshape(image_T2, patch_shape)

	# Convert dtype.
	image_T1 = tf.cast(image_T1, tf.float32)
	image_T2 = tf.cast(image_T2, tf.float32)
	label = tf.zeros(image_T1.shape) # pseudo label

	return image_T1, image_T2, label 
开发者ID:zhengyang-wang,项目名称:3D-Unet--Tensorflow,代码行数:26,代码来源:input_fn.py

示例10: parse_tfrecord_tf

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import decode_raw [as 别名]
def parse_tfrecord_tf(record, res, rnd_crop):
    features = tf.parse_single_example(record, features={
        'shape': tf.FixedLenFeature([3], tf.int64),
        'data': tf.FixedLenFeature([], tf.string),
        'label': tf.FixedLenFeature([1], tf.int64)})
    # label is always 0 if uncondtional
    # to get CelebA attr, add 'attr': tf.FixedLenFeature([40], tf.int64)
    data, label, shape = features['data'], features['label'], features['shape']
    label = tf.cast(tf.reshape(label, shape=[]), dtype=tf.int32)
    img = tf.decode_raw(data, tf.uint8)
    if rnd_crop:
        # For LSUN Realnvp only - random crop
        img = tf.reshape(img, shape)
        img = tf.random_crop(img, [res, res, 3])
    img = tf.reshape(img, [res, res, 3])
    return img, label  # to get CelebA attr, also return attr 
开发者ID:openai,项目名称:glow,代码行数:18,代码来源:get_data.py

示例11: get_tfrecords_features

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import decode_raw [as 别名]
def get_tfrecords_features(self) -> dict:
        """
        Return dict, possibly nested, with feature names as keys and its
        serialized type as values of type :obj:`FixedLenFeature`.
        Keys should not have any '/', use nested dict instead.

        Returns
        -------
        features
            features inside of tfrecords file

        See Also
        --------
        output_types
            :func:`tf.decode_raw`
        """ 
开发者ID:audi,项目名称:nucleus7,代码行数:18,代码来源:tf_data_utils.py

示例12: decode_field

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import decode_raw [as 别名]
def decode_field(self,
                     field_name: str,
                     field_value: Union[tf.Tensor, tf.SparseTensor],
                     field_type: Optional[tf.DType] = None) -> tf.Tensor:
        """
        Decode a field from a tfrecord example

        Parameters
        ----------
        field_name
            name of the field, if nested - will be separated using "/"
        field_value
            value of the field from tfrecords example
        field_type
            type of the decoded field from self.get_tfrecords_output_types
            or None, if it was not provided
        """
        # pylint: disable=no-self-use
        # is designed to be overridden
        # pylint: disable=unused-argument
        # this method is really an interface, but has a default implementation.
        if field_type is None:
            return field_value
        return tf.decode_raw(field_value, field_type) 
开发者ID:audi,项目名称:nucleus7,代码行数:26,代码来源:tf_data_utils.py

示例13: tf_record_parser

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import decode_raw [as 别名]
def tf_record_parser(record):
    keys_to_features = {
        "image_raw": tf.FixedLenFeature((), tf.string, default_value=""),
        'annotation_raw': tf.FixedLenFeature([], tf.string),
        "height": tf.FixedLenFeature((), tf.int64),
        "width": tf.FixedLenFeature((), tf.int64)
    }

    features = tf.parse_single_example(record, keys_to_features)

    image = tf.decode_raw(features['image_raw'], tf.uint8)
    annotation = tf.decode_raw(features['annotation_raw'], tf.uint8)

    height = tf.cast(features['height'], tf.int32)
    width = tf.cast(features['width'], tf.int32)

    # reshape input and annotation images
    image = tf.reshape(image, (height, width, 3), name="image_reshape")
    annotation = tf.reshape(annotation, (height, width, 1), name="annotation_reshape")
    annotation = tf.to_int32(annotation)

    return tf.to_float(image), annotation, (height, width) 
开发者ID:autoai-org,项目名称:CVTron,代码行数:24,代码来源:read_data.py

示例14: read_image

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import decode_raw [as 别名]
def read_image(file_queue):
	reader = tf.TFRecordReader()
	# key, value = reader.read(file_queue)
	_, serialized_example = reader.read(file_queue)
	features = tf.parse_single_example(
		serialized_example,
		features={
			'label': tf.FixedLenFeature([], tf.string),
			'image_raw': tf.FixedLenFeature([], tf.string)
			})

	image = tf.decode_raw(features['image_raw'], tf.uint8)
	# print('image ' + str(image))
	image = tf.reshape(image, [INPUT_IMG_WIDE, INPUT_IMG_HEIGHT, INPUT_IMG_CHANNEL])
	# image = tf.image.convert_image_dtype(image, dtype=tf.float32)
	# image = tf.image.resize_images(image, (IMG_HEIGHT, IMG_WIDE))
	# image = tf.cast(image, tf.float32) * (1. / 255) - 0.5

	label = tf.decode_raw(features['label'], tf.uint8)
	# label = tf.cast(label, tf.int64)
	label = tf.reshape(label, [OUTPUT_IMG_WIDE, OUTPUT_IMG_HEIGHT])
	# label = tf.decode_raw(features['image_raw'], tf.uint8)
	# print(label)
	# label = tf.reshape(label, shape=[1, 4])
	return image, label 
开发者ID:DuFanXin,项目名称:U-net,代码行数:27,代码来源:unet-TF-withBatchNormal.py

示例15: read_my_file_format

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import decode_raw [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


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