Exemplo n.º 1
0
    def preprocess(self, image: tf.Tensor,
                   label: tf.Tensor) -> Tuple[tf.Tensor, tf.Tensor]:
        """Apply image preprocessing and augmentation to the image and label."""
        if self.is_training:
            image = preprocessing.preprocess_for_train(
                image,
                image_size=self.image_size,
                mean_subtract=self.config.mean_subtract,
                standardize=self.config.standardize,
                dtype=self.dtype,
                augmenter=self.augmenter)
        else:
            image = preprocessing.preprocess_for_eval(
                image,
                image_size=self.image_size,
                num_channels=self.num_channels,
                mean_subtract=self.config.mean_subtract,
                standardize=self.config.standardize,
                dtype=self.dtype)

        label = tf.cast(label, tf.int32)
        if self.config.one_hot:
            label = tf.one_hot(label, self.num_classes)
            label = tf.reshape(label, [self.num_classes])

        return image, label
Exemplo n.º 2
0
def preprocess_data_imagenet(data, is_training):
    """ImageNet data preprocessing"""
    if is_training:
        image = preprocessing.preprocess_for_train(data['image'],
                                                   image_size=224)
    else:
        image = preprocessing.preprocess_for_eval(data['image'],
                                                  image_size=224)
    return (image, data['label'])
Exemplo n.º 3
0
def preprocess_data(data, is_training):
  """ImageNet data preprocessing"""
  if is_training:
    image = preprocessing.preprocess_for_train(
        data['image'],
        image_size=224,
        augmenter=augment.AutoAugment() if FLAGS.use_autoaugment else None)
    if FLAGS.distort_color:
      image = color_distortion(image, s=1.0)
  else:
    image = preprocessing.preprocess_for_eval(data['image'], image_size=224)
  return {'input_1': image, 'label': data['label']}