我对使用caffe比较新,正在尝试创建最小的工作示例,以后可以进行调整。使用MNIST数据时,我没有遇到任何困难。我下载了图像网数据(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)
问题:在.prototxt文件中有没有必须设置的“标志”,表明train-lmdb是编码图像?(同样的标志可能还必须赋予测试数据层,test-lmdb。)
一些研究:
在谷歌上搜索时,我发现已解决的问题似乎很有前途。然而,将“force_encoded_color”设置为true并没有解决我的问题。
我还发现这个答案非常有用,可以创建lmdb(具体来说,可以启用编码),但是,并没有提到应该做什么,让caffe知道图像被编码了。
--check_size
是否检查通道数,据我所知它只检查宽度和高度,但我可能错了。 - Shai