Tensorflow image reading & display

Tensorflow image reading & display

Asked on December 26, 2018 in Tensorflow.
Add Comment


  • 1 Answer(s)

        Using tf.train.match_filenames_once load names, with tf.size get the number of files to iterate.

    import tensorflow as tf
    import numpy as np
    import matplotlib;
    from PIL import Image
     
    matplotlib.use('Agg')
    import matplotlib.pyplot as plt
     
     
    filenames = tf.train.match_filenames_once('./images/*.jpg')
    count_num_files = tf.size(filenames)
    filename_queue = tf.train.string_input_producer(filenames)
     
    reader=tf.WholeFileReader()
    key,value=reader.read(filename_queue)
    img = tf.image.decode_jpeg(value)
     
    init = tf.global_variables_initializer()
    with tf.Session() as sess:
        sess.run(init)
        coord = tf.train.Coordinator()
        threads = tf.train.start_queue_runners(coord=coord)
        num_files = sess.run(count_num_files)
        for i in range(num_files):
            image=img.eval()
            print(image.shape)
            Image.fromarray(np.asarray(image)).save('te.jpeg')
    
    Answered on December 26, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.