lint and two test_iters in lenet_consolidated_solver
authorJeff Donahue <jeff.donahue@gmail.com>
Sat, 10 May 2014 18:46:19 +0000 (11:46 -0700)
committerJeff Donahue <jeff.donahue@gmail.com>
Sat, 10 May 2014 19:29:50 +0000 (12:29 -0700)
examples/mnist/lenet_consolidated_solver.prototxt
src/caffe/solver.cpp

index 14a048a..76ccbfc 100644 (file)
@@ -6,10 +6,6 @@
 # (specify NetParameters directly in the solver, specify multiple test nets)
 # if desired.
 # 
-# test_iter specifies how many forward passes the test should carry out.
-# In the case of MNIST, we have test batch size 100 and 100 test iterations,
-# covering the full 10,000 testing images.
-test_iter: 100
 # Carry out testing every 500 training iterations.
 test_interval: 500
 # The base learning rate, momentum and the weight decay of the network.
@@ -33,6 +29,7 @@ snapshot_prefix: "lenet"
 random_seed: 1701
 # solver mode: CPU or GPU
 solver_mode: GPU
+
 # The training protocol buffer definition
 train_net_param {
   name: "LeNet"
@@ -154,6 +151,11 @@ train_net_param {
     bottom: "label"
   }
 }
+
+# test_iter specifies how many forward passes the test should carry out.
+# In the case of MNIST, we have test batch size 100 and 100 test iterations,
+# covering the full 10,000 testing images.
+test_iter: 100
 # The testing protocol buffer definition
 test_net_param {
   name: "LeNet-test"
@@ -274,6 +276,9 @@ test_net_param {
     top: "accuracy"
   }
 }
+
+# The train set has 60K images, so we run 600 test iters (600 * 100 = 60K).
+test_iter: 600
 # The protocol buffer definition to test on the train set
 test_net_param {
   name: "LeNet-test-on-train"
index e68f719..48434f4 100644 (file)
@@ -53,7 +53,8 @@ void Solver<Dtype>::Init(const SolverParameter& param) {
   const int num_test_net_files = param_.test_net_size();
   const int num_test_nets = num_test_net_params + num_test_net_files;
   if (num_test_nets) {
-    CHECK_EQ(param_.test_iter().size(), num_test_nets) << "you need to specify test_iter for each test network.";
+    CHECK_EQ(param_.test_iter_size(), num_test_nets)
+        << "test_iter must be specified for each test network.";
     CHECK_GT(param_.test_interval(), 0);
   }
   test_nets_.resize(num_test_nets);
@@ -133,7 +134,8 @@ void Solver<Dtype>::TestAll() {
 
 template <typename Dtype>
 void Solver<Dtype>::Test(const int test_net_id) {
-  LOG(INFO) << "Iteration " << iter_ << ", Testing net (#" << test_net_id << ")";
+  LOG(INFO) << "Iteration " << iter_
+            << ", Testing net (#" << test_net_id << ")";
   // We need to set phase to test before running.
   Caffe::set_phase(Caffe::TEST);
   CHECK_NOTNULL(test_nets_[test_net_id].get())->
@@ -141,7 +143,7 @@ void Solver<Dtype>::Test(const int test_net_id) {
   vector<Dtype> test_score;
   vector<Blob<Dtype>*> bottom_vec;
   Dtype loss = 0;
-  for (int i = 0; i < param_.test_iter().Get(test_net_id); ++i) {
+  for (int i = 0; i < param_.test_iter(test_net_id); ++i) {
     Dtype iter_loss;
     const vector<Blob<Dtype>*>& result =
         test_nets_[test_net_id]->Forward(bottom_vec, &iter_loss);
@@ -166,12 +168,12 @@ void Solver<Dtype>::Test(const int test_net_id) {
     }
   }
   if (param_.test_compute_loss()) {
-    loss /= param_.test_iter().Get(test_net_id);
+    loss /= param_.test_iter(test_net_id);
     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().Get(test_net_id);
+        << test_score[i] / param_.test_iter(test_net_id);
   }
   Caffe::set_phase(Caffe::TRAIN);
 }