def image(n, size, path, epochs=2, shuffle=True, crop=True):
# for macOS
if exists(join(path, '.DS_Store')):
remove(join(path, '.DS_Store'))
filenames = [join(path, f) for f in listdir(path) if isfile(join(path, f))]
if not shuffle:
filenames = sorted(filenames)
png = filenames[0].lower().endswith('png') # If first file is a png, assume they all are
filename_queue = tf.train.string_input_producer(filenames, shuffle=shuffle, num_epochs=epochs)
reader = tf.WholeFileReader()
_, img_bytes = reader.read(filename_queue)
image = tf.image.decode_png(img_bytes, channels=3) if png else tf.image.decode_jpeg(img_bytes, channels=3)
processed_image = preprocess(image, size)
return tf.train.batch([processed_image], n, dynamic_pad=True)
评论列表
文章目录