Tensorflow image reading & display

前端 未结 8 1181
轮回少年
轮回少年 2020-11-30 21:41

I\'ve got a bunch of images in a format similar to Cifar10 (binary file, size = 96*96*3 bytes per image), one image after another (STL-10 dataset). The file I\'

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-30 21:54

    Just to give a complete answer:

    filename_queue = tf.train.string_input_producer(['/Users/HANEL/Desktop/tf.png']) #  list of files to read
    
    reader = tf.WholeFileReader()
    key, value = reader.read(filename_queue)
    
    my_img = tf.image.decode_png(value) # use png or jpg decoder based on your files.
    
    init_op = tf.global_variables_initializer()
    with tf.Session() as sess:
      sess.run(init_op)
    
      # Start populating the filename queue.
    
      coord = tf.train.Coordinator()
      threads = tf.train.start_queue_runners(coord=coord)
    
      for i in range(1): #length of your filename list
        image = my_img.eval() #here is your image Tensor :) 
    
      print(image.shape)
      Image.fromarray(np.asarray(image)).show()
    
      coord.request_stop()
      coord.join(threads)
    

    Or if you have a directory of images you can add them all via this Github source file

    @mttk and @salvador-dali: I hope it is what you need

提交回复
热议问题