Exemplo n.º 1
0
def inputs(eval_data):
    """
    Construct input for captcha evaluation using the Reader ops.

    Args:
        eval_data: bool, indicating if one should use the train or eval data set.

    Raises:
        ValueError: if no data_dir

    Returns:
        images: Images. 4D tensor of [batch_size, IMAGE_SIZE[0], IMAGE_SIZE[1], 1] size.
        labels: Labels. 2D tensor of [batch_size, 6] size.
    """

    if not eval_data:
        filenames = TRAIN_FNAMES
        num_examples_per_epoch = NUM_EXAMPLES_PER_EPOCH_FOR_TRAIN
        print("Using files {} for training".format(TRAIN_FNAMES))
    else:
        filenames = TEST_FNAMES
        num_examples_per_epoch = NUM_EXAMPLES_PER_EPOCH_FOR_EVAL
        print("Using files {} for testing".format(TEST_FNAMES))

    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.
    key, string = input_data.read_string(filename_queue, FULL_IMAGE_SIZE,
                                         NUM_CHANNELS, LABEL_BYTES, NUM_LABELS)
    labels, im = input_data.string_to_data_multilabel(string, NUM_LABELS,
                                                      FULL_IMAGE_SIZE,
                                                      NUM_CHANNELS,
                                                      LABEL_BYTES)
    reshaped_image = tf.cast(im, tf.float32)

    height = IMAGE_SIZE[0]
    width = IMAGE_SIZE[1]

    # Image processing for evaluation.
    # Crop the central [height, width] of the image.
    resized_image = tf.image.resize_image_with_crop_or_pad(
        reshaped_image, height, width)

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

    # Ensure that the random shuffling has good mixing properties.
    min_fraction_of_examples_in_queue = 0.04
    min_queue_examples = int(num_examples_per_epoch *
                             min_fraction_of_examples_in_queue)

    # Generate a batch of images and labels by building up a queue of examples.
    return _generate_image_and_label_batch(float_image, labels,
                                           min_queue_examples)
def inputs(eval_data):
    """
    Construct input for captcha evaluation using the Reader ops.

    Args:
        eval_data: bool, indicating if one should use the train or eval data set.

    Raises:
        ValueError: if no data_dir

    Returns:
        images: Images. 4D tensor of [batch_size, IMAGE_SIZE[0], IMAGE_SIZE[1], 1] size.
        labels: Labels. 2D tensor of [batch_size, 6] size.
    """

    if not eval_data:
        filenames = TRAIN_FNAMES
        num_examples_per_epoch = NUM_EXAMPLES_PER_EPOCH_FOR_TRAIN
        print("Using files {} for training".format(TRAIN_FNAMES))
    else:
        filenames = TEST_FNAMES
        num_examples_per_epoch = NUM_EXAMPLES_PER_EPOCH_FOR_EVAL
        print("Using files {} for testing".format(TEST_FNAMES))

    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.
    key, string = input_data.read_string(filename_queue, FULL_IMAGE_SIZE, NUM_CHANNELS, LABEL_BYTES, NUM_LABELS)
    labels, im = input_data.string_to_data_multilabel(string, NUM_LABELS, FULL_IMAGE_SIZE, NUM_CHANNELS, LABEL_BYTES)
    reshaped_image = tf.cast(im, tf.float32)

    height = IMAGE_SIZE[0]
    width = IMAGE_SIZE[1]

    # Image processing for evaluation.
    # Crop the central [height, width] of the image.
    resized_image = tf.image.resize_image_with_crop_or_pad(reshaped_image,
                                                           height, width)

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

    # Ensure that the random shuffling has good mixing properties.
    min_fraction_of_examples_in_queue = 0.04
    min_queue_examples = int(num_examples_per_epoch *
                             min_fraction_of_examples_in_queue)

    # Generate a batch of images and labels by building up a queue of examples.
    return _generate_image_and_label_batch(float_image, labels,
                                           min_queue_examples)
Exemplo n.º 3
0
def distorted_inputs():
    """
    Construct distorted input for captcha training using the Reader ops.

    Raises:
        ValueError: if no data_dir

    Returns:
        images: Images. 4D tensor of [batch_size, IMAGE_SIZE[0], IMAGE_SIZE[1], 1] size.
        labels: Labels. 2D tensor of [batch_size, 6] size.
    """
    filenames = TRAIN_FNAMES

    for f in filenames:
        if not gfile.Exists(f):
            raise ValueError('Failed to find file: ' + f)
    print("Using files {} for training".format(TRAIN_FNAMES))

    # 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.
    key, string = input_data.read_string(filename_queue, FULL_IMAGE_SIZE,
                                         NUM_CHANNELS, LABEL_BYTES, NUM_LABELS)
    labels, im = input_data.string_to_data_multilabel(string, NUM_LABELS,
                                                      FULL_IMAGE_SIZE,
                                                      NUM_CHANNELS,
                                                      LABEL_BYTES)
    reshaped_image = tf.cast(im, tf.float32)

    height = IMAGE_SIZE[0]
    width = IMAGE_SIZE[1]

    # Randomly crop a [height, width] section of the image.
    distorted_image = tf.image.random_crop(reshaped_image, [height, width])

    distorted_image = tf.image.random_brightness(distorted_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.1
    min_queue_examples = int(NUM_EXAMPLES_PER_EPOCH_FOR_TRAIN *
                             min_fraction_of_examples_in_queue)
    print('Filling queue with %d 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, labels,
                                           min_queue_examples)
def distorted_inputs():
    """
    Construct distorted input for captcha training using the Reader ops.

    Raises:
        ValueError: if no data_dir

    Returns:
        images: Images. 4D tensor of [batch_size, IMAGE_SIZE[0], IMAGE_SIZE[1], 1] size.
        labels: Labels. 2D tensor of [batch_size, 6] size.
    """
    filenames = TRAIN_FNAMES

    for f in filenames:
        if not gfile.Exists(f):
            raise ValueError('Failed to find file: ' + f)
    print("Using files {} for training".format(TRAIN_FNAMES))

    # 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.
    key, string = input_data.read_string(filename_queue, FULL_IMAGE_SIZE, NUM_CHANNELS, LABEL_BYTES, NUM_LABELS)
    labels, im = input_data.string_to_data_multilabel(string, NUM_LABELS, FULL_IMAGE_SIZE, NUM_CHANNELS, LABEL_BYTES)
    reshaped_image = tf.cast(im, tf.float32)

    height = IMAGE_SIZE[0]
    width = IMAGE_SIZE[1]

    # Randomly crop a [height, width] section of the image.
    distorted_image = tf.image.random_crop(reshaped_image, [height, width])

    distorted_image = tf.image.random_brightness(distorted_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.1
    min_queue_examples = int(NUM_EXAMPLES_PER_EPOCH_FOR_TRAIN *
                             min_fraction_of_examples_in_queue)
    print ('Filling queue with %d 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, labels,
                                           min_queue_examples)