| 25 | // in the solver parameter protocol buffer, and iter is the current iteration. |
| 26 | template <typename Dtype> |
| 27 | Dtype SGDSolver<Dtype>::GetLearningRate() { |
| 28 | Dtype rate; |
| 29 | const string& lr_policy = this->param_.lr_policy(); |
| 30 | if (lr_policy == "fixed") { |
| 31 | rate = this->param_.base_lr(); |
| 32 | } else if (lr_policy == "step") { |
| 33 | this->current_step_ = this->iter_ / this->param_.stepsize(); |
| 34 | rate = this->param_.base_lr() * |
| 35 | pow(this->param_.gamma(), this->current_step_); |
| 36 | } else if (lr_policy == "exp") { |
| 37 | rate = this->param_.base_lr() * pow(this->param_.gamma(), this->iter_); |
| 38 | } else if (lr_policy == "inv") { |
| 39 | rate = this->param_.base_lr() * |
| 40 | pow(Dtype(1) + this->param_.gamma() * this->iter_, |
| 41 | - this->param_.power()); |
| 42 | } else if (lr_policy == "multistep") { |
| 43 | if (this->current_step_ < this->param_.stepvalue_size() && |
| 44 | this->iter_ >= this->param_.stepvalue(this->current_step_)) { |
| 45 | this->current_step_++; |
| 46 | LOG(INFO) << "MultiStep Status: Iteration " << |
| 47 | this->iter_ << ", step = " << this->current_step_; |
| 48 | } |
| 49 | rate = this->param_.base_lr() * |
| 50 | pow(this->param_.gamma(), this->current_step_); |
| 51 | } else if (lr_policy == "poly") { |
| 52 | rate = this->param_.base_lr() * pow(Dtype(1.) - |
| 53 | (Dtype(this->iter_) / Dtype(this->param_.max_iter())), |
| 54 | this->param_.power()); |
| 55 | } else if (lr_policy == "sigmoid") { |
| 56 | rate = this->param_.base_lr() * (Dtype(1.) / |
| 57 | (Dtype(1.) + exp(-this->param_.gamma() * (Dtype(this->iter_) - |
| 58 | Dtype(this->param_.stepsize()))))); |
| 59 | } else { |
| 60 | LOG(FATAL) << "Unknown learning rate policy: " << lr_policy; |
| 61 | } |
| 62 | return rate; |
| 63 | } |
| 64 | |
| 65 | template <typename Dtype> |
| 66 | void SGDSolver<Dtype>::PreSolve() { |
nothing calls this directly
no outgoing calls
no test coverage detected