def _abspath_no_label_load_file(path, epochs=None, shuffle=True, seed=0):
filename_queue = tf.train.string_input_producer([path],
num_epochs=epochs, shuffle=shuffle, seed=seed)
reader = tf.TextLineReader()
key, value = reader.read(filename_queue)
#image_path, = tf.decode_csv(value, record_defaults=[['']], field_delim=' ')
image_path = value
image_abspath = image_path
image_content = tf.read_file(image_abspath)
image = decode_image(image_content, channels=3)
image.set_shape([None, None, 3])
imgshape = tf.shape(image)[:2]
return image, imgshape, image_path
python类read_file()的实例源码
def read_tensor_from_image_file(file_name='test.jpg', input_height=128, input_width=128,
input_mean=0, input_std=255):
input_name = "file_reader"
output_name = "normalized"
file_reader = tf.read_file(file_name, input_name)
image_reader = tf.image.decode_jpeg(file_reader, channels = 3, name='jpeg_reader')
float_caster = tf.cast(image_reader, tf.float32)
dims_expander = tf.expand_dims(float_caster, 0);
resized = tf.image.resize_bilinear(dims_expander, [input_height, input_width])
normalized = tf.divide(tf.subtract(resized, [input_mean]), [input_std])
sess = tf.Session()
result = sess.run(normalized)
return result
def image_reading(path: str, resized_size: Tuple[int, int]=None, data_augmentation: bool=False,
padding: bool=False) -> Tuple[tf.Tensor, tf.Tensor]:
# Read image
image_content = tf.read_file(path, name='image_reader')
image = tf.cond(tf.equal(tf.string_split([path], '.').values[1], tf.constant('jpg', dtype=tf.string)),
true_fn=lambda: tf.image.decode_jpeg(image_content, channels=1, try_recover_truncated=True), # TODO channels = 3 ?
false_fn=lambda: tf.image.decode_png(image_content, channels=1), name='image_decoding')
# Data augmentation
if data_augmentation:
image = augment_data(image)
# Padding
if padding:
with tf.name_scope('padding'):
image, img_width = padding_inputs_width(image, resized_size, increment=CONST.DIMENSION_REDUCTION_W_POOLING)
# Resize
else:
image = tf.image.resize_images(image, size=resized_size)
img_width = tf.shape(image)[1]
with tf.control_dependencies([tf.assert_equal(image.shape[:2], resized_size)]):
return image, img_width
def read_image_and_label(image_label_q):
# Returns three Tensors: the decoded PNG image, the hour, and the minute.
filename, hour_str, minute_str = tf.decode_csv(
image_label_q.dequeue(), [[""], [""], [""]], " ")
file_contents = tf.read_file(filename)
# Decode image from PNG, and cast it to a float.
example = tf.image.decode_png(file_contents, channels=image_channels)
image = tf.cast(example, tf.float32)
# Set the tensor size manually from the image.
image.set_shape([image_size, image_size, image_channels])
# Do per-image whitening (zero mean, unit standard deviation). Without this,
# the learning algorithm diverges almost immediately because the gradient is
# too big.
image = tf.image.per_image_whitening(image)
# The label should be an integer.
hour = tf.string_to_number(hour_str, out_type=tf.int32)
minute = tf.string_to_number(minute_str, out_type=tf.int32)
return image, hour, minute
def tf_ops(self, capacity=32, produce_filenames=False):
im_path, label_path = tf.train.slice_input_producer(
[tf.constant(self.images), tf.constant(self.labels)],
capacity=capacity,
shuffle=self.shuffle)
im = tf.read_file(im_path)
im = tf.image.decode_image(im, channels=3)
im = tf.cast(im, tf.float32)
im.set_shape((1024, 2048, 3))
label = tf.read_file(label_path)
label = tf.image.decode_image(label, channels=1)
label = label[:, :, 0]
label = tf.cast(label, tf.int32)
label.set_shape((1024, 2048))
if produce_filenames:
return im, label, im_path, label_path
else:
return im, label
def read_tensor_from_image_file(file_name, input_height=299, input_width=299,
input_mean=0, input_std=255):
input_name = "file_reader"
output_name = "normalized"
file_reader = tf.read_file(file_name, input_name)
if file_name.endswith(".png"):
image_reader = tf.image.decode_png(file_reader, channels = 3,
name='png_reader')
elif file_name.endswith(".gif"):
image_reader = tf.squeeze(tf.image.decode_gif(file_reader,
name='gif_reader'))
elif file_name.endswith(".bmp"):
image_reader = tf.image.decode_bmp(file_reader, name='bmp_reader')
else:
image_reader = tf.image.decode_jpeg(file_reader, channels = 3,
name='jpeg_reader')
float_caster = tf.cast(image_reader, tf.float32)
dims_expander = tf.expand_dims(float_caster, 0);
resized = tf.image.resize_bilinear(dims_expander, [input_height, input_width])
normalized = tf.divide(tf.subtract(resized, [input_mean]), [input_std])
sess = tf.Session()
result = sess.run(normalized)
return result
def decode(self, filename, distort_data, whiten_data = True):
"""distort: random distort the iamge"""
image_tensor = tf.read_file(filename)
image_tensor = self.decode_fun(image_tensor, channels = self.channels, ratio = self.ratio)
image_tensor = tf.image.convert_image_dtype(image_tensor, tf.float32)
image_tensor = tf.image.resize_images(image_tensor,
[self.shape[0] + self.offset, self.shape[1] + self.offset])
if distort_data:
# it will crop in the function
image_tensor = self.distort_op(image_tensor)
else:
image_tensor = tf.image.resize_image_with_crop_or_pad(image_tensor,
self.shape[0], self.shape[1])
if whiten_data:
# Subtract off the mean and divide by the variance of the pixels.
image_tensor = tf.image.per_image_whitening(image_tensor)
return image_tensor
def decode(self, filename, distort_data, whiten_data = True):
"""distort: random distort the iamge"""
image_tensor = tf.read_file(filename)
image_tensor = self.decode_fun(image_tensor, channels = self.channels, ratio = self.ratio)
image_tensor = tf.image.convert_image_dtype(image_tensor, tf.float32)
image_tensor = tf.image.resize_images(image_tensor,
[self.shape[0] + self.offset, self.shape[1] + self.offset])
if distort_data:
# it will crop in the function
image_tensor = self.distort_op(image_tensor)
else:
image_tensor = tf.image.resize_image_with_crop_or_pad(image_tensor,
self.shape[0], self.shape[1])
if whiten_data:
# Subtract off the mean and divide by the variance of the pixels.
image_tensor = tf.image.per_image_whitening(image_tensor)
return image_tensor
def read_image(self, image_path):
# tf.decode_image does not return the image size, this is an ugly workaround to handle both jpeg and png
path_length = string_length_tf(image_path)[0]
file_extension = tf.substr(image_path, path_length - 3, 3)
file_cond = tf.equal(file_extension, 'jpg')
image = tf.cond(file_cond, lambda: tf.image.decode_jpeg(tf.read_file(image_path)), lambda: tf.image.decode_png(tf.read_file(image_path)))
# if the dataset is cityscapes, we crop the last fifth to remove the car hood
if self.dataset == 'cityscapes':
o_height = tf.shape(image)[0]
crop_height = (o_height * 4) / 5
image = image[:crop_height,:,:]
image = tf.image.convert_image_dtype(image, tf.float32)
image = tf.image.resize_images(image, [self.params.height, self.params.width], tf.image.ResizeMethod.AREA)
return image
def read_data(prefix, labels_dic, mixing, files_from_cl):
image_list = sorted(map(lambda x: os.path.join(prefix, x),
filter(lambda x: x.endswith('JPEG'), files_from_cl)))
prefix2 = []
for file_i in image_list:
tmp = file_i.split(prefix+'/')[1].split("_")[0]
prefix2.append(tmp)
prefix2 = np.array(prefix2)
labels_list = np.array([mixing[labels_dic[i]] for i in prefix2])
assert(len(image_list) == len(labels_list))
images = tf.convert_to_tensor(image_list, dtype=tf.string)
labels = tf.convert_to_tensor(labels_list, dtype=tf.int32)
input_queue = tf.train.slice_input_producer([images, labels], shuffle=True, capacity=2000)
image_file_content = tf.read_file(input_queue[0])
label = input_queue[1]
image = tf.image.resize_images(tf.image.decode_jpeg(image_file_content, channels=3), [256, 256])
image = tf.random_crop(image, [224, 224, 3])
image = tf.image.random_flip_left_right(image)
return image, label
def read_tensor_from_image_file(file_name, input_height=299, input_width=299,
input_mean=0, input_std=255):
input_name = "file_reader"
output_name = "normalized"
file_reader = tf.read_file(file_name, input_name)
if file_name.endswith(".png"):
image_reader = tf.image.decode_png(file_reader, channels = 3,
name='png_reader')
elif file_name.endswith(".gif"):
image_reader = tf.squeeze(tf.image.decode_gif(file_reader,
name='gif_reader'))
elif file_name.endswith(".bmp"):
image_reader = tf.image.decode_bmp(file_reader, name='bmp_reader')
else:
image_reader = tf.image.decode_jpeg(file_reader, channels = 3,
name='jpeg_reader')
float_caster = tf.cast(image_reader, tf.float32)
dims_expander = tf.expand_dims(float_caster, 0);
resized = tf.image.resize_bilinear(dims_expander, [input_height, input_width])
normalized = tf.divide(tf.subtract(resized, [input_mean]), [input_std])
sess = tf.Session()
result = sess.run(normalized)
return result
def get_feature_vectors_from_files(self, image_paths):
# Decode image
with self.graph.as_default():
image_path = tf.placeholder(tf.string, None, 'image_path')
image = tf.image.decode_jpeg(tf.read_file(image_path))
# Extract features
features = []
with tf.Session(graph=self.graph) as sess:
for path in image_paths:
image_data = sess.run(
image,
{image_path: path}
)
feature_data = sess.run(
self.feature_op,
{INPUT_DATA_TENSOR_NAME: image_data}
)
features.append(feature_data)
return features
def verify_image_jpeg(imagepath, imageshape):
scope = inspect.stack()[0][3]
try:
graph = tf.get_default_graph()
path = graph.get_tensor_by_name(scope + '/path:0')
decode = graph.get_tensor_by_name(scope + '/decode_jpeg:0')
except KeyError:
tf.logging.debug('creating decode_jpeg tensor')
path = tf.placeholder(tf.string, name=scope + '/path')
imagefile = tf.read_file(path, name=scope + '/read_file')
decode = tf.image.decode_jpeg(imagefile, channels=3, name=scope + '/decode_jpeg')
try:
image = tf.get_default_session().run(decode, {path: imagepath})
except:
return False
return np.all(np.equal(image.shape[:2], imageshape[:2]))
def decode_image_objects(paths):
with tf.name_scope(inspect.stack()[0][3]):
with tf.name_scope('parse_example'):
reader = tf.TFRecordReader()
_, serialized = reader.read(tf.train.string_input_producer(paths))
example = tf.parse_single_example(serialized, features={
'imagepath': tf.FixedLenFeature([], tf.string),
'imageshape': tf.FixedLenFeature([3], tf.int64),
'objects': tf.FixedLenFeature([2], tf.string),
})
imagepath = example['imagepath']
objects = example['objects']
with tf.name_scope('decode_objects'):
objects_class = tf.decode_raw(objects[0], tf.int64, name='objects_class')
objects_coord = tf.decode_raw(objects[1], tf.float32)
objects_coord = tf.reshape(objects_coord, [-1, 4], name='objects_coord')
with tf.name_scope('load_image'):
imagefile = tf.read_file(imagepath)
image = tf.image.decode_jpeg(imagefile, channels=3)
return image, example['imageshape'], objects_class, objects_coord
def _voc_seg_load_file(path, epochs=None, shuffle=True, seed=0):
PASCAL_ROOT = os.environ['VOC_DIR']
filename_queue = tf.train.string_input_producer([path],
num_epochs=epochs, shuffle=shuffle, seed=seed)
reader = tf.TextLineReader()
key, value = reader.read(filename_queue)
image_path, seg_path = tf.decode_csv(value, record_defaults=[[''], ['']], field_delim=' ')
image_abspath = PASCAL_ROOT + image_path
seg_abspath = PASCAL_ROOT + seg_path
image_content = tf.read_file(image_abspath)
image = decode_image(image_content, channels=3)
image.set_shape([None, None, 3])
imgshape = tf.shape(image)[:2]
imgname = image_path
seg_content = tf.read_file(seg_abspath)
seg = tf.cast(tf.image.decode_png(seg_content, channels=1), tf.int32)
return image, seg, imgshape, imgname
def _imagenet_load_file(path, epochs=None, shuffle=True, seed=0, subset='train', prepare_path=True):
IMAGENET_ROOT = os.environ.get('IMAGENET_DIR', '')
if not isinstance(path, list):
path = [path]
filename_queue = tf.train.string_input_producer(path,
num_epochs=epochs, shuffle=shuffle, seed=seed)
reader = tf.TextLineReader()
key, value = reader.read(filename_queue)
image_path, label_str = tf.decode_csv(value, record_defaults=[[''], ['']], field_delim=' ')
if prepare_path:
image_abspath = IMAGENET_ROOT + '/images/' + subset + image_path
else:
image_abspath = image_path
image_content = tf.read_file(image_abspath)
image = decode_image(image_content, channels=3)
image.set_shape([None, None, 3])
imgshape = tf.shape(image)[:2]
label = tf.string_to_number(label_str, out_type=tf.int32)
return image, label, imgshape, image_path
def _relpath_no_label_load_file(path, root_path, epochs=None, shuffle=True, seed=0):
filename_queue = tf.train.string_input_producer([path],
num_epochs=epochs, shuffle=shuffle, seed=seed)
reader = tf.TextLineReader()
key, value = reader.read(filename_queue)
#image_path, = tf.decode_csv(value, record_defaults=[['']], field_delim=' ')
image_path = value
image_abspath = root_path + '/' + image_path
image_content = tf.read_file(image_abspath)
image = decode_image(image_content, channels=3)
image.set_shape([None, None, 3])
imgshape = tf.shape(image)[:2]
return image, imgshape, image_path
def CamVid_reader_seq(filename_queue, seq_length):
image_seq_filenames = tf.split(axis=0, num_or_size_splits=seq_length, value=filename_queue[0])
label_seq_filenames = tf.split(axis=0, num_or_size_splits=seq_length, value=filename_queue[1])
image_seq = []
label_seq = []
for im ,la in zip(image_seq_filenames, label_seq_filenames):
imageValue = tf.read_file(tf.squeeze(im))
labelValue = tf.read_file(tf.squeeze(la))
image_bytes = tf.image.decode_png(imageValue)
label_bytes = tf.image.decode_png(labelValue)
image = tf.cast(tf.reshape(image_bytes, (IMAGE_HEIGHT, IMAGE_WIDTH, IMAGE_DEPTH)), tf.float32)
label = tf.cast(tf.reshape(label_bytes, (IMAGE_HEIGHT, IMAGE_WIDTH, 1)), tf.int64)
image_seq.append(image)
label_seq.append(label)
return image_seq, label_seq
def _process(self):
def img_process(fn):
img = tf.image.decode_image(tf.read_file(fn))
cropped = tf.image.resize_image_with_crop_or_pad(img, tf.app.flags.FLAGS.crop_height, tf.app.flags.FLAGS.crop_width)
new_img = tf.image.resize_images(cropped, (tf.app.flags.FLAGS.target_height, tf.app.flags.FLAGS.target_width), method =
tf.image.ResizeMethod.AREA)
return fn, new_img
filenames = tf.constant(glob.glob(os.path.join(self.src_dir,"*")))
dataset = tf.data.Dataset.from_tensor_slices((filenames, ))
dataset = dataset.map(img_process)
dataset = dataset.shuffle(buffer_size=10000)
dataset = dataset.batch(tf.app.flags.FLAGS.batch_size)
dataset = dataset.repeat(tf.app.flags.FLAGS.epochs)
iterator = dataset.make_one_shot_iterator()
labels, imgs = iterator.get_next()
return labels, imgs
def _process(self):
def img_process(fn):
img = tf.image.decode_image(tf.read_file(fn))
cropped = tf.image.resize_image_with_crop_or_pad(img, tf.app.flags.FLAGS.crop_height, tf.app.flags.FLAGS.crop_width)
new_img = tf.image.resize_images(cropped, (tf.app.flags.FLAGS.target_height, tf.app.flags.FLAGS.target_width), method =
tf.image.ResizeMethod.AREA)
return fn, new_img
filenames = tf.constant(glob.glob(os.path.join(self.src_dir,"*")))
dataset = tf.data.Dataset.from_tensor_slices((filenames, ))
dataset = dataset.map(img_process)
dataset = dataset.shuffle(buffer_size=10000)
dataset = dataset.batch(tf.app.flags.FLAGS.batch_size)
dataset = dataset.repeat(tf.app.flags.FLAGS.epochs)
iterator = dataset.make_one_shot_iterator()
labels, imgs = iterator.get_next()
return labels, imgs
def _process(self):
def img_process(fn):
img = tf.image.decode_image(tf.read_file(fn))
cropped = tf.image.resize_image_with_crop_or_pad(img, tf.app.flags.FLAGS.crop_height, tf.app.flags.FLAGS.crop_width)
new_img = tf.image.resize_images(cropped, (tf.app.flags.FLAGS.target_height, tf.app.flags.FLAGS.target_width), method =
tf.image.ResizeMethod.AREA)
return fn, new_img
filenames = tf.constant(glob.glob(os.path.join(self.src_dir,"*")))
dataset = tf.data.Dataset.from_tensor_slices((filenames, ))
dataset = dataset.map(img_process)
dataset = dataset.shuffle(buffer_size=10000)
dataset = dataset.batch(tf.app.flags.FLAGS.batch_size)
dataset = dataset.repeat(tf.app.flags.FLAGS.epochs)
iterator = dataset.make_one_shot_iterator()
labels, imgs = iterator.get_next()
return labels, imgs
def _get_image(self):
_, records = self.reader.read(self.input_queue)
file_names = tf.decode_csv(records, [tf.constant([], tf.string), tf.constant([], tf.string)],
field_delim=None, name=None)
im_raw = tf.read_file(self.base_folder+file_names[0])
seg_raw = tf.read_file(self.base_folder+file_names[1])
image = tf.reshape(
tf.cast(tf.image.decode_png(
im_raw,
channels=1, dtype=tf.uint16),
tf.float32), self.image_size, name='input_image')
seg = tf.reshape(
tf.cast(tf.image.decode_png(
seg_raw,
channels=1, dtype=tf.uint8),
tf.float32), self.image_size, name='input_seg')
return image, seg, file_names[0]
def _get_image(self):
im_filename = tf.sparse_tensor_to_dense(tf.string_split(tf.expand_dims(self.raw_queue.dequeue(), 0), ':'), '')
im_filename.set_shape([1, 2])
im_raw = tf.read_file(self.base_folder+im_filename[0][0])
seg_raw = tf.read_file(self.base_folder+im_filename[0][1])
image = tf.reshape(tf.cast(tf.image.decode_png(im_raw, channels=1, dtype=tf.uint16), tf.float32),
self.image_size, name='input_image')
seg = tf.reshape(tf.cast(tf.image.decode_png(seg_raw, channels=1, dtype=tf.uint8), tf.float32), self.image_size,
name='input_seg')
if self.partial_frame:
crop_y_start = int(((1-self.partial_frame) * self.image_size[0])/2)
crop_y_end = int(((1+self.partial_frame) * self.image_size[0])/2)
crop_x_start = int(((1-self.partial_frame) * self.image_size[1])/2)
crop_x_end = int(((1+self.partial_frame) * self.image_size[1])/2)
image = tf.slice(image, [crop_y_start, crop_x_start, 0], [crop_y_end, crop_x_end, -1])
seg = tf.slice(seg, [crop_y_start, crop_x_start, 0], [crop_y_end, crop_x_end, -1])
return image, seg, im_filename[0][0], im_filename[0][1]
def _get_image_sequence(self):
filenames = self.raw_queue
im_list = []
seg_list = []
for i in range(0, len(filenames), 2):
im_filename, seg_filename = filenames[i], filenames[i+1]
im_raw = tf.read_file(self.base_folder+im_filename)
seg_raw = tf.read_file(self.base_folder+seg_filename)
image_size = self.image_size + (1, )
image = tf.reshape(tf.cast(tf.image.decode_png(im_raw, channels=1, dtype=tf.uint16), tf.float32),
image_size)
seg = tf.reshape(tf.cast(tf.image.decode_png(seg_raw, channels=1, dtype=tf.uint8), tf.float32),
image_size)
if self.partial_frame:
crop_y_start = int(((1-self.partial_frame) * image_size[0])/2)
crop_y_end = int(((1+self.partial_frame) * image_size[0])/2)
crop_x_start = int(((1-self.partial_frame) * image_size[1])/2)
crop_x_end = int(((1+self.partial_frame) * image_size[1])/2)
image = tf.slice(image, [crop_y_start, crop_x_start, 0], [crop_y_end, crop_x_end, -1])
seg = tf.slice(seg, [crop_y_start, crop_x_start, 0], [crop_y_end, crop_x_end, -1])
im_list.append(image)
seg_list.append(seg)
return im_list, seg_list, filenames
def subtract_mean_multi(image_tensors, mean_image_path, channels=NUM_CHANNELS, image_size=512):
mean_image = tf.convert_to_tensor(mean_image_path, dtype=tf.string)
mean_file_contents = tf.read_file(mean_image)
mean_uint8 = tf.image.decode_png(mean_file_contents, channels=channels)
mean_uint8.set_shape([image_size, image_size, channels])
images_mean_free = []
for image_tensor in image_tensors:
image_tensor.set_shape([image_size, image_size, channels])
image = tf.cast(image_tensor, tf.float32)
#subtract mean image
image_mean_free = tf.subtract(image, tf.cast(mean_uint8, tf.float32))
images_mean_free.append(image_mean_free)
return images_mean_free
def __init__(self, checkpoint, threads):
# Create the session
self.session = tf.Session(graph = tf.Graph(), config=tf.ConfigProto(inter_op_parallelism_threads=threads,
intra_op_parallelism_threads=threads))
with self.session.graph.as_default():
# Construct the model
self.images = tf.placeholder(tf.float32, [None, self.HEIGHT, self.WIDTH, 3])
with tf_slim.arg_scope(tf_slim.nets.resnet_v1.resnet_arg_scope(is_training=False)):
resnet, _ = tf_slim.nets.resnet_v1.resnet_v1_50(self.images, num_classes = self.CLASSES)
self.predictions = tf.argmax(tf.squeeze(resnet, [1, 2]), 1)
# Load the checkpoint
self.saver = tf.train.Saver()
self.saver.restore(self.session, checkpoint)
# JPG loading
self.jpeg_file = tf.placeholder(tf.string, [])
self.jpeg_data = tf.image.resize_image_with_crop_or_pad(tf.image.decode_jpeg(tf.read_file(self.jpeg_file), channels=3), self.HEIGHT, self.WIDTH)
def read_image(self, image_path):
# tf.decode_image does not return the image size, this is an ugly workaround to handle both jpeg and png
path_length = string_length_tf(image_path)[0]
file_extension = tf.substr(image_path, path_length - 3, 3)
file_cond = tf.equal(file_extension, 'jpg')
image = tf.cond(file_cond, lambda: tf.image.decode_jpeg(tf.read_file(image_path)), lambda: tf.image.decode_png(tf.read_file(image_path)))
# if the dataset is cityscapes, we crop the last fifth to remove the car hood
if self.dataset == 'cityscapes':
o_height = tf.shape(image)[0]
crop_height = (o_height * 4) // 5
image = image[:crop_height,:,:]
image = tf.image.convert_image_dtype(image, tf.float32)
image = tf.image.resize_images(image, [self.params.height, self.params.width], tf.image.ResizeMethod.AREA)
return image
chinese_character_recognition_bn.py 文件源码
项目:Chinese-Character-Recognition
作者: soloice
项目源码
文件源码
阅读 24
收藏 0
点赞 0
评论 0
def input_pipeline(self, batch_size, num_epochs=None, aug=False):
images_tensor = tf.convert_to_tensor(self.image_names, dtype=tf.string)
labels_tensor = tf.convert_to_tensor(self.labels, dtype=tf.int64)
input_queue = tf.train.slice_input_producer([images_tensor, labels_tensor], num_epochs=num_epochs)
labels = input_queue[1]
images_content = tf.read_file(input_queue[0])
images = tf.image.convert_image_dtype(tf.image.decode_png(images_content, channels=1), tf.float32)
if aug:
images = self.data_augmentation(images)
new_size = tf.constant([FLAGS.image_size, FLAGS.image_size], dtype=tf.int32)
images = tf.image.resize_images(images, new_size)
image_batch, label_batch = tf.train.shuffle_batch([images, labels], batch_size=batch_size, capacity=50000,
min_after_dequeue=10000)
# print 'image_batch', image_batch.get_shape()
return image_batch, label_batch
def dataset_reader(filename_queue): #prev name: CamVid_reader
image_filename = filename_queue[0] #tensor of type string
label_filename = filename_queue[1] #tensor of type string
#get png encoded image
imageValue = tf.read_file(image_filename)
labelValue = tf.read_file(label_filename)
#decodes a png image into a uint8 or uint16 tensor
#returns a tensor of type dtype with shape [height, width, depth]
image_bytes = tf.image.decode_png(imageValue)
label_bytes = tf.image.decode_png(labelValue) #Labels are png, not jpeg
image = tf.reshape(image_bytes, (FLAGS.image_h, FLAGS.image_w, FLAGS.image_c))
label = tf.reshape(label_bytes, (FLAGS.image_h, FLAGS.image_w, 1))
return image, label
def read_images_from_disk(input_queue):
"""Consumes a single filename and label as a ' '-delimited string.
Args:
filename_and_label_tensor: A scalar string tensor.
Returns:
Two tensors: the decoded image, and the string label.
"""
label = input_queue[1]
file_contents = tf.read_file(input_queue[0])
example = tf.image.decode_png(file_contents, channels=3)
return example, label
# def random_rotate_image(image):
# angle = np.random.uniform(low=-10.0, high=10.0)
# return misc.imrotate(image, angle, 'bicubic')