如何在图像目录之外为暹罗网络创建CaffeDB培训数据

Feu*_*fel 7 training-data neural-network deep-learning caffe conv-neural-network

我需要一些帮助,用一个带有images和label-text-file的普通目录为暹罗CNN创建一个CaffeDB.最好的将是一种python方式.
问题不是遍历目录并制作图像对.我的问题更多的是从这些对中制作CaffeDB.
到目前为止,我只用于convert_imageset从图像目录中创建CaffeDB.
感谢帮助!

Sha*_*hai 6

你为什么不简单地使用旧的两个数据集convert_imagest

layer {
  name: "data_a"
  top: "data_a"
  top: "label_a"
  type: "Data"
  data_param { source: "/path/to/first/data_lmdb" }
  ...
}
layer {
  name: "data_b"
  top: "data_b"
  top: "label_b"
  type: "Data"
  data_param { source: "/path/to/second/data_lmdb" }
  ...
}
Run Code Online (Sandbox Code Playgroud)

至于损失,因为每个例子有一个类标签,你需要转换label_alabel_bsame_not_same_label.我建议你使用python层"在运行中"这样做.在prototxt添加对python层的调用:

layer {
  name: "a_b_to_same_not_same_label"
  type: "Python"
  bottom: "label_a"
  bottom: "label_b"
  top: "same_not_same_label"
  python_param { 
    # the module name -- usually the filename -- that needs to be in $PYTHONPATH
    module: "siamese"
    # the layer name -- the class name in the module
    layer: "SiameseLabels"
  }
  propagate_down: false
}
Run Code Online (Sandbox Code Playgroud)

创建siamese.py(确保它在您的身上$PYTHONPATH).在siamese.py你应该有图层类:

import sys, os
sys.path.insert(0,os.environ['CAFFE_ROOT'] + '/python')
import caffe
class SiameseLabels(caffe.Layer):
  def setup(self, bottom, top):
    if len(bottom) != 2:
       raise Exception('must have exactly two inputs')
    if len(top) != 1:
       raise Exception('must have exactly one output')
  def reshape(self,bottom,top):
    top[0].reshape( *bottom[0].shape )
  def forward(self,bottom,top):
    top[0].data[...] = (bottom[0].data == bottom[1].data).astype('f4')
  def backward(self,top,propagate_down,bottom):
      # no back prop
      pass
Run Code Online (Sandbox Code Playgroud)

确保以不同的方式对两组中的示例进行洗牌,这样您就可以得到非平凡的对.此外,如果您构建具有不同数量示例的第一个和第二个数据集,那么您将在每个时期看到不同的对;)


确保构建网络以共享重复层的权重,有关详细信息,请参阅本教程.