def load_data(csv, batch_size, shuffle = True, distored = True):
queue = tf.train.string_input_producer(csv, shuffle=shuffle)
reader = tf.TextLineReader()
key, value = reader.read(queue)
filename, label = tf.decode_csv(value, [["path"],[1]], field_delim=" ")
label = tf.cast(label, tf.int64)
label = tf.one_hot(label, depth = get_count_member(), on_value = 1.0, off_value = 0.0, axis = -1)
jpeg = tf.read_file(filename)
image = tf.image.decode_jpeg(jpeg, channels=3)
image = tf.cast(image, tf.float32)
image.set_shape([IMAGE_SIZE, IMAGE_SIZE, 3])
if distored:
cropsize = random.randint(INPUT_SIZE, INPUT_SIZE + (IMAGE_SIZE - INPUT_SIZE) / 2)
framesize = INPUT_SIZE + (cropsize - INPUT_SIZE) * 2
image = tf.image.resize_image_with_crop_or_pad(image, framesize, framesize)
image = tf.random_crop(image, [cropsize, cropsize, 3])
image = tf.image.random_flip_left_right(image)
image = tf.image.random_brightness(image, max_delta=0.8)
image = tf.image.random_contrast(image, lower=0.8, upper=1.0)
image = tf.image.random_hue(image, max_delta=0.04)
image = tf.image.random_saturation(image, lower=0.6, upper=1.4)
image = tf.image.resize_images(image, DST_INPUT_SIZE, DST_INPUT_SIZE)
image = tf.image.per_image_whitening(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)
return _generate_image_and_label_batch(
image,
label,
filename,
min_queue_examples, batch_size,
shuffle=shuffle)
评论列表
文章目录