基础
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