轉自:https://blog.csdn.net/wjmishuai/article/details/50890214
剛開始摸caffe,找了個比較清楚的模型。
原始數據是28*28
input: "data"
input_dim: 60 // number of picture
input_dim: 1 // channel
input_dim: 1 // heigth
input_dim: 784 // width
input: "data"
input_dim: 60 // number of picture
input_dim: 1 // channel
input_dim: 1 // heigth
input_dim: 784 // width
1:數據層: layer { name: "mnist"//數據層的名字是mnist type: "Data"//這個層的類型是data top: "data"//產生兩個blob,一個是data blob top: "label"//一個是lable blob include { phase: TRAIN } transform_param { scale: 0.00390625//像素歸一化 } data_param { source: "examples/mnist/mnist_train_lmdb" batch_size: 64 backend: LMDB } } 2:卷積層 layer { name: "conv1" type: "Convolution" bottom: "data"//獲取上一層的data blob top: "conv1"//產生conv1層 param { lr_mult: 1//學習率。表示 weight的學習率和slover.pro中的學習率是一致的。 } param { lr_mult: 2//表示 bias的學習率是slover.pro中的學習率的2倍。 這樣設置會導致更快的收斂 } convolution_param { num_output: 20//cov1層將產生輸出20個通道 kernel_size: 5//卷積核大小是5*5 stride: 1//步長是1 weight_filler {//權重填充器,使用xavier算法填充weight。根據輸入和輸出神經元的數量自動確定初始化的規模。 type: "xavier" } bias_filler {//偏置填充器,使用constant算法填充bias。是一個常數,默認是0 type: "constant" } } } 3:池化層(避免數據過擬合) layer { name: "pool1" type: "Pooling" bottom: "conv1" top: "pool1" pooling_param { pool: MAX//使用MAX進行池化 kernel_size: 2//卷積核大小是2*2 stride: 2//步長是2 } } 4:全連接層 layer { name: "ip1" type: "InnerProduct" bottom: "pool2" top: "ip1" param { lr_mult: 1 } param { lr_mult: 2 } inner_product_param { num_output: 500//產生500維的輸出數據 weight_filler { type: "xavier" } bias_filler { type: "constant" } } } 5:ReLU層(緊跟在全連接層后,目的是節省內存) layer { name: "relu1" type: "ReLU" bottom: "ip1" top: "ip1" } ReLU層后緊跟一個InnerProduct層 layer { name: "ip2" type: "InnerProduct" bottom: "ip1" top: "ip2" param { lr_mult: 1 } param { lr_mult: 2 } inner_product_param { num_output: 10//因為有10類,所以輸出10 weight_filler { type: "xavier" } bias_filler { type: "constant" } } } 6:Loss層//不產生任何輸出,只是用來計算損失函數的值,用來初始化ip2的gradient layer { name: "loss" type: "SoftmaxWithLoss" bottom: "ip2"//需要兩個blob,一個是ip2,作為預測用 bottom: "label"//來自數據層,作為標簽 top: "loss" }