如何在 caffe python 上测试 FCN(voc-fcn8s)?
how to test FCN(voc-fcn8s) on caffe python?
我想用图片测试shelhamer给出的FCN caffemodel:
但我不确定如何 运行 测试程序并显示标记的图像。
我思考的代码如下:
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)
那么接下来是什么有人可以帮助我吗?我在这里苦苦挣扎了好几天。
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))
您可以参考存储库中的 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)
重塑数据层至关重要,因为测试图像的形状可能不同。
我想用图片测试shelhamer给出的FCN caffemodel:
但我不确定如何 运行 测试程序并显示标记的图像。
我思考的代码如下:
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)
那么接下来是什么有人可以帮助我吗?我在这里苦苦挣扎了好几天。
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))
您可以参考存储库中的 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)
重塑数据层至关重要,因为测试图像的形状可能不同。