summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/mnist/mnist_autoencoder_solver.prototxt1
-rw-r--r--examples/mnist/mnist_autoencoder_test.prototxt20
-rw-r--r--src/caffe/proto/caffe.proto1
-rw-r--r--src/caffe/solver.cpp11
4 files changed, 12 insertions, 21 deletions
diff --git a/examples/mnist/mnist_autoencoder_solver.prototxt b/examples/mnist/mnist_autoencoder_solver.prototxt
index b11b2c46..dd4f0fec 100644
--- a/examples/mnist/mnist_autoencoder_solver.prototxt
+++ b/examples/mnist/mnist_autoencoder_solver.prototxt
@@ -2,6 +2,7 @@ train_net: "mnist_autoencoder_train.prototxt"
test_net: "mnist_autoencoder_test.prototxt"
test_iter: 50
test_interval: 100
+test_compute_loss: true
base_lr: 0.0001
lr_policy: "fixed"
display: 20
diff --git a/examples/mnist/mnist_autoencoder_test.prototxt b/examples/mnist/mnist_autoencoder_test.prototxt
index c106b47f..5090e82f 100644
--- a/examples/mnist/mnist_autoencoder_test.prototxt
+++ b/examples/mnist/mnist_autoencoder_test.prototxt
@@ -20,10 +20,6 @@ layers {
top: "encode1"
name: "encode1"
type: INNER_PRODUCT
- blobs_lr: 1
- blobs_lr: 1
- weight_decay: 1
- weight_decay: 0
inner_product_param {
num_output: 1000
}
@@ -39,10 +35,6 @@ layers {
top: "encode2"
name: "encode2"
type: INNER_PRODUCT
- blobs_lr: 1
- blobs_lr: 1
- weight_decay: 1
- weight_decay: 0
inner_product_param {
num_output: 500
}
@@ -58,10 +50,6 @@ layers {
top: "encode3"
name: "encode3"
type: INNER_PRODUCT
- blobs_lr: 1
- blobs_lr: 1
- weight_decay: 1
- weight_decay: 0
inner_product_param {
num_output: 250
}
@@ -109,10 +97,6 @@ layers {
top: "decode3"
name: "decode3"
type: INNER_PRODUCT
- blobs_lr: 1
- blobs_lr: 1
- weight_decay: 1
- weight_decay: 0
inner_product_param {
num_output: 500
}
@@ -128,10 +112,6 @@ layers {
top: "decode2"
name: "decode2"
type: INNER_PRODUCT
- blobs_lr: 1
- blobs_lr: 1
- weight_decay: 1
- weight_decay: 0
inner_product_param {
num_output: 1000
}
diff --git a/src/caffe/proto/caffe.proto b/src/caffe/proto/caffe.proto
index 19953bf6..8073c281 100644
--- a/src/caffe/proto/caffe.proto
+++ b/src/caffe/proto/caffe.proto
@@ -63,6 +63,7 @@ message SolverParameter {
optional int32 test_iter = 3 [default = 0];
// The number of iterations between two testing phases.
optional int32 test_interval = 4 [default = 0];
+ optional bool test_compute_loss = 19 [default = false];
optional float base_lr = 5; // The base learning rate
// the number of iterations between displaying info. If display = 0, no info
// will be displayed.
diff --git a/src/caffe/solver.cpp b/src/caffe/solver.cpp
index ef5123cf..8daedf4a 100644
--- a/src/caffe/solver.cpp
+++ b/src/caffe/solver.cpp
@@ -100,9 +100,14 @@ void Solver<Dtype>::Test() {
CHECK_NOTNULL(test_net_.get())->CopyTrainedLayersFrom(net_param);
vector<Dtype> test_score;
vector<Blob<Dtype>*> bottom_vec;
+ Dtype loss = 0;
for (int i = 0; i < param_.test_iter(); ++i) {
+ Dtype iter_loss;
const vector<Blob<Dtype>*>& result =
- test_net_->Forward(bottom_vec);
+ test_net_->Forward(bottom_vec, &iter_loss);
+ if (param_.test_compute_loss()) {
+ loss += iter_loss;
+ }
if (i == 0) {
for (int j = 0; j < result.size(); ++j) {
const Dtype* result_vec = result[j]->cpu_data();
@@ -120,6 +125,10 @@ void Solver<Dtype>::Test() {
}
}
}
+ if (param_.test_compute_loss()) {
+ loss /= param_.test_iter();
+ LOG(INFO) << "Test loss: " << loss;
+ }
for (int i = 0; i < test_score.size(); ++i) {
LOG(INFO) << "Test score #" << i << ": "
<< test_score[i] / param_.test_iter();