欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

caffe:Data 层

发布时间:2025/4/16 编程问答 47 豆豆
生活随笔 收集整理的这篇文章主要介绍了 caffe:Data 层 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

在看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: truecrop_size: 227mean_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: 256backend: LMDB} } **name: "FlickrStyleCaffeNet"** layer {name: "data"type: "ImageData"top: "data"top: "label"include {phase: TRAIN}transform_param {mirror: truecrop_size: 227mean_file: "data/ilsvrc12/imagenet_mean.binaryproto"}image_data_param {source: "data/flickr_style/train.txt"batch_size: 50new_height: 256new_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.

总结

以上是生活随笔为你收集整理的caffe:Data 层的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。