为多标签分类创建lmdb

时间:2016-10-25 09:52:38

标签: deep-learning caffe multilabel-classification

我正在尝试创建2个lmdbs。一个用于我的图像一个用于我的标签。我想确定图片的角度,这样做我试图估计水平和垂直角度。我有类:0-10度水平10-20度horiozntal等等。对于垂直角度也是如此。现在我不知道如何创建标签db,因为标签必须如何在lmdb中格式化。 我有一个.txt列表文件,其中包含:/path/pic.png 1 32条目,其中1表示10-20度,32表示320-330度。 我的代码如下所示:

for line in fileinput.input(data):
    entries = re.split(' ', line.strip())
    images.append(entries[0])
    labels.append(entries[1:])
.... 
for in_idx, (image, label) in enumerate(inputs):
    im = cv2.imread(image)
    im = im[:,:,::-1]
    im = im.transpose((2,0,1))

    im_dat = caffe.io.array_to_datum(im)
    print im_dat

    images_txn.put('{:0>10d}'.format(in_idx), im_dat.SerializeToString())

    label = np.array(label).astype(int).reshape(1, 1, len(label))

    label_dat = caffe.io.array_to_datum(label)
    labels_txn.put('{:0>10d}'.format(in_idx), label_dat.SerializeToString())

然而,这似乎不正确,因为我在尝试训练网络时遇到以下错误:

  

检查失败:outer_num_ * inner_num_ == bottom [1] - > count()(10 vs. 20)标签数量必须与预测数量匹配;例如,如果softmax轴== 1且预测形状为(N,C,H,W),则标签计数(标签数量)必须为N H W,整数值为{0,1 ,...,C-1}。

我的数据层如下所示:

name: "LearnAngle"
layer {
  name: "data"
  type: "Data"
  top: "images"
  include {
    phase: TRAIN
  }
  transform_param {
    mirror: true
    crop_size: 256
    mean_file: "/path/mean_train.binaryproto"
  }
  data_param {
    source: "path/train2_images_lmdb"
    batch_size: 10
    backend: LMDB
  }
}
layer {
  name: "data_label"
  type: "Data"
  top: "labels"
  include {
    phase: TRAIN
  }
  data_param {
    source: "path/train2_labels_lmdb"
    batch_size: 10
    backend: LMDB
  }
}

我的最后一层看起来像

layer {
  name: "fc8"
  type: "InnerProduct"
  bottom: "fc7"
  top: "fc8"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  param {
    lr_mult: 2
    decay_mult: 0
  }
  inner_product_param {
    num_output: 36
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}

layer {
  name: "loss"
  type: "SoftmaxWithLoss"
  bottom: "fc8"
  bottom: "labels"
  top: "loss"
}

1 个答案:

答案 0 :(得分:0)

问题是:第二个public ActionResult test(int PrimaryID) { var testing = db.TableName.Find(PrimaryID); // db = Whatever the variable holding your connection string is.. maybe DbContext // TableName = Whatever table in your database that holds the record you want // This will return the specific object that you are looking for return View(testing); } 图层中的top: "labels"包含2种水平和垂直角度标签,而您只使用1 data图层作为标签。

事实上,要在一个网络中训练2个分类任务,您可以分别为2个任务的标签创建2个SoftmaxWithLoss数据库,并使用2 lmdb个图层将它们解析为2 {{1层。如下所示:

为2任务分类创建data的代码:

SoftmaxWithLoss

train_val.prototxt:

lmdb