tensorflow 的reshape()和resize()函数

来源:互联网 发布:js调用手写输入法 编辑:程序博客网 时间:2024/06/05 01:11

如果Linux上没有安装opencv即import cv2报错,
image=cv2.resize(image,(76,76)).reshape((1,76,76,3))
以上语句可以由PIL中的函数代替,语句如下:
#coding=utf-8import  tensorflow  as tfimport  osimport numpy as npfrom PIL import Imagedef 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')
阅读全文
0 0
原创粉丝点击