在看caffe教程中Fine-tuning for style recognition时比较image_net和style微调网络结构时,发现两个不同的Data layer的类型Data 和 ImageData,如下:
**name: "CaffeNet"**
layer {
name: "data"
type: "Data"
top: "data"
top: "label"
include {
phase: TRAIN
}
transform_param {
mirror: true
crop_size: 227
mean_file: "data/ilsvrc12/imagenet_mean.binaryproto"
}
# mean pixel / channel-wise mean instead of mean image
# transform_param {
# crop_size: 227
# mean_value: 104
# mean_value: 117
# mean_value: 123
# mirror: true
# }
data_param {
source: "examples/imagenet/ilsvrc12_train_lmdb"
batch_size: 256
backend: LMDB
}
}
**name: "FlickrStyleCaffeNet"**
layer {
name: "data"
type: "ImageData"
top: "data"
top: "label"
include {
phase: TRAIN
}
transform_param {
mirror: true
crop_size: 227
mean_file: "data/ilsvrc12/imagenet_mean.binaryproto"
}
image_data_param {
source: "data/flickr_style/train.txt"
batch_size: 50
new_height: 256
new_width: 256
}
}
查看文档资料发现,原来Data layer不仅能接受lmdb和leveldb格式的数据,也能通过设置类型为ImageData,提供文件列表和*.jpg,绕过转换过程,直接提供给caffe。
参考:http://caffe.berkeleyvision.org/tutorial/layers.html
中 Data Layers
Data enters Caffe through data layers: they lie at the bottom of nets. Data can come from efficient databases (LevelDB or LMDB), directly from memory, or, when efficiency is not critical, from files on disk in HDF5 or common image formats.
Common input preprocessing (mean subtraction, scaling, random cropping, and mirroring) is available by specifying TransformationParameters.
Database
Layer type: Data
Parameters
Required
source: the name of the directory containing the database
batch_size: the number of inputs to process at one time
Optional
rand_skip: skip up to this number of inputs at the beginning; useful for asynchronous sgd
backend [default LEVELDB]: choose whether to use a LEVELDB or LMDB
In-Memory
Layer type: MemoryData
Parameters
Required
batch_size, channels, height, width: specify the size of input chunks to read from memory
The memory data layer reads data directly from memory, without copying it. In order to use it, one must call MemoryDataLayer::Reset (from C++) or Net.set_input_arrays (from Python) in order to specify a source of contiguous data (as 4D row major array), which is read one batch-sized chunk at a time.
HDF5 Input
Layer type: HDF5Data
Parameters
Required
source: the name of the file to read from
batch_size
HDF5 Output
Layer type: HDF5Output
Parameters
Required
file_name: name of file to write to
The HDF5 output layer performs the opposite function of the other layers in this section: it writes its input blobs to disk.
Images
Layer type: ImageData
Parameters
Required
source: name of a text file, with each line giving an image filename and label
batch_size: number of images to batch together
Optional
rand_skip
shuffle [default false]
new_height, new_width: if provided, resize all images to this size
Windows
WindowData
Dummy
DummyData is for development and debugging. See DummyDataParameter.