| 277 | |
| 278 | template <typename Dtype> |
| 279 | void Solver<Dtype>::Solve(const char* resume_file) { |
| 280 | CHECK(Caffe::root_solver()); |
| 281 | LOG(INFO) << "Solving " << net_->name(); |
| 282 | LOG(INFO) << "Learning Rate Policy: " << param_.lr_policy(); |
| 283 | |
| 284 | // Initialize to false every time we start solving. |
| 285 | requested_early_exit_ = false; |
| 286 | |
| 287 | if (resume_file) { |
| 288 | LOG(INFO) << "Restoring previous solver status from " << resume_file; |
| 289 | Restore(resume_file); |
| 290 | } |
| 291 | |
| 292 | // For a network that is trained by the solver, no bottom or top vecs |
| 293 | // should be given, and we will just provide dummy vecs. |
| 294 | int start_iter = iter_; |
| 295 | Step(param_.max_iter() - iter_); |
| 296 | // If we haven't already, save a snapshot after optimization, unless |
| 297 | // overridden by setting snapshot_after_train := false |
| 298 | if (param_.snapshot_after_train() |
| 299 | && (!param_.snapshot() || iter_ % param_.snapshot() != 0)) { |
| 300 | Snapshot(); |
| 301 | } |
| 302 | if (requested_early_exit_) { |
| 303 | LOG(INFO) << "Optimization stopped early."; |
| 304 | return; |
| 305 | } |
| 306 | // After the optimization is done, run an additional train and test pass to |
| 307 | // display the train and test loss/outputs if appropriate (based on the |
| 308 | // display and test_interval settings, respectively). Unlike in the rest of |
| 309 | // training, for the train net we only run a forward pass as we've already |
| 310 | // updated the parameters "max_iter" times -- this final pass is only done to |
| 311 | // display the loss, which is computed in the forward pass. |
| 312 | if (param_.display() && iter_ % param_.display() == 0) { |
| 313 | int average_loss = this->param_.average_loss(); |
| 314 | Dtype loss; |
| 315 | net_->Forward(&loss); |
| 316 | |
| 317 | UpdateSmoothedLoss(loss, start_iter, average_loss); |
| 318 | |
| 319 | LOG(INFO) << "Iteration " << iter_ << ", loss = " << smoothed_loss_; |
| 320 | } |
| 321 | if (param_.test_interval() && iter_ % param_.test_interval() == 0) { |
| 322 | TestAll(); |
| 323 | } |
| 324 | LOG(INFO) << "Optimization Done."; |
| 325 | } |
| 326 | |
| 327 | template <typename Dtype> |
| 328 | void Solver<Dtype>::TestAll() { |