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

Method Step

src/caffe/solver.cpp:180–267  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

178
179template <typename Dtype>
180void Solver<Dtype>::Step(int iters) {
181 const int start_iter = iter_;
182 const int stop_iter = iter_ + iters;
183 int average_loss = this->param_.average_loss();
184 losses_.clear();
185 smoothed_loss_ = 0;
186 iteration_timer_.Start();
187
188 while (iter_ < stop_iter) {
189 // zero-init the params
190 net_->ClearParamDiffs();
191 if (param_.test_interval() && iter_ % param_.test_interval() == 0
192 && (iter_ > 0 || param_.test_initialization())) {
193 if (Caffe::root_solver()) {
194 TestAll();
195 }
196 if (requested_early_exit_) {
197 // Break out of the while loop because stop was requested while testing.
198 break;
199 }
200 }
201
202 for (int i = 0; i < callbacks_.size(); ++i) {
203 callbacks_[i]->on_start();
204 }
205 const bool display = param_.display() && iter_ % param_.display() == 0;
206 net_->set_debug_info(display && param_.debug_info());
207 // accumulate the loss and gradient
208 Dtype loss = 0;
209 for (int i = 0; i < param_.iter_size(); ++i) {
210 loss += net_->ForwardBackward();
211 }
212 loss /= param_.iter_size();
213 // average the loss across iterations for smoothed reporting
214 UpdateSmoothedLoss(loss, start_iter, average_loss);
215 if (display) {
216 float lapse = iteration_timer_.Seconds();
217 float per_s = (iter_ - iterations_last_) / (lapse ? lapse : 1);
218 LOG_IF(INFO, Caffe::root_solver()) << "Iteration " << iter_
219 << " (" << per_s << " iter/s, " << lapse << "s/"
220 << param_.display() << " iters), loss = " << smoothed_loss_;
221 iteration_timer_.Start();
222 iterations_last_ = iter_;
223 const vector<Blob<Dtype>*>& result = net_->output_blobs();
224 int score_index = 0;
225 for (int j = 0; j < result.size(); ++j) {
226 const Dtype* result_vec = result[j]->cpu_data();
227 const string& output_name =
228 net_->blob_names()[net_->output_blob_indices()[j]];
229 const Dtype loss_weight =
230 net_->blob_loss_weights()[net_->output_blob_indices()[j]];
231 for (int k = 0; k < result[j]->count(); ++k) {
232 ostringstream loss_msg_stream;
233 if (loss_weight) {
234 loss_msg_stream << " (* " << loss_weight
235 << " = " << loss_weight * result_vec[k] << " loss)";
236 }
237 LOG_IF(INFO, Caffe::root_solver()) << " Train net output #"

Callers 2

InternalThreadEntryMethod · 0.80
solver_stepFunction · 0.80

Calls 11

GetRequestedActionFunction · 0.85
StartMethod · 0.80
ClearParamDiffsMethod · 0.80
set_debug_infoMethod · 0.80
ForwardBackwardMethod · 0.80
SecondsMethod · 0.80
countMethod · 0.80
sizeMethod · 0.45
on_startMethod · 0.45
cpu_dataMethod · 0.45
on_gradients_readyMethod · 0.45

Tested by

no test coverage detected