2016-10-21 5 views
2

私がイメージしてshelhamerによって与えられたFCNのcaffemodelをテストしたい:caffe pythonでFCN(voc-fcn8s)をテストする方法は?

enter image description here

しかし、テストプログラムを実行し、ラベルされた画像を表示する方法を私はわかりません。

私はおよそ以下の通りですが、コード:

import caffe 
caffe_root = 'fcn.berkeleyvision.org-master/voc-fcn8s/' 
model_def = caffe_root + 'deploy.prototxt' 
model_weights = caffe_root + 'fcn8s-heavy-pascal.caffemodel' 
test_image = caffe_root + 'test.jpg' 

net = caffe.Net(model_def, model_weights, caffe.TEST) 
image = caffe.io.load_image(test_image) 

をので、次は何か誰も私を助けることができますか?私はここで連続した日に苦労しています。

答えて

2

リポジトリのinfer.pyを参照できます。

# load image, switch to BGR, subtract mean, and make dims C x H x W for Caffe 
im = Image.open('pascal/VOC2010/JPEGImages/2007_000129.jpg') 
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)) 

# load net 
net = caffe.Net('voc-fcn8s/deploy.prototxt', 'voc-fcn8s/fcn8s-heavy-pascal.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) 

テストイメージの形状が異なる可能性があるため、データレイヤの再形成が不可欠です。

+0

ありがとうございました.... –

3

Hereは、ファイルのバッチで推論を実行するために使用するスクリプトです。あなたが探しているコマンドは、

net.forward() 

です。ネットワークから出力イメージを取得するには、次のコマンドを使用します。

out = net.blobs['score'].data # Extract the output 
out = out.argmax(axis=1) # Get the labels at each pixel 
out = out.transpose(1, 2, 0) # Reshape the output into an image 
out = np.tile(out, (1,3)) 
関連する問題