如何在caffe python上测试FCN(vocfcn8s)?

2024-05-06 18:18:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用图像测试shelhamer给出的FCN caffemodel:

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)

下一步怎么办?有人能帮我吗?我在这里挣扎了好几天。在


Tags: 代码标记test图像imagemodeldefroot
2条回答

Here是我用来对一批文件运行推理的脚本。我想你要找的命令是

net.forward()

要从网络获取输出图像,请使用以下命令。在

^{pr2}$

您可以在存储库中引用^{}。在

# 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)

由于测试图像的形状可能不同,因此重塑数据层至关重要。在

相关问题 更多 >