python FCN批量测试图片

来源:互联网 发布:淘宝图片要求尺寸 编辑:程序博客网 时间:2024/06/05 09:15
import numpy as npfrom PIL import Imageimport sysimport matplotlib.pyplot as pltimport caffeimport caffeimport globfileList=glob.glob('/home/yangwb/FCN/jpeg/*.jpg')#遍历读取jpg文件                             for filename in fileList:    # load image, switch to BGR, subtract mean, and make dims C x H x W for Caffe    im = Image.open(filename)    in_ = np.array(im, dtype=np.float32)    in_ = in_[:,:,::-1]    in_ -= np.array((104.00698793,116.66876762,122.67891434))    in_ = in_.transpose((2,0,1))   # init    #caffe.set_device(int(sys.argv[1]))    caffe.set_device(2)    caffe.set_mode_gpu()    # load net    net = caffe.Net('/home/yangwb/FCN/fcn.berkeleyvision.org-master/myvoc/deploy.prototxt', '/home/yangwb/FCN/fcn.berkeleyvision.org-master/myvoc/_iter_50000.caffemodel', caffe.TEST)    # shape for input (data blob is N x C x H x W), set data    net.blobs['data'].reshape(1, *in_.shape)    net.blobs['data'].data[...] = in_    # run net and take argmax for prediction    net.forward()    out = net.blobs['score'].data[0].argmax(axis=0)     #plt.imshow(out,cmap='gray')    #plt.axis('off')    #plt.savefig(filename)    #plt.show()    np.save(filename[:-4]+"50000", out) #存储
0 1
原创粉丝点击