如何在映像目录外为暹罗网络创建CaffeDB培训数据 [英] How to Create CaffeDB training data for siamese networks out of image directory

查看:67
本文介绍了如何在映像目录外为暹罗网络创建CaffeDB培训数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助,以从带有图像和标签文本文件的纯目录中为暹罗CNN创建CaffeDB.最好的办法是使用python方法.
问题不在于浏览目录并制作图像对.我的问题更多是从这些对中创建一个CaffeDB.
到目前为止,我仅使用 convert_imageset 从映像目录中创建CaffeDB.
感谢您的帮助!

I need some help to create a CaffeDB for siamese CNN out of a plain directory with images and label-text-file. Best would be a python-way to do it.
The problem is not to walk through the directory and making pairs of images. My problem is more of making a CaffeDB out of those pairs.
So far I only used convert_imageset to create a CaffeDB out of an image directory.
Thanks for help!

推荐答案

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

Why don't you simply make two datasets using good old 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" }
  ...
}

对于损失,由于每个示例都有一个类标签,因此需要将label_alabel_b转换为same_not_same_label.我建议您使用python层即时"执行此操作.在prototxt中,将调用添加到python层:

As for the loss, since every example has a class label you need to convert label_a and label_b into a same_not_same_label. I suggest you do this "on-the-fly" using a python layer. In the prototxt add the call to python layer:

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
}

创建siamese.py(确保它在您的$PYTHONPATH中).在siamese.py中,您应该具有图层类:

Create siamese.py (make sure it is in your $PYTHONPATH). In siamese.py you should have the layer class:

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

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

Make sure you shuffle the examples in the two sets in a different manner, so you get non-trivial pairs. Moreover, if you construct the first and second data sets with different number of examples, then you will see different pairs at each epoch ;)

确保您构建网络以共享重复图层的权重,请参见本教程了解更多信息.

Make sure you construct the network to share the weights of the duplicated layers, see this tutorial for more information.

这篇关于如何在映像目录外为暹罗网络创建CaffeDB培训数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆