TensorFLow能够识别的图像文件,可以通过numpy,使用tf.Variable或者tf.placeholder加载进tensorflow;也可以通过自带函数(tf.read)读取,当图像文件过多时,一般使用pipeline通过队列的方法进行读取。下面我们介绍两种生成tensorflow的图像格式的方法,供给tensorflow的graph的输入与输出。
1
import cv2
import numpy as np
import h5py
height = 460
width = 345
with h5py.File('make3d_dataset_f460.mat','r') as f:
images = f['images'][:]
image_num = len(images)
data = np.zeros((image_num, height, width, 3), np.uint8)
data = images.transpose((0,3,2,1))
先生成图像文件的路径:ls *.jpg> list.txt
import cv2
import numpy as np
image_path = './'
list_file = 'list.txt'
height = 48
width = 48
image_name_list = [] # read image
with open(image_path + list_file) as fid:
image_name_list = [x.