// Set to TRAIN Phase
caffe::Caffe::set_phase(caffe::Caffe::TRAIN);
// set GPU
caffe::Caffe::set_mode(caffe::Caffe::GPU);
int deviceId = 0;
caffe::Caffe::SetDevice(deviceId);
LOG(INFO) << "Using GPU";
// Solver initialization and evaluation
caffe::SolverParameter solverParams;
caffe::ReadProtoFromTextFileOrDie("/home/iar/caffe/caffe/examples/mnist/lenet_solver.prototxt", &solverParams);
caffe::Solver<float>* solver = new caffe::SGDSolver<float>(solverParams);
solver->Solve();
name: "LeNet"
layers {
name: "mnist"
type: DATA
top: "data"
top: "label"
data_param {
source: "/home/iar/caffe/caffe/examples/mnist/mnist_train_lmdb"
backend: LMDB
batch_size: 64
}
transform_param {
scale: 0.00390625
}
include: { phase: TRAIN }
}
layers {
name: "data"
type: IMAGE_DATA
top: "data"
top: "label"
image_data_param {
source: "/home/iar/caffe/caffe/examples/mnist/file_list.txt"
batch_size: 1
new_height: 28
new_width: 28
}
include: { phase: TEST }
}
layers {
name: "conv1"
type: CONVOLUTION
bottom: "data"
top: "conv1"
blobs_lr: 1
blobs_lr: 2
convolution_param {
num_output: 20
kernel_size: 5
stride: 1
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
}
}
}
layers {
name: "pool1"
type: POOLING
bottom: "conv1"
top: "pool1"
pooling_param {
pool: MAX
kernel_size: 2
stride: 2
}
}
layers {
name: "conv2"
type: CONVOLUTION
bottom: "pool1"
top: "conv2"
blobs_lr: 1
blobs_lr: 2
convolution_param {
num_output: 50
kernel_size: 5
stride: 1
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
}
}
}
layers {
name: "pool2"
type: POOLING
bottom: "conv2"
top: "pool2"
pooling_param {
pool: MAX
kernel_size: 2
stride: 2
}
}
layers {
name: "ip1"
type: INNER_PRODUCT
bottom: "pool2"
top: "ip1"
blobs_lr: 1
blobs_lr: 2
inner_product_param {
num_output: 500
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
}
}
}
layers {
name: "relu1"
type: RELU
bottom: "ip1"
top: "ip1"
}
layers {
name: "ip2"
type: INNER_PRODUCT
bottom: "ip1"
top: "ip2"
blobs_lr: 1
blobs_lr: 2
inner_product_param {
num_output: 10
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
}
}
}
layers {
name: "accuracy"
type: ACCURACY
bottom: "ip2"
bottom: "label"
top: "accuracy"
include: { phase: TEST }
}
layers {
name: "loss"
type: SOFTMAX_LOSS
bottom: "ip2"
bottom: "label"
top: "loss"
}
layers {
name: "output"
type: ARGMAX
bottom: "loss"
top: "output"
include: { phase: TEST }
}
caffe::Net<float> mnistLeNet("my_lenet_test.prototxt");
mnistLeNet.CopyTrainedLayersFrom("/home/iar/caffe/caffe/examples/mnist/lenet_iter_10000.caffemodel");
Check failed: target_blobs[j]->channels() == source_layer.blobs(j).channels() (3 vs. 1)
include: { phue: TEST }
}
... this http://ibuzzlog.blogspot.tw/search/label/Caffe
6 Feb |