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


Python vgg_preprocessing.preprocess_image方法代码示例

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


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

示例1: preprocess

# 需要导入模块: import vgg_preprocessing [as 别名]
# 或者: from vgg_preprocessing import preprocess_image [as 别名]
def preprocess(self, image_buffer, bbox, thread_id):
    """Preprocessing image_buffer using thread_id."""
    # Note: Width and height of image is known only at runtime.
    image = tf.image.decode_jpeg(image_buffer, channels=3,
                                 dct_method='INTEGER_FAST')
    if self.train and self.distortions:
      image = distort_image(image, self.height, self.width, bbox, thread_id)
    else:
      #image = eval_image(image, self.height, self.width, bbox, thread_id,
      #                   self.resize_method)
      image = vgg_preprocessing.preprocess_image(image,224,224,False)
    # Note: image is now float32 [height,width,3] with range [0, 255]

    # image = tf.cast(image, tf.uint8) # HACK TESTING

    return image 
开发者ID:IntelAI,项目名称:models,代码行数:18,代码来源:preprocessing.py

示例2: parse_record

# 需要导入模块: import vgg_preprocessing [as 别名]
# 或者: from vgg_preprocessing import preprocess_image [as 别名]
def parse_record(filename, label, is_training):
  """Parses a record containing a training example of an image.

  The input record is parsed into a label and image, and the image is passed
  through preprocessing steps (cropping, flipping, and so on).

  Args:
    raw_record: scalar Tensor tf.string containing a serialized
      Example protocol buffer.
    is_training: A boolean denoting whether the input is for training.

  Returns:
    Tuple with processed image tensor and one-hot-encoded label tensor.
"""
  # Decode the string as an RGB JPEG.
  # Note that the resulting image contains an unknown height and width
  # that is set dynamically by decode_jpeg. In other words, the height
  # and width of image is unknown at compile-time.
  # Results in a 3-D int8 Tensor. This will be converted to a float later,
  # during resizing.

  print (filename)
  image_encoded = tf.read_file(tf.reduce_join([data_dir, '/', filename]))
  image_decoded = tf.image.decode_jpeg(image_encoded, channels=3)
  image = tf.image.decode_jpeg(image_encoded, channels=_NUM_CHANNELS)

  image = vgg_preprocessing.preprocess_image(
      image=image,
      output_height=_DEFAULT_IMAGE_SIZE,
      output_width=_DEFAULT_IMAGE_SIZE,
      is_training=is_training)

  label = tf.cast(tf.reshape(label, shape=[]), dtype=tf.int32)
  label = tf.one_hot(label, _NUM_CLASSES)

  print (image, label)
  return image, label 
开发者ID:wuyuebupt,项目名称:LargeScaleIncrementalLearning,代码行数:39,代码来源:imagenet_main.py

示例3: parse_and_preprocess

# 需要导入模块: import vgg_preprocessing [as 别名]
# 或者: from vgg_preprocessing import preprocess_image [as 别名]
def parse_and_preprocess(self, value):
    # parse
    image_buffer, label_index = parse_example_proto(value)
    # preprocess
    image = tf.image.decode_jpeg(
      image_buffer, channels=3, fancy_upscaling=False, dct_method='INTEGER_FAST')
    image = vgg_preprocessing.preprocess_image(image,224,224,False)

    return (image, label_index) 
开发者ID:IntelAI,项目名称:models,代码行数:11,代码来源:preprocessing.py

示例4: record_parser

# 需要导入模块: import vgg_preprocessing [as 别名]
# 或者: from vgg_preprocessing import preprocess_image [as 别名]
def record_parser(value, is_training):
  """Parse an ImageNet record from `value`."""
  keys_to_features = {
      'image/encoded':
          tf.FixedLenFeature((), tf.string, default_value=''),
      'image/format':
          tf.FixedLenFeature((), tf.string, default_value='jpeg'),
      'image/class/label':
          tf.FixedLenFeature([], dtype=tf.int64, default_value=-1),
      'image/class/text':
          tf.FixedLenFeature([], dtype=tf.string, default_value=''),
      'image/object/bbox/xmin':
          tf.VarLenFeature(dtype=tf.float32),
      'image/object/bbox/ymin':
          tf.VarLenFeature(dtype=tf.float32),
      'image/object/bbox/xmax':
          tf.VarLenFeature(dtype=tf.float32),
      'image/object/bbox/ymax':
          tf.VarLenFeature(dtype=tf.float32),
      'image/object/class/label':
          tf.VarLenFeature(dtype=tf.int64),
  }

  parsed = tf.parse_single_example(value, keys_to_features)

  image = tf.image.decode_image(
      tf.reshape(parsed['image/encoded'], shape=[]),
      _NUM_CHANNELS)
  image = tf.image.convert_image_dtype(image, dtype=tf.float32)

  image = vgg_preprocessing.preprocess_image(
      image=image,
      output_height=_DEFAULT_IMAGE_SIZE,
      output_width=_DEFAULT_IMAGE_SIZE,
      is_training=is_training)

  label = tf.cast(
      tf.reshape(parsed['image/class/label'], shape=[]),
      dtype=tf.int32)

  return image, tf.one_hot(label, _LABEL_CLASSES) 
开发者ID:rky0930,项目名称:yolo_v2,代码行数:43,代码来源:imagenet_main.py

示例5: preprocess_raw_bytes

# 需要导入模块: import vgg_preprocessing [as 别名]
# 或者: from vgg_preprocessing import preprocess_image [as 别名]
def preprocess_raw_bytes(image_bytes, is_training=False, bbox=None):
  """Preprocesses a raw JPEG image.

  This implementation is shared in common between train/eval pipelines,
  and when serving the model.

  Args:
    image_bytes: A string Tensor, containing the encoded JPEG.
    is_training: Whether or not to preprocess for training.
    bbox:        In inception preprocessing, this bbox can be used for cropping.

  Returns:
    A 3-Tensor [height, width, RGB channels] of type float32.
  """

  image = tf.image.decode_jpeg(image_bytes, channels=3)
  image = tf.image.convert_image_dtype(image, dtype=tf.float32)

  if FLAGS.preprocessing == 'vgg':
    image = vgg_preprocessing.preprocess_image(
        image=image,
        output_height=FLAGS.height,
        output_width=FLAGS.width,
        is_training=is_training,
        resize_side_min=_RESIZE_SIDE_MIN,
        resize_side_max=_RESIZE_SIDE_MAX)
  elif FLAGS.preprocessing == 'inception':
    image = inception_preprocessing.preprocess_image(
        image=image,
        output_height=FLAGS.height,
        output_width=FLAGS.width,
        is_training=is_training,
        bbox=bbox)
  else:
    assert False, 'Unknown preprocessing type: %s' % FLAGS.preprocessing
  return image 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:38,代码来源:inception_v4.py

示例6: dataset_parser

# 需要导入模块: import vgg_preprocessing [as 别名]
# 或者: from vgg_preprocessing import preprocess_image [as 别名]
def dataset_parser(self, value):
    """Parse an Imagenet record from value."""
    keys_to_features = {
        "image/encoded": tf.FixedLenFeature((), tf.string, ""),
        "image/format": tf.FixedLenFeature((), tf.string, "jpeg"),
        "image/class/label": tf.FixedLenFeature([], tf.int64, -1),
        "image/class/text": tf.FixedLenFeature([], tf.string, ""),
        "image/object/bbox/xmin": tf.VarLenFeature(dtype=tf.float32),
        "image/object/bbox/ymin": tf.VarLenFeature(dtype=tf.float32),
        "image/object/bbox/xmax": tf.VarLenFeature(dtype=tf.float32),
        "image/object/bbox/ymax": tf.VarLenFeature(dtype=tf.float32),
        "image/object/class/label": tf.VarLenFeature(dtype=tf.int64),
    }

    parsed = tf.parse_single_example(value, keys_to_features)

    image = tf.image.decode_image(
        tf.reshape(parsed["image/encoded"], shape=[]), _NUM_CHANNELS)
    image = tf.image.convert_image_dtype(image, dtype=tf.float32)

    # TODO(shivaniagrawal): height and width of image from model
    image = vgg_preprocessing.preprocess_image(
        image=image,
        output_height=224,
        output_width=224,
        is_training=self.is_training)

    label = tf.cast(
        tf.reshape(parsed["image/class/label"], shape=[]), dtype=tf.int32)

    return image, tf.one_hot(label, _LABEL_CLASSES) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:33,代码来源:densenet_imagenet.py

示例7: __init__

# 需要导入模块: import vgg_preprocessing [as 别名]
# 或者: from vgg_preprocessing import preprocess_image [as 别名]
def __init__(self, is_training, data_dir, batch_size):
    """Constructor for ImageNetInput.

    Args:
      is_training: `bool` for whether the input is for training.
      data_dir: `str` for the directory of the training and validation data.
      batch_size: The global batch size to use.
    """
    self.image_preprocessing_fn = vgg_preprocessing.preprocess_image
    self.is_training = is_training
    self.data_dir = data_dir
    self.batch_size = batch_size 
开发者ID:artyompal,项目名称:tpu_models,代码行数:14,代码来源:densenet_keras_imagenet.py

示例8: parser

# 需要导入模块: import vgg_preprocessing [as 别名]
# 或者: from vgg_preprocessing import preprocess_image [as 别名]
def parser(self, value, is_training):
    """Parse an ImageNet record from `value`."""
    keys_to_features = {
        'image/encoded':
            tf.compat.v1.FixedLenFeature((), tf.string, default_value=''),
        'image/format':
            tf.compat.v1.FixedLenFeature((), tf.string, default_value='jpeg'),
        'image/class/label':
            tf.compat.v1.FixedLenFeature([], dtype=tf.int64, default_value=-1),
        'image/class/text':
            tf.compat.v1.FixedLenFeature([], dtype=tf.string, default_value=''),
        'image/object/bbox/xmin':
            tf.compat.v1.VarLenFeature(dtype=tf.float32),
        'image/object/bbox/ymin':
            tf.compat.v1.VarLenFeature(dtype=tf.float32),
        'image/object/bbox/xmax':
            tf.compat.v1.VarLenFeature(dtype=tf.float32),
        'image/object/bbox/ymax':
            tf.compat.v1.VarLenFeature(dtype=tf.float32),
        'image/object/class/label':
            tf.compat.v1.VarLenFeature(dtype=tf.int64),
    }

    parsed = tf.compat.v1.parse_single_example(value, keys_to_features)

    image = tf.image.decode_image(
        tf.reshape(parsed['image/encoded'], shape=[]),
        _NUM_CHANNELS)
    image = tf.image.convert_image_dtype(image, dtype=tf.float32)

    image = vgg_preprocessing.preprocess_image(
        image=image,
        output_height=_DEFAULT_IMAGE_SIZE,
        output_width=_DEFAULT_IMAGE_SIZE,
        is_training=is_training)

    label = tf.cast(
        tf.reshape(parsed['image/class/label'], shape=[]),
        dtype=tf.int32)

    return image, label #tf.one_hot(label, _LABEL_CLASSES) 
开发者ID:ucloud,项目名称:uai-sdk,代码行数:43,代码来源:imagenet.py

示例9: parser

# 需要导入模块: import vgg_preprocessing [as 别名]
# 或者: from vgg_preprocessing import preprocess_image [as 别名]
def parser(self, value, is_training):
    """Parse an ImageNet record from `value`."""
    keys_to_features = {
        'image/encoded':
            tf.FixedLenFeature((), tf.string, default_value=''),
        'image/format':
            tf.FixedLenFeature((), tf.string, default_value='jpeg'),
        'image/class/label':
            tf.FixedLenFeature([], dtype=tf.int64, default_value=-1),
        'image/class/text':
            tf.FixedLenFeature([], dtype=tf.string, default_value=''),
        'image/object/bbox/xmin':
             tf.VarLenFeature(dtype=tf.float32),
        'image/object/bbox/ymin':
            tf.VarLenFeature(dtype=tf.float32),
        'image/object/bbox/xmax':
            tf.VarLenFeature(dtype=tf.float32),
        'image/object/bbox/ymax':
            tf.VarLenFeature(dtype=tf.float32),
        'image/object/class/label':
            tf.VarLenFeature(dtype=tf.int64),
    }

    parsed = tf.parse_single_example(value, keys_to_features)

    image = tf.image.decode_image(
        tf.reshape(parsed['image/encoded'], shape=[]),
        _NUM_CHANNELS)
    image = tf.image.convert_image_dtype(image, dtype=tf.float32)

    image = vgg_preprocessing.preprocess_image(
        image=image,
        output_height=_DEFAULT_IMAGE_SIZE,
        output_width=_DEFAULT_IMAGE_SIZE,
        is_training=is_training)

    label = tf.cast(
        tf.reshape(parsed['image/class/label'], shape=[]),
        dtype=tf.int32)

    return image, label #tf.one_hot(label, _LABEL_CLASSES) 
开发者ID:ucloud,项目名称:uai-sdk,代码行数:43,代码来源:imagenet.py


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