如果Linux上没有安装opencv即import cv2报错,
image=cv2.resize(image,(76,76)).reshape((1,76,76,3))
以上语句可以由PIL中的函数代替,语句如下:
#coding=utf-8 import tensorflow as tf import os import numpy as np from PIL import Image def test(data_root='/home/system/Python/DData'): image_filenames = os.listdir(data_root) image_filenames = [(data_root + '/' + i) for i in image_filenames] print "kkk" with tf.Session() as session: coord = tf.train.Coordinator() threads = tf.train.start_queue_runners(coord=coord) for img in image_filenames: print img image = Image.open(img) new_img = image.resize((76,76)) new_img=np.array(new_img) new_imgg=new_img.reshape([1,76,76,3]) print "cv shape:", image coord.request_stop() # queue需要关闭,否则报错 coord.join(threads) test('/home/system/Python/DData')