caffe Python API 之 数据输入层(Data,ImageData,HDF5Data)

1 import sys
2 sys.path.append('/projects/caffe-ssd/python')
3 import caffe
4 net = caffe.NetSpec()

一、ImageData Layer

net.data ,net.label = caffe.layers.ImageData(
name="InputData" source
="train.txt", batch_size=32, new_width=48, new_height=48, ntop=2, is_color=True, shuffle=True, root_folder='/', transform_param=dict(crop_size=40,mirror=True)) print str(net.to_proto()) 输出: layer { name: "InputData" type: "ImageData" top: "data" top: "label" transform_param { mirror: true crop_size: 40 } image_data_param { source: "train.txt" batch_size: 32 shuffle: true new_height: 48 new_ 48 is_color: true root_folder: "/" } }

二、Data Layer (lmdb/leveldb)

net.data, net.label = caffe.layers.Data(
    name="InputData",
    source="train_lmdb",
    backend = caffe.params.Data.LMDB,
    batch_size=32,
    ntop=2,
include=dict(phase=caffe.TRAIN) transform_param
=dict( crop_size=227, mean_value=[104, 117, 123], mirror=True ) ) 输出: layer { name: "InputData" type: "Data" top: "data" top: "label" transform_param { mirror: true crop_size: 227 mean_value: 104 mean_value: 117 mean_value: 123 } data_param { source: "train_lmdb" batch_size: 32 backend: LMDB } }

三、HDF5Data Layer

net.data, net.label = caffe.layers.HDF5Data(
            name="InputData",
            source='./training_data_paths.txt',
            batch_size=64,
            include=dict(phase=caffe.TRAIN),
            ntop=2
            )

输出:
layer {
  name: "InputData"
  type: "HDF5Data"
  top: "data"
  top: "label"
  include {
    phase: TRAIN
  }
  hdf5_data_param {
    source: "./training_data_paths.txt"
    batch_size: 64
  }
}

另有:
image = L.HDF5Data( 
    hdf5_data_param={ 'source': './training_data_paths.txt', 'batch_size': 64 },
     include={'phase': caffe.TRAIN } 
)
原文地址:https://www.cnblogs.com/houjun/p/9909764.html