【问题标题】:Is it possible to run caffe models on the data-set which is not stored in data-source like LMDB?是否可以在未存储在 LMDB 等数据源中的数据集上运行 caffe 模型?
【发布时间】:2016-08-22 05:23:46
【问题描述】:

我有 2 组图像补丁数据,即训练集和测试集。这两个都已写入 LMDB 文件。我正在使用 Caffe 对这些数据运行卷积神经网络。

问题在于存储在硬盘上的数据占用了大量空间,这阻碍了我引入更多训练数据并故意添加噪声以使我的模型更健壮的努力。

有没有一种方法可以将图像补丁从我的程序直接发送到 CNN(在 Caffe 中)而不将它们存储在 LMDB 中?我目前正在使用 python 从训练数据集的图像中生成补丁。

【问题讨论】:

  • 您是否尝试过使用 ImageData 图层?
  • 在将图片转换为LMDB文件时,您可以通过convert_imageset --encoded=true --encoded_type=png对其进行编码以节省空间,详情可参见here。另外,可以考虑使用ImageData层,尝试多核版本的OpenCV,根据this post加快读取图片的速度

标签: python caffe conv-neural-network lmdb


【解决方案1】:

您可以编写自己的 python 数据层。请参阅讨论here 和视频流输入数据层的实现here

基本上你需要添加到你的网络描述层,比如:

layer {
  type: 'Python'
  name: 'data'
  top: 'data'
  top: 'label'
  python_param {
    # the module name -- usually the filename -- that needs to be in $PYTHONPATH
    module: 'filename'
    # the layer name -- the class name in the module
    layer: 'CustomInputDataLayer'
  }
}

并在 Python 中实现层接口:

class CustomInputDataLayer(caffe.Layer):
    def setup(self):
         ...

    def reshape(self, bottom, top)
        top[0].reshape(BATCH_SIZE, your_data.shape)
        top[1].reshape(BATCH_SIZE, your_label.shape)

    def forward(self, bottom, top):
        # assign output
        top[0].data[...] = your_data
        top[1].data[...] = your_label

    def backward(self, top, propagate_down, bottom):
        pass

【讨论】:

  • 谢谢你!为我工作。 :)
【解决方案2】:

除了定义自定义 python 层之外,您还可以使用以下选项:

  • 使用ImageData层:它有一个源参数(源:文本文件的名称,每行给出一个图像文件名和标签)

  • 使用MemoryData 层:使用它,您可以使用python 中的“setinputarrays”方法将输入图像直接从内存加载到网络。请谨慎使用该层,因为它只接受单值标签,并且您不能将图像用作标签(例如在语义分割中)

  • 像这样使用网络的部署版本:

    input: "data"
    input_shape {
    dim: n # batch size
    dim: c # number of channels
    dim: r # image size1
    dim: w # image size2
    }
    
    input: "label"
    input_shape {
    dim: n # batch size
    dim: c # number of channels
    dim: r # label image size1
    dim: w # label image size2
    }
     ... #your other layers to follow
    
  • 使用 HDF5 输入层(或多或少在 lmdb 中,但 lmdb 的计算效率更高)

您可以在此处找到这些层的详细信息: http://caffe.berkeleyvision.org/tutorial/layers.html

网上也有例子。

【讨论】:

  • 如果我们必须在线提取补丁进行语义分割怎么办?我有一个 python 层正在做一项特定的工作,然后我需要从特定区域提取补丁,然后将其发送到另一个网络。有可能做到吗?有什么选择?谢谢
猜你喜欢
  • 1970-01-01
  • 2020-03-09
  • 1970-01-01
  • 1970-01-01
  • 2016-12-31
  • 2013-07-12
  • 1970-01-01
  • 2016-07-14
  • 1970-01-01
相关资源
最近更新 更多