Ejemplo n.º 1
0
def parse_record(raw_record, is_training, percent, dtype):
    """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.
    dtype: data type to use for images/features.

  Returns:
    Tuple with processed image tensor and one-hot-encoded label tensor.
  """
    image_buffer, label, bbox, data_idx = _parse_example_proto(raw_record)
    image, label = imagenet_preprocessing.preprocess_image(
        image_buffer=image_buffer,
        bbox=bbox,
        output_height=DEFAULT_IMAGE_SIZE,
        output_width=DEFAULT_IMAGE_SIZE,
        num_channels=NUM_CHANNELS,
        label=label,
        data_idx=data_idx,
        is_training=is_training,
        percent=percent)
    image = tf.cast(image, dtype)

    return image, label
Ejemplo n.º 2
0
 def _preprocess_image(image_bytes):
   """Preprocess a single raw image."""
   # Bounding box around the whole image.
   bbox = tf.constant([0.0, 0.0, 1.0, 1.0], dtype=dtype, shape=[1, 1, 4])
   height, width, num_channels = image_shape
   image = imagenet_preprocessing.preprocess_image(
       image_bytes, bbox, height, width, num_channels, is_training=False)
   return image