Skip to content

Commit 5c6a290

Browse files
authored
Merge pull request #6104 from YaYaB/master_bvlc
Check solver gamma and stepsize to avoid unexplained core dump
2 parents f7135ed + c23b356 commit 5c6a290

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/caffe/solvers/sgd_solver.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,16 @@ Dtype SGDSolver<Dtype>::GetLearningRate() {
3030
if (lr_policy == "fixed") {
3131
rate = this->param_.base_lr();
3232
} else if (lr_policy == "step") {
33+
CHECK_GT(this->param_.stepsize(), 0);
3334
this->current_step_ = this->iter_ / this->param_.stepsize();
35+
CHECK_GE(this->param_.gamma(), 0);
3436
rate = this->param_.base_lr() *
3537
pow(this->param_.gamma(), this->current_step_);
3638
} else if (lr_policy == "exp") {
39+
CHECK_GE(this->param_.gamma(), 0);
3740
rate = this->param_.base_lr() * pow(this->param_.gamma(), this->iter_);
3841
} else if (lr_policy == "inv") {
42+
CHECK_GE(this->param_.gamma(), 0);
3943
rate = this->param_.base_lr() *
4044
pow(Dtype(1) + this->param_.gamma() * this->iter_,
4145
- this->param_.power());
@@ -46,13 +50,16 @@ Dtype SGDSolver<Dtype>::GetLearningRate() {
4650
LOG(INFO) << "MultiStep Status: Iteration " <<
4751
this->iter_ << ", step = " << this->current_step_;
4852
}
53+
CHECK_GE(this->param_.gamma(), 0);
4954
rate = this->param_.base_lr() *
5055
pow(this->param_.gamma(), this->current_step_);
5156
} else if (lr_policy == "poly") {
5257
rate = this->param_.base_lr() * pow(Dtype(1.) -
5358
(Dtype(this->iter_) / Dtype(this->param_.max_iter())),
5459
this->param_.power());
5560
} else if (lr_policy == "sigmoid") {
61+
CHECK_GE(this->param_.gamma(), 0);
62+
CHECK_GT(this->param_.stepsize(), 0);
5663
rate = this->param_.base_lr() * (Dtype(1.) /
5764
(Dtype(1.) + exp(-this->param_.gamma() * (Dtype(this->iter_) -
5865
Dtype(this->param_.stepsize())))));

0 commit comments

Comments
 (0)