def read_input(image_queue):
# Read the images and generate the decode from PNG image
imageReader = tf.WholeFileReader()
image_key, image_value = imageReader.read(image_queue)
image_decode = tf.image.decode_png(image_value, channels=1)
image_decode = tf.cast(image_decode, tf.float32)
# Preprocess data
image_key = rename_image_filename(image_key) # rename image filename
label = search_label(image_key)
# CREATE OBJECT
class Record(object):
pass
record = Record()
# Instantiate object
record.key = image_key
record.label = tf.cast(label, tf.int32)
record.image = image_decode
# PROCESSING IMAGES
# reshaped_image = tf.cast(record.image, tf.float32)
# height = 245
# width = 320
height = 96
width = 96
# Image processing for training the network. Note the many random distortions applied to the image.
# Randomly crop a [height, width] section of the image.
distorted_image = tf.random_crop(record.image, [height, width, 1])
# Randomly flip the image horizontally.
distorted_image = tf.image.random_flip_left_right(distorted_image)
# Because these operations are not commutative, consider randomizing randomize the order their operation.
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)
return generate_train_batch(record.label, float_image)
评论列表
文章目录