从caffe中的lmdb数据库读取编码图像数据
Reading encoded image data from lmdb database in caffe
我对使用 caffe 比较陌生,正在尝试创建我可以(稍后)调整的最小工作示例。我可以毫无困难地使用带有 MNIST 数据的 caffe 示例。我下载了 image-net 数据 (ILSVRC12) 并使用 caffe 的工具将其转换为 lmdb 数据库,使用:
$CAFFE_ROOT/build/install/bin/convert_imageset -shuffle -encoded=true top_level_data_dir/ fileNames.txt lmdb_name
创建包含编码 (jpeg) 图像数据的 lmdb。这样做的原因是编码后,lmdb 约为 64GB,而未编码约为 240GB。
我的描述网络的 .prototxt 文件是最小的(一对内积层,主要是从 MNIST 示例中借用的——这里不追求准确性,我只是想要一些有用的东西)。
name: "example"
layer {
name: "imagenet"
type: "Data"
top: "data"
top: "label"
include {
phase: TRAIN
}
transform_param {
scale: 0.00390625
}
data_param {
source: "train-lmdb"
batch_size: 100
backend: LMDB
}
}
layer {
name: "imagenet"
type: "Data"
top: "data"
top: "label"
include {
phase: TEST
}
transform_param {
scale: 0.00390625
}
data_param {
source: "test-lmdb"
batch_size: 100
backend: LMDB
}
}
layer {
name: "ip1"
type: "InnerProduct"
bottom: "data"
top: "ip1"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
inner_product_param {
num_output: 1000
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
}
}
}
layer {
name: "relu1"
type: "ReLU"
bottom: "ip1"
top: "ip1"
}
layer {
name: "ip2"
type: "InnerProduct"
bottom: "ip1"
top: "ip2"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
inner_product_param {
num_output: 1000
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
}
}
}
layer {
name: "accuracy"
type: "Accuracy"
bottom: "ip2"
bottom: "label"
top: "accuracy"
include {
phase: TEST
}
}
layer {
name: "loss"
type: "SoftmaxWithLoss"
bottom: "ip2"
bottom: "label"
top: "loss"
}
当 train-lmdb 未编码时,此 .prototxt 文件工作正常(准确性很差,但 caffe 不会崩溃)。但是,如果对 train-lmdb 进行编码,则会出现以下错误:
data_transformer.cpp:239] Check failed: channels == img_channels (3 vs. 1)
问题:有没有一些"flag"我必须在.prototxt文件中设置,表明train-lmdb是编码图像? (可能必须为测试数据层 test-lmdb 提供相同的标志。)
一点研究:
四处寻找 google 我发现 resolved issue 看起来很有希望。但是,将 'force_encoded_color'
设置为 true 并没有解决我的问题。
我还发现 答案对创建 lmdb 非常有帮助(具体来说,有启用编码的说明),但是,没有提到应该做什么,以便 caffe 知道图像已编码。
您收到的错误信息:
data_transformer.cpp:239] Check failed: channels == img_channels (3 vs. 1)
表示 caffe 数据转换器期望输入 3 channels
(即彩色图像),但得到的图像只有 1img_channels
(即灰度图像)。
looking ar caffe.proto
似乎您应该在 transformation_param
:
处设置参数
layer {
name: "imagenet"
type: "Data"
top: "data"
top: "label"
include {
phase: TRAIN
}
transform_param {
scale: 0.00390625
force_color: true ## try this
}
data_param {
source: "train-lmdb"
batch_size: 100
backend: LMDB
force_encoded_color: true ## cannot hurt...
}
}
我对使用 caffe 比较陌生,正在尝试创建我可以(稍后)调整的最小工作示例。我可以毫无困难地使用带有 MNIST 数据的 caffe 示例。我下载了 image-net 数据 (ILSVRC12) 并使用 caffe 的工具将其转换为 lmdb 数据库,使用:
$CAFFE_ROOT/build/install/bin/convert_imageset -shuffle -encoded=true top_level_data_dir/ fileNames.txt lmdb_name
创建包含编码 (jpeg) 图像数据的 lmdb。这样做的原因是编码后,lmdb 约为 64GB,而未编码约为 240GB。
我的描述网络的 .prototxt 文件是最小的(一对内积层,主要是从 MNIST 示例中借用的——这里不追求准确性,我只是想要一些有用的东西)。
name: "example"
layer {
name: "imagenet"
type: "Data"
top: "data"
top: "label"
include {
phase: TRAIN
}
transform_param {
scale: 0.00390625
}
data_param {
source: "train-lmdb"
batch_size: 100
backend: LMDB
}
}
layer {
name: "imagenet"
type: "Data"
top: "data"
top: "label"
include {
phase: TEST
}
transform_param {
scale: 0.00390625
}
data_param {
source: "test-lmdb"
batch_size: 100
backend: LMDB
}
}
layer {
name: "ip1"
type: "InnerProduct"
bottom: "data"
top: "ip1"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
inner_product_param {
num_output: 1000
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
}
}
}
layer {
name: "relu1"
type: "ReLU"
bottom: "ip1"
top: "ip1"
}
layer {
name: "ip2"
type: "InnerProduct"
bottom: "ip1"
top: "ip2"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
inner_product_param {
num_output: 1000
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
}
}
}
layer {
name: "accuracy"
type: "Accuracy"
bottom: "ip2"
bottom: "label"
top: "accuracy"
include {
phase: TEST
}
}
layer {
name: "loss"
type: "SoftmaxWithLoss"
bottom: "ip2"
bottom: "label"
top: "loss"
}
当 train-lmdb 未编码时,此 .prototxt 文件工作正常(准确性很差,但 caffe 不会崩溃)。但是,如果对 train-lmdb 进行编码,则会出现以下错误:
data_transformer.cpp:239] Check failed: channels == img_channels (3 vs. 1)
问题:有没有一些"flag"我必须在.prototxt文件中设置,表明train-lmdb是编码图像? (可能必须为测试数据层 test-lmdb 提供相同的标志。)
一点研究:
四处寻找 google 我发现 resolved issue 看起来很有希望。但是,将 'force_encoded_color'
设置为 true 并没有解决我的问题。
我还发现
您收到的错误信息:
data_transformer.cpp:239] Check failed: channels == img_channels (3 vs. 1)
表示 caffe 数据转换器期望输入 3 channels
(即彩色图像),但得到的图像只有 1img_channels
(即灰度图像)。
looking ar caffe.proto
似乎您应该在 transformation_param
:
layer {
name: "imagenet"
type: "Data"
top: "data"
top: "label"
include {
phase: TRAIN
}
transform_param {
scale: 0.00390625
force_color: true ## try this
}
data_param {
source: "train-lmdb"
batch_size: 100
backend: LMDB
force_encoded_color: true ## cannot hurt...
}
}