Caffe中的标签作为图像 [英] Labels in Caffe as Images
问题描述
我是Caffe的新手.我正在尝试为语义分割实现完全卷积神经网络( FCN-8s ).我有图像数据和标签数据,它们都是图像.这是针对逐像素的预测.
I'm new to Caffe. I am trying to implement a Fully Convolution Neural Network (FCN-8s) for semantic segmentation. I have image data and label data, which are both images. This is for pixel-wise predictions.
我尝试使用ImageData作为数据类型,但它要求输入整数标签,该标签不适用于这种情况.请告知我如何给Caffe一个2D标签.我应该更喜欢LMDB而不是ImageData吗?如果是这样,我该如何进行?对于这种情况,我找不到任何好的教程/文档.
I tried using ImageData as the data type, but it asks for an integer label, which is not applicable to this scenario. Kindly advise as how to I can give Caffe a 2D label. Should I prefer LMDB instead of ImageData? If so, how do I proceed? I could not find any good tutorial/documentation for a situation like this.
推荐答案
由于您需要实现逐像素预测,因此不能将单个标签用作事实.相反,您应该使用标签的真实矩阵.
Since you need to achieve pixel-wise predictions, you can't use a single label as ground-truth. Instead, you should use a ground-truth matrix of labels.
其中一位Caffe专家编写了一个代码片段,用于使用图像数据创建LMDB,请参见
One of the Caffe guys wrote a code snippet for creating an LMDB with image data, see here:
import caffe
import lmdb
from PIL import Image
in_db = lmdb.open('image-lmdb', map_size=int(1e12))
with in_db.begin(write=True) as in_txn:
for in_idx, in_ in enumerate(inputs):
# load image:
# - as np.uint8 {0, ..., 255}
# - in BGR (switch from RGB)
# - in Channel x Height x Width order (switch from H x W x C)
im = np.array(Image.open(in_)) # or load whatever ndarray you need
im = im[:,:,::-1]
im = im.transpose((2,0,1))
im_dat = caffe.io.array_to_datum(im)
in_txn.put('{:0>10d}'.format(in_idx), im_dat.SerializeToString())
in_db.close()
这篇关于Caffe中的标签作为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!