Exemple #1
0
def inputs():
    filenames = [os.path.join(FLAGS.test_dir, FLAGS.test_file)]
    for f in filenames:
        if not gfile.Exists(f):
            raise ValueError('Failed to find file: ' + f)
    filename_queue = tf.train.string_input_producer(filenames, shuffle=False)
    read_input = svhn_input.read_cifar10(filename_queue)
    reshaped_image = tf.cast(read_input.uint8image, tf.float32)
    height = FLAGS.image_size
    width = FLAGS.image_size
    float_image = tf.image.per_image_whitening(reshaped_image)
    num_preprocess_threads = 1
    images, label_batch = tf.train.batch([float_image, read_input.label],
                                         batch_size=FLAGS.batch_size,
                                         num_threads=num_preprocess_threads,
                                         capacity=FLAGS.batch_size)
    tf.image_summary('images', images, max_images=29)
    return images, tf.reshape(label_batch, [FLAGS.batch_size])
Exemple #2
0
def inputs():
    filenames = [os.path.join(FLAGS.test_dir, FLAGS.test_file)]
    for f in filenames:
        if not gfile.Exists(f):
            raise ValueError("Failed to find file: " + f)
    filename_queue = tf.train.string_input_producer(filenames, shuffle=False)
    read_input = svhn_input.read_cifar10(filename_queue)
    reshaped_image = tf.cast(read_input.uint8image, tf.float32)
    height = FLAGS.image_size
    width = FLAGS.image_size
    float_image = tf.image.per_image_whitening(reshaped_image)
    num_preprocess_threads = 1
    images, label_batch = tf.train.batch(
        [float_image, read_input.label],
        batch_size=FLAGS.batch_size,
        num_threads=num_preprocess_threads,
        capacity=FLAGS.batch_size,
    )
    tf.image_summary("images", images, max_images=29)
    return images, tf.reshape(label_batch, [FLAGS.batch_size])
Exemple #3
0
def distorted_inputs():
    """Construct distorted input for CIFAR training using the Reader ops.

  Raises:
    ValueError: if no data_dir

  Returns:
    images: Images. 4D tensor of [batch_size, IMAGE_SIZE, IMAGE_SIZE, 3] size.
    labels: Labels. 1D tensor of [batch_size] size.
  """
    # filenames = [os.path.join(FLAGS.data_dir, 'data_batch_%d.bin' % i) for i in xrange(1, 7)]
    filenames = [os.path.join(FLAGS.data_dir, 'train_batch.bin')]
    for f in filenames:
        if not gfile.Exists(f):
            raise ValueError('Failed to find file: ' + f)

    # Create a queue that produces the filenames to read.
    filename_queue = tf.train.string_input_producer(filenames)

    # Read examples from files in the filename queue.
    read_input = svhn_input.read_cifar10(filename_queue)
    reshaped_image = tf.cast(read_input.uint8image, tf.float32)
    distorted_image = tf.image.random_brightness(reshaped_image, max_delta=63)
    distorted_image = tf.image.random_contrast(distorted_image,
                                               lower=0.2,
                                               upper=1.8)

    # Subtract off the mean and divide by the variance of the pixels.
    float_image = tf.image.per_image_whitening(distorted_image)

    # Ensure that the random shuffling has good mixing properties.
    min_fraction_of_examples_in_queue = 0.4
    min_queue_examples = int(NUM_EXAMPLES_PER_EPOCH_FOR_TRAIN *
                             min_fraction_of_examples_in_queue)
    print('Filling queue with %d SVHN images before starting to train. '
          'This will take a few minutes.' % min_queue_examples)

    # Generate a batch of images and labels by building up a queue of examples.
    return _generate_image_and_label_batch(float_image, read_input.label,
                                           min_queue_examples)
Exemple #4
0
def distorted_inputs():
  """Construct distorted input for CIFAR training using the Reader ops.

  Raises:
    ValueError: if no data_dir

  Returns:
    images: Images. 4D tensor of [batch_size, IMAGE_SIZE, IMAGE_SIZE, 3] size.
    labels: Labels. 1D tensor of [batch_size] size.
  """
  # filenames = [os.path.join(FLAGS.data_dir, 'data_batch_%d.bin' % i) for i in xrange(1, 7)]
  filenames = [os.path.join(FLAGS.data_dir,'train_batch.bin')]
  for f in filenames:
    if not gfile.Exists(f):
      raise ValueError('Failed to find file: ' + f)

  # Create a queue that produces the filenames to read.
  filename_queue = tf.train.string_input_producer(filenames)

  # Read examples from files in the filename queue.
  read_input = svhn_input.read_cifar10(filename_queue)
  reshaped_image = tf.cast(read_input.uint8image, tf.float32)
  distorted_image = tf.image.random_brightness(reshaped_image,
                                               max_delta=63)
  distorted_image = tf.image.random_contrast(distorted_image,
                                             lower=0.2, upper=1.8)

  # Subtract off the mean and divide by the variance of the pixels.
  float_image = tf.image.per_image_whitening(distorted_image)

  # Ensure that the random shuffling has good mixing properties.
  min_fraction_of_examples_in_queue = 0.4
  min_queue_examples = int(NUM_EXAMPLES_PER_EPOCH_FOR_TRAIN *
                           min_fraction_of_examples_in_queue)
  print ('Filling queue with %d SVHN images before starting to train. '
         'This will take a few minutes.' % min_queue_examples)

  # Generate a batch of images and labels by building up a queue of examples.
  return _generate_image_and_label_batch(float_image, read_input.label,
                                         min_queue_examples)