Exemplo n.º 1
0
def load_and_process_example(example_string, mode,
                             image_size=224, preprocess=True):
  """To process records read from tfRecords file.

  Args:
    example_string: str, serialized string record.
    mode: str, from tf.estimator.ModeKeys. Decides how the data is preprocessed.
    image_size: int, for resizing the image.
    preprocess: bool, if true resized to `image_size`.

  Returns:
    {'inputs': image, 'targets':label}
  """
  data = tf.io.parse_single_example(
      example_string,
      features={
          'image/encoded': tf.io.FixedLenFeature([], dtype=tf.string),
          'image/class/label': tf.io.FixedLenFeature([], tf.int64)
      })
  image_string = data['image/encoded']
  image_decoded = tf.image.decode_jpeg(image_string, channels=3)
  if preprocess:
    # The following does random crop/flip for training and center crop for test.
    image_decoded = _do_scale(image_decoded, image_size + 32)
    image_decoded = imagenet_preprocess_example({'inputs': image_decoded},
                                                mode,
                                                resize_size=(image_size,
                                                             image_size),
                                                normalize=False)['inputs']
    image_decoded = _keras_vgg16_preprocess(image_decoded)
  return {'inputs': image_decoded, 'targets': data['image/class/label']}
Exemplo n.º 2
0
 def preprocess_example(self, example, mode, _):
     return imagenet.imagenet_preprocess_example(example, mode)
Exemplo n.º 3
0
 def preprocess_example(self, example, mode, _):
   return imagenet.imagenet_preprocess_example(example, mode)