(style_dataset_file,
                                 batch_size=None,
                                 image_size=None,
                                 center_crop=True,
                                 shuffle=True,
                                 augment_style_images=False,
                                 random_style_image_size=False,
                                 min_rand_image_size=128,
                                 max_rand_image_size=300)
Loads a batch of random style image given the path of tfrecord dataset.

  This method does not return pre-compute Gram matrices for the images like
  style_image_inputs. But it can provide data augmentation. If
  augment_style_images is equal to True, then style images will randomly
  modified (eg. changes in brightness, hue or saturation) for data
  augmentation. If random_style_image_size is set to True then all images
  in one batch will be resized to a random size.
  Args:
    style_dataset_file: str, path to the tfrecord dataset of style files.
    batch_size: int. If provided, batches style images. Defaults to None.
    image_size: int. The images will be resized bilinearly so that the smallest
        side has size image_size. Defaults to None.
    center_crop: bool. If True, center-crops to [image_size, image_size].
        Defaults to False.
    shuffle: bool, whether to shuffle style files at random. Defaults to False.
    augment_style_images: bool. Wheather to augment style images or not.
    random_style_image_size: bool. If this value is True, then all the style
        images in one batch will be resized to a random size between
        min_rand_image_size and max_rand_image_size.
    min_rand_image_size: int. If random_style_image_size is True, this value
        specifies the minimum image size.
    max_rand_image_size: int. If random_style_image_size is True, this value
        specifies the maximum image size.

  Returns:
    4-D tensor of shape [1, ?, ?, 3] with values in [0, 1] for the style
    image (with random changes for data augmentation if
    augment_style_image_size is set to true), and 0-D tensor for the style
    label, 4-D tensor of shape [1, ?, ?, 3] with values in [0, 1] for the style
    image without random changes for data augmentation.

  Raises:
    ValueError: if center cropping is requested but no image size is provided,
        or if batch size is specified but center-cropping or
        augment-style-images is not requested,
        or if both augment-style-images and center-cropping are requested.
Loads a batch of random style image given the path of tfrecord dataset.
Loads a batch of random style image given the path of tfrecord dataset .
def arbitrary_style_image_inputs(style_dataset_file,
                                 batch_size=None,
                                 image_size=None,
                                 center_crop=True,
                                 shuffle=True,
                                 augment_style_images=False,
                                 random_style_image_size=False,
                                 min_rand_image_size=128,
                                 max_rand_image_size=300):
  """Loads a batch of random style image given the path of tfrecord dataset.

  This method does not return pre-compute Gram matrices for the images like
  style_image_inputs. But it can provide data augmentation. If
  augment_style_images is equal to True, then style images will randomly
  modified (eg. changes in brightness, hue or saturation) for data
  augmentation. If random_style_image_size is set to True then all images
  in one batch will be resized to a random size.
  Args:
    style_dataset_file: str, path to the tfrecord dataset of style files.
    batch_size: int. If provided, batches style images. Defaults to None.
    image_size: int. The images will be resized bilinearly so that the smallest
        side has size image_size. Defaults to None.
    center_crop: bool. If True, center-crops to [image_size, image_size].
        Defaults to False.
    shuffle: bool, whether to shuffle style files at random. Defaults to False.
    augment_style_images: bool. Wheather to augment style images or not.
    random_style_image_size: bool. If this value is True, then all the style
        images in one batch will be resized to a random size between
        min_rand_image_size and max_rand_image_size.
    min_rand_image_size: int. If random_style_image_size is True, this value
        specifies the minimum image size.
    max_rand_image_size: int. If random_style_image_size is True, this value
        specifies the maximum image size.

  Returns:
    4-D tensor of shape [1, ?, ?, 3] with values in [0, 1] for the style
    image (with random changes for data augmentation if
    augment_style_image_size is set to true), and 0-D tensor for the style
    label, 4-D tensor of shape [1, ?, ?, 3] with values in [0, 1] for the style
    image without random changes for data augmentation.

  Raises:
    ValueError: if center cropping is requested but no image size is provided,
        or if batch size is specified but center-cropping or
        augment-style-images is not requested,
        or if both augment-style-images and center-cropping are requested.
  """
  if center_crop and image_size is None:
    raise ValueError('center-cropping requires specifying the image size.')
  if center_crop and augment_style_images:
    raise ValueError(
        'When augment_style_images is true images will be randomly cropped.')
  if batch_size is not None and not center_crop and not augment_style_images:
    raise ValueError(
        'batching requires same image sizes (Set center-cropping or '
        'augment_style_images to true)')

  with tf.name_scope('style_image_processing'):
    # Force all input processing onto CPU in order to reserve the GPU for the
    # forward inference and back-propagation.
    with tf.device('/cpu:0'):
      filename_queue = tf.train.string_input_producer(
          [style_dataset_file],
          shuffle=False,
          capacity=1,
          name='filename_queue')
      if shuffle:
        examples_queue = tf.RandomShuffleQueue(
            capacity=64,
            min_after_dequeue=32,
            dtypes=[tf.string],
            name='random_examples_queue')
      else:
        examples_queue = tf.FIFOQueue(
            capacity=64, dtypes=[tf.string], name='fifo_examples_queue')
      reader = tf.TFRecordReader()
      _, value = reader.read(filename_queue)
      enqueue_ops = [examples_queue.enqueue([value])]
      tf.train.queue_runner.add_queue_runner(
          tf.train.queue_runner.QueueRunner(examples_queue, enqueue_ops))
      example_serialized = examples_queue.dequeue()
      features = tf.parse_single_example(
          example_serialized,
          features={
              'label': tf.FixedLenFeature([], tf.int64),
              'image_raw': tf.FixedLenFeature([], tf.string)
          })
      image = tf.image.decode_jpeg(features['image_raw'])
      image.set_shape([None, None, 3])
      label = features['label']

      if image_size is not None:
        image_channels = int(image.shape[2])
        if augment_style_images:
          image_orig = image
          image = tf.image.random_brightness(image, max_delta=0.8)
          image = tf.image.random_saturation(image, lower=0.5, upper=1.5)
          image = tf.image.random_hue(image, max_delta=0.2)
          image = tf.image.random_flip_left_right(image)
          image = tf.image.random_flip_up_down(image)
          random_larger_image_size = tf.random_uniform(
              [],
              minval=image_size + 2,
              maxval=image_size + 200,
              dtype=tf.int32)
          image = _aspect_preserving_resize(image, random_larger_image_size)
          image = tf.random_crop(
              image, size=[image_size, image_size, image_channels])
          image.set_shape([image_size, image_size, image_channels])

          image_orig = _aspect_preserving_resize(image_orig, image_size + 2)
          image_orig = _central_crop([image_orig], image_size, image_size)[0]
          image_orig.set_shape([image_size, image_size, 3])
        elif center_crop:
          image = _aspect_preserving_resize(image, image_size + 2)
          image = _central_crop([image], image_size, image_size)[0]
          image.set_shape([image_size, image_size, image_channels])
          image_orig = image
        else:
          image = _aspect_preserving_resize(image, image_size)
          image_orig = image

      image = tf.to_float(image) / 255.0
      image_orig = tf.to_float(image_orig) / 255.0

      if batch_size is None:
        image = tf.expand_dims(image, 0)
      else:
        [image, image_orig, label] = tf.train.batch(
            [image, image_orig, label], batch_size=batch_size)

      if random_style_image_size:
        # Selects a random size for the style images and resizes all the images
        # in the batch to that size.
        image = _aspect_preserving_resize(image,
                                          tf.random_uniform(
                                              [],
                                              minval=min_rand_image_size,
                                              maxval=max_rand_image_size,
                                              dtype=tf.int32))

      return image, label, image_orig
def arbitrary_style_image_inputs ( style_dataset_file , batch_size = None , image_size = None , center_crop = True , shuffle = True , augment_style_images = False , random_style_image_size = False , min_rand_image_size = 128 , max_rand_image_size = 300 ) : if center_crop and image_size is None : raise ValueError ( 'center-cropping requires specifying the image size.' ) if center_crop and augment_style_images : raise ValueError ( 'When augment_style_images is true images will be randomly cropped.' ) if batch_size is not None and not center_crop and not augment_style_images : raise ValueError ( 'batching requires same image sizes (Set center-cropping or ' 'augment_style_images to true)' ) with tf . name_scope ( 'style_image_processing' ) : # Force all input processing onto CPU in order to reserve the GPU for the # forward inference and back-propagation. with tf . device ( '/cpu:0' ) : filename_queue = tf . train . string_input_producer ( [ style_dataset_file ] , shuffle = False , capacity = 1 , name = 'filename_queue' ) if shuffle : examples_queue = tf . RandomShuffleQueue ( capacity = 64 , min_after_dequeue = 32 , dtypes = [ tf . string ] , name = 'random_examples_queue' ) else : examples_queue = tf . FIFOQueue ( capacity = 64 , dtypes = [ tf . string ] , name = 'fifo_examples_queue' ) reader = tf . TFRecordReader ( ) _ , value = reader . read ( filename_queue ) enqueue_ops = [ examples_queue . enqueue ( [ value ] ) ] tf . train . queue_runner . add_queue_runner ( tf . train . queue_runner . QueueRunner ( examples_queue , enqueue_ops ) ) example_serialized = examples_queue . dequeue ( ) features = tf . parse_single_example ( example_serialized , features = { 'label' : tf . FixedLenFeature ( [ ] , tf . int64 ) , 'image_raw' : tf . FixedLenFeature ( [ ] , tf . string ) } ) image = tf . image . decode_jpeg ( features [ 'image_raw' ] ) image . set_shape ( [ None , None , 3 ] ) label = features [ 'label' ] if image_size is not None : image_channels = int ( image . shape [ 2 ] ) if augment_style_images : image_orig = image image = tf . image . random_brightness ( image , max_delta = 0.8 ) image = tf . image . random_saturation ( image , lower = 0.5 , upper = 1.5 ) image = tf . image . random_hue ( image , max_delta = 0.2 ) image = tf . image . random_flip_left_right ( image ) image = tf . image . random_flip_up_down ( image ) random_larger_image_size = tf . random_uniform ( [ ] , minval = image_size + 2 , maxval = image_size + 200 , dtype = tf . int32 ) image = _aspect_preserving_resize ( image , random_larger_image_size ) image = tf . random_crop ( image , size = [ image_size , image_size , image_channels ] ) image . set_shape ( [ image_size , image_size , image_channels ] ) image_orig = _aspect_preserving_resize ( image_orig , image_size + 2 ) image_orig = _central_crop ( [ image_orig ] , image_size , image_size ) [ 0 ] image_orig . set_shape ( [ image_size , image_size , 3 ] ) elif center_crop : image = _aspect_preserving_resize ( image , image_size + 2 ) image = _central_crop ( [ image ] , image_size , image_size ) [ 0 ] image . set_shape ( [ image_size , image_size , image_channels ] ) image_orig = image else : image = _aspect_preserving_resize ( image , image_size ) image_orig = image image = tf . to_float ( image ) / 255.0 image_orig = tf . to_float ( image_orig ) / 255.0 if batch_size is None : image = tf . expand_dims ( image , 0 ) else : [ image , image_orig , label ] = tf . train . batch ( [ image , image_orig , label ] , batch_size = batch_size ) if random_style_image_size : # Selects a random size for the style images and resizes all the images # in the batch to that size. image = _aspect_preserving_resize ( image , tf . random_uniform ( [ ] , minval = min_rand_image_size , maxval = max_rand_image_size , dtype = tf . int32 ) ) return image , label , image_orig