(style_dataset_file, batch_size=None, image_size=None,
                       square_crop=False, shuffle=True)
Loads a batch of random style image given the path of tfrecord dataset.

  Args:
    style_dataset_file: str, path to the tfrecord dataset of style files.
        The dataset is produced via the create_style_dataset.py script and is
        made of Example protobufs with the following features:
        * 'image_raw': byte encoding of the JPEG string of the style image.
        * 'label': integer identifier of the style image in [0, N - 1], where
              N is the number of examples in the dataset.
        * 'vgg_16/<LAYER_NAME>': Gram matrix at layer <LAYER_NAME> of the VGG-16
              network (<LAYER_NAME> in {conv,pool}{1,2,3,4,5}) for the style
              image.
    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.
    square_crop: bool. If True, square-crops to [image_size, image_size].
        Defaults to False.
    shuffle: bool, whether to shuffle style files at random. Defaults to True.

  Returns:
    If batch_size is defined, a 4-D tensor of shape [batch_size, ?, ?, 3] with
    values in [0, 1] for the style image, and 1-D tensor for the style label.

  Raises:
    ValueError: if center cropping is requested but no image size is provided,
        or if batch size is specified but center-cropping is not 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 style_image_inputs(style_dataset_file, batch_size=None, image_size=None,
                       square_crop=False, shuffle=True):
  """Loads a batch of random style image given the path of tfrecord dataset.

  Args:
    style_dataset_file: str, path to the tfrecord dataset of style files.
        The dataset is produced via the create_style_dataset.py script and is
        made of Example protobufs with the following features:
        * 'image_raw': byte encoding of the JPEG string of the style image.
        * 'label': integer identifier of the style image in [0, N - 1], where
              N is the number of examples in the dataset.
        * 'vgg_16/<LAYER_NAME>': Gram matrix at layer <LAYER_NAME> of the VGG-16
              network (<LAYER_NAME> in {conv,pool}{1,2,3,4,5}) for the style
              image.
    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.
    square_crop: bool. If True, square-crops to [image_size, image_size].
        Defaults to False.
    shuffle: bool, whether to shuffle style files at random. Defaults to True.

  Returns:
    If batch_size is defined, a 4-D tensor of shape [batch_size, ?, ?, 3] with
    values in [0, 1] for the style image, and 1-D tensor for the style label.

  Raises:
    ValueError: if center cropping is requested but no image size is provided,
        or if batch size is specified but center-cropping is not requested.
  """
  vgg_layers = ['vgg_16/conv1', 'vgg_16/pool1', 'vgg_16/conv2', 'vgg_16/pool2',
                'vgg_16/conv3', 'vgg_16/pool3', 'vgg_16/conv4', 'vgg_16/pool4',
                'vgg_16/conv5', 'vgg_16/pool5']

  if square_crop and image_size is None:
    raise ValueError('center-cropping requires specifying the image size.')
  if batch_size is not None and not square_crop:
    raise ValueError('batching requires center-cropping.')

  with tf.name_scope('style_image_processing'):
    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),
                  'vgg_16/conv1': tf.FixedLenFeature([64, 64], tf.float32),
                  'vgg_16/pool1': tf.FixedLenFeature([64, 64], tf.float32),
                  'vgg_16/conv2': tf.FixedLenFeature([128, 128], tf.float32),
                  'vgg_16/pool2': tf.FixedLenFeature([128, 128], tf.float32),
                  'vgg_16/conv3': tf.FixedLenFeature([256, 256], tf.float32),
                  'vgg_16/pool3': tf.FixedLenFeature([256, 256], tf.float32),
                  'vgg_16/conv4': tf.FixedLenFeature([512, 512], tf.float32),
                  'vgg_16/pool4': tf.FixedLenFeature([512, 512], tf.float32),
                  'vgg_16/conv5': tf.FixedLenFeature([512, 512], tf.float32),
                  'vgg_16/pool5': tf.FixedLenFeature([512, 512], tf.float32)})
    image = tf.image.decode_jpeg(features['image_raw'])
    label = features['label']
    gram_matrices = [features[vgg_layer] for vgg_layer in vgg_layers]
    image.set_shape([None, None, 3])

    if image_size:
      if square_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, 3])
      else:
        image = _aspect_preserving_resize(image, image_size)

    image = tf.to_float(image) / 255.0

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

    gram_matrices = dict((vgg_layer, gram_matrix)
                         for vgg_layer, gram_matrix
                         in zip(vgg_layers, gram_matrices))
    return image, label, gram_matrices
def style_image_inputs ( style_dataset_file , batch_size = None , image_size = None , square_crop = False , shuffle = True ) : vgg_layers = [ 'vgg_16/conv1' , 'vgg_16/pool1' , 'vgg_16/conv2' , 'vgg_16/pool2' , 'vgg_16/conv3' , 'vgg_16/pool3' , 'vgg_16/conv4' , 'vgg_16/pool4' , 'vgg_16/conv5' , 'vgg_16/pool5' ] if square_crop and image_size is None : raise ValueError ( 'center-cropping requires specifying the image size.' ) if batch_size is not None and not square_crop : raise ValueError ( 'batching requires center-cropping.' ) with tf . name_scope ( 'style_image_processing' ) : 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 ) , 'vgg_16/conv1' : tf . FixedLenFeature ( [ 64 , 64 ] , tf . float32 ) , 'vgg_16/pool1' : tf . FixedLenFeature ( [ 64 , 64 ] , tf . float32 ) , 'vgg_16/conv2' : tf . FixedLenFeature ( [ 128 , 128 ] , tf . float32 ) , 'vgg_16/pool2' : tf . FixedLenFeature ( [ 128 , 128 ] , tf . float32 ) , 'vgg_16/conv3' : tf . FixedLenFeature ( [ 256 , 256 ] , tf . float32 ) , 'vgg_16/pool3' : tf . FixedLenFeature ( [ 256 , 256 ] , tf . float32 ) , 'vgg_16/conv4' : tf . FixedLenFeature ( [ 512 , 512 ] , tf . float32 ) , 'vgg_16/pool4' : tf . FixedLenFeature ( [ 512 , 512 ] , tf . float32 ) , 'vgg_16/conv5' : tf . FixedLenFeature ( [ 512 , 512 ] , tf . float32 ) , 'vgg_16/pool5' : tf . FixedLenFeature ( [ 512 , 512 ] , tf . float32 ) } ) image = tf . image . decode_jpeg ( features [ 'image_raw' ] ) label = features [ 'label' ] gram_matrices = [ features [ vgg_layer ] for vgg_layer in vgg_layers ] image . set_shape ( [ None , None , 3 ] ) if image_size : if square_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 , 3 ] ) else : image = _aspect_preserving_resize ( image , image_size ) image = tf . to_float ( image ) / 255.0 if batch_size is None : image = tf . expand_dims ( image , 0 ) else : image_label_gram_matrices = tf . train . batch ( [ image , label ] + gram_matrices , batch_size = batch_size ) image , label = image_label_gram_matrices [ : 2 ] gram_matrices = image_label_gram_matrices [ 2 : ] gram_matrices = dict ( ( vgg_layer , gram_matrix ) for vgg_layer , gram_matrix in zip ( vgg_layers , gram_matrices ) ) return image , label , gram_matrices