caffe 全卷積網路
阿新 • • 發佈:2019-02-16
論文:Long_Fully_Convolutional_Networks
簡介
- 全卷積網路相對於之前的cnn,是對影象中的每個畫素點進行分類
- 常用於影象的語義分割中
參考
測試
- 需要下載
pascalVoc
的資料集 下載程式碼之後,在其根目錄下新建py檔案如下
import numpy as np from PIL import Image import matplotlib.pyplot as plt caffe_root = '/home/gry/libs/caffe/' import sys sys.path.insert(0,caffe_root + 'python/') import caffe fn = 'data/pascal/VOCdevkit/VOC2012/JPEGImages/2007_000129.jpg' im = Image.open( fn ) # im = im.resize([500,500],Image.ANTIALIAS) # im.save("1.jpg","JPEG") npimg = np.array( im, dtype=np.float32 ) print( 'max val of the npimg is : %f'%(npimg.max()) ) npimg -= np.array((104.00698793,116.66876762,122.67891434)) npimg.shape npimg = npimg.transpose( (2,0,1) ) # load net # net = caffe.Net( 'voc-fcn8s/deploy.prototxt','voc-fcn8s/fcn8s-heavy-pascal.caffemodel', caffe.TEST ) net = caffe.Net( 'voc-fcn16s/deploy.prototxt','voc-fcn16s/fcn16s-heavy-pascal.caffemodel', caffe.TEST ) # shape for input (data blob is N x C x H x W), set data # note : the H X W is not necessary to be equal with the network H X W # but the channel must be equal net.blobs['data'].reshape(1, *npimg.shape) net.blobs['data'].data[...] = npimg # net.blobs['data'].data.shape # run net and take argmax for prediction net.forward() out = net.blobs['score'].data[0].argmax(axis=0) plt.imshow(out,cmap='autumn');plt.axis('off') plt.savefig('test.png') plt.show() print('end now')
用不同的caffemodel得到的結果如下
- 原圖
- voc-fcn8s
- voc-fcn16s
- voc-fcn32s
- 原圖
SegNet
簡介
- 基於caffe
參考連結
測試
- 下載基於cudnn5的segnet程式碼與segnet-tutorial的程式碼,按照參考連結裡的教程組織檔案結構
- 修改
trian.txt
與test.txt
,並3進行訓練 - 如果視訊記憶體超過限制,則需要減小訓練的
batchsize
- 轉換caffemodel並按照教程裡的方式進行測試,可以實時顯示原圖、groudtruth與網路輸出影象
- 原始碼中使用的是
plt.show()
,需要關閉之後才能繼續執行,為更方便的顯示,可以結合opencv
imshow
與waitKey
。