Python 是否可以在不存储在数据源(如LMDB)中的数据集上运行caffe模型?
我有两套图像补丁数据,即训练集和测试集。这两个文件都已写入LMDB文件。我正在使用Caffe对这些数据运行卷积神经网络 问题是,存储在硬盘上的数据占用了相当大的空间,阻碍了我引入更多训练数据的努力,故意添加噪声,使我的模型更加健壮Python 是否可以在不存储在数据源(如LMDB)中的数据集上运行caffe模型?,python,caffe,conv-neural-network,lmdb,Python,Caffe,Conv Neural Network,Lmdb,我有两套图像补丁数据,即训练集和测试集。这两个文件都已写入LMDB文件。我正在使用Caffe对这些数据运行卷积神经网络 问题是,存储在硬盘上的数据占用了相当大的空间,阻碍了我引入更多训练数据的努力,故意添加噪声,使我的模型更加健壮 有没有一种方法可以让我直接将程序中的图像补丁发送到CNN(在Caffe中),而无需将它们存储在LMDB中?我目前正在使用python为训练数据集的图像生成补丁 您可以编写自己的python数据层。有关视频流输入数据层的详细信息,请参阅讨论和实现 基本上,您需要添加网络
有没有一种方法可以让我直接将程序中的图像补丁发送到CNN(在Caffe中),而无需将它们存储在LMDB中?我目前正在使用python为训练数据集的图像生成补丁 您可以编写自己的python数据层。有关视频流输入数据层的详细信息,请参阅讨论和实现 基本上,您需要添加网络描述层,如:
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数据层。有关视频流输入数据层的详细信息,请参阅讨论和实现 基本上,您需要添加网络描述层,如:
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层外,还可以使用以下选项:
- 使用
layer:它有一个源参数(源:文本文件的名称,每行给出一个图像文件名和标签)ImageData
- 使用
层:使用该层,您可以使用python中的“setInputArray”方法将输入图像直接从内存加载到网络。使用该层时要小心,因为它只接受单个值的标签,并且不能使用图像作为标签(例如,在语义分割中)MemoryData
- 使用网络的部署版本,如下所示:
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的计算效率更高)
网上也有一些例子 除了定义自定义python层之外,还可以使用以下选项:
- 使用
layer:它有一个源参数(源:文本文件的名称,每行给出一个图像文件名和标签)ImageData
- 使用
层:使用该层,您可以使用python中的“setInputArray”方法将输入图像直接从内存加载到网络。使用该层时要小心,因为它只接受单个值的标签,并且不能使用图像作为标签(例如,在语义分割中)MemoryData
- 使用网络的部署版本,如下所示:
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的计算效率更高)
网上也有一些例子 您是否尝试过使用ImageData层?将图像转换为LMDB文件时,您可以通过
convert\u imageset--encoded=true--encoded\u type=png
对其进行编码以节省空间。可以找到详细信息。另外,你可以考虑使用IGEDATA层,并尝试使用OpenCV的多核版本来加速读取图像是否已经尝试使用IVEDATA层?当将图像转换成LMDB文件时,可以通过代码> >转换子IGETESEET-编码-=真-编码-yType=PNG < /代码>来保存它们,以节省空间细节。此外,您可以考虑使用IMAGEATA层,并尝试多核版本的OpenCV,以加速阅读图像,谢谢!为我工作。:)谢谢你!为我工作。:)如果我们必须在线提取补丁进行语义分割呢?我有一个python层,它正在执行特定的工作,然后我需要从特定区域提取补丁,然后将其发送到另一个网络。有可能吗?有哪些选择?谢谢如果我们必须在线提取补丁进行语义分割,该怎么办?我有一个python层,它正在执行特定的工作,然后我需要从特定区域提取补丁,然后将其发送到另一个网络。有可能吗?有哪些选择?谢谢