MCPcopy Create free account
hub / github.com/BVLC/caffe / InitTestNets

Method InitTestNets

src/caffe/solver.cpp:104–177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

102
103template <typename Dtype>
104void Solver<Dtype>::InitTestNets() {
105 const bool has_net_param = param_.has_net_param();
106 const bool has_net_file = param_.has_net();
107 const int num_generic_nets = has_net_param + has_net_file;
108 CHECK_LE(num_generic_nets, 1)
109 << "Both net_param and net_file may not be specified.";
110 const int num_test_net_params = param_.test_net_param_size();
111 const int num_test_net_files = param_.test_net_size();
112 const int num_test_nets = num_test_net_params + num_test_net_files;
113 if (num_generic_nets) {
114 CHECK_GE(param_.test_iter_size(), num_test_nets)
115 << "test_iter must be specified for each test network.";
116 } else {
117 CHECK_EQ(param_.test_iter_size(), num_test_nets)
118 << "test_iter must be specified for each test network.";
119 }
120 // If we have a generic net (specified by net or net_param, rather than
121 // test_net or test_net_param), we may have an unlimited number of actual
122 // test networks -- the actual number is given by the number of remaining
123 // test_iters after any test nets specified by test_net_param and/or test_net
124 // are evaluated.
125 const int num_generic_net_instances = param_.test_iter_size() - num_test_nets;
126 const int num_test_net_instances = num_test_nets + num_generic_net_instances;
127 if (param_.test_state_size()) {
128 CHECK_EQ(param_.test_state_size(), num_test_net_instances)
129 << "test_state must be unspecified or specified once per test net.";
130 }
131 if (num_test_net_instances) {
132 CHECK_GT(param_.test_interval(), 0);
133 }
134 int test_net_id = 0;
135 vector<string> sources(num_test_net_instances);
136 vector<NetParameter> net_params(num_test_net_instances);
137 for (int i = 0; i < num_test_net_params; ++i, ++test_net_id) {
138 sources[test_net_id] = "test_net_param";
139 net_params[test_net_id].CopyFrom(param_.test_net_param(i));
140 }
141 for (int i = 0; i < num_test_net_files; ++i, ++test_net_id) {
142 sources[test_net_id] = "test_net file: " + param_.test_net(i);
143 ReadNetParamsFromTextFileOrDie(param_.test_net(i),
144 &net_params[test_net_id]);
145 }
146 const int remaining_test_nets = param_.test_iter_size() - test_net_id;
147 if (has_net_param) {
148 for (int i = 0; i < remaining_test_nets; ++i, ++test_net_id) {
149 sources[test_net_id] = "net_param";
150 net_params[test_net_id].CopyFrom(param_.net_param());
151 }
152 }
153 if (has_net_file) {
154 for (int i = 0; i < remaining_test_nets; ++i, ++test_net_id) {
155 sources[test_net_id] = "net file: " + param_.net();
156 ReadNetParamsFromTextFileOrDie(param_.net(), &net_params[test_net_id]);
157 }
158 }
159 test_nets_.resize(num_test_net_instances);
160 for (int i = 0; i < num_test_net_instances; ++i) {
161 // Set the correct NetState. We start with the solver defaults (lowest

Callers

nothing calls this directly

Calls 5

CopyFromMethod · 0.80
netMethod · 0.80
set_debug_infoMethod · 0.80
resetMethod · 0.45

Tested by

no test coverage detected