是否可以在未存储在 LMDB 等数据源中的数据集上 运行 caffe 模型?

Is it possible to run caffe models on the data-set which is not stored in data-source like LMDB?

我有 2 组图像块数据,即训练集和测试集。这两个都已写入 LMDB 文件。我是 运行 使用 Caffe 处理此数据的卷积神经网络。

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

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

您可以编写自己的 python 数据层。查看讨论 here and implementation for of input data layer for video stream 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

除了定义自定义 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

也有在线示例。