Tensorflow image reading & display

前端 未结 8 1185
轮回少年
轮回少年 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 22:18

    First of all scipy.misc.imread and PIL are no longer available. Instead use imageio library but you need to install Pillow for that as a dependancy

    pip install Pillow imageio
    

    Then use the following code to load the image and get the details about it.

    import imageio
    import tensorflow as tf
    
    path = 'your_path_to_image' # '~/Downloads/image.png'
    
    img = imageio.imread(path)
    print(img.shape) 
    

    or

    img_tf = tf.Variable(img)
    print(img_tf.get_shape().as_list()) 
    

    both work fine.

提交回复
热议问题