reader.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:prisma 作者: hijkzzz 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号