基礎
Caffe (Convolution Architecture For Feature Embedding (Extraction))
網絡各層詳細解釋 http://caffe.berkeleyvision.org/tutorial/layers.html
Questions:
1. 從中斷處開始訓練
caffe train solver solver.prototxt snapshot train_1000.solverstate
https://github.com/BVLC/caffe/wiki/Training-and-Resuming
2. 可視化卷積層
name: "myconvnet"
input: "data"
input_dim: 1
input_dim: 1
input_dim: 256
input_dim: 256
layer {
name: "conv"
type: "Convolution"
bottom: "data"
top: "conv"
convolution_param {
num_output: 10
kernel_size: 3
stride: 1
}
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
value: 0
}
}
$ pip insall pydot
$ sudo aptget install graphviz libgraphvizdev
$ pip install pygraphviz
$ python /path/to/caffe/python/draw_net.py myconvnet.prototxt myconvnet.png
3. 什麼樣的 layer 才能它的 bottom 和 top 可以是相同的名稱?
目前只有 Relu 層它的上下層可以使用相同名稱,因爲它是 element-wise 的,所以可以使用 in-place 的操作以節省內存
http://caffe.berkeleyvision.org/tutorial/interfaces.html
4. 測試網絡
impoort sys
sys.path.insert(0, '/path/to/caffe/python')
import numpy as np
import cv2
from pylab import * #畫圖
import caffe
#initialize
caffe.set_device(1)
caffe.set_mode_gpu() #指定使用哪一塊GPU
#指定GPU計算
model_def = 'deploy.prototxt'
model_weight = 'net.cafffemodel' #給定網絡模型
#給定參數
net = caffe.Net(model_def, model_weight, caffe.TEST)
#給定phase =TEST, 那麼網絡只會向前計算,不會 backpropagation
Net instance: Mnist http://caffe.berkeleyvision.org/gathered/examples/mnist.html
Caffe_Net_and_Visualization
name: "LogReg"
layer {
name: "mnist"
type: "Data"
top: "data"
top: "label"
data_param {
source: "input_leveldb"
batch_size: 64}
}
layer {
name: "ip"
type: "InnerProduct"
bottom: "data"
top: "ip"
inner_product_param {
num_output: 2}
}
layer {
name: "loss"
type: "SoftmaxWithLoss"
bottom: "ip"
bottom: "label"
top: "loss"
}
可視化
~/caffe/python/draw_net.py yout_net.prototxt yoursave.png