Skip to content

Commit

Permalink
Merge BVLC#2072 and fix conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
weiliu89 committed Apr 14, 2015
2 parents 6eeb282 + 4a4118f commit 4d9b5d1
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/caffe/solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ void Solver<Dtype>::Step(int iters) {
vector<Dtype> losses;
Dtype smoothed_loss = 0;

for (; iter_ < stop_iter; ++iter_) {
while (iter_ < stop_iter) {
// zero-init the params
for (int i = 0; i < net_->params().size(); ++i) {
shared_ptr<Blob<Dtype> > blob = net_->params()[i];
Expand Down Expand Up @@ -235,8 +235,12 @@ void Solver<Dtype>::Step(int iters) {
ComputeUpdateValue();
net_->Update();

// Increment the internal iter_ counter -- its value should always indicate
// the number of times the weights have been updated.
++iter_;

// Save a snapshot if needed.
if (param_.snapshot() && (iter_ + 1) % param_.snapshot() == 0) {
if (param_.snapshot() && iter_ % param_.snapshot() == 0) {
Snapshot();
}
}
Expand Down Expand Up @@ -448,15 +452,14 @@ void Solver<Dtype>::Snapshot() {
string model_filename, snapshot_filename;
const int kBufferSize = 20;
char iter_str_buffer[kBufferSize];
// Add one to iter_ to get the number of iterations that have completed.
snprintf(iter_str_buffer, kBufferSize, "_iter_%d", iter_ + 1);
snprintf(iter_str_buffer, kBufferSize, "_iter_%d", iter_);
filename += iter_str_buffer;
model_filename = filename + ".caffemodel";
LOG(INFO) << "Snapshotting to " << model_filename;
WriteProtoToBinaryFile(net_param, model_filename.c_str());
SolverState state;
SnapshotSolverState(&state);
state.set_iter(iter_ + 1);
state.set_iter(iter_);
state.set_learned_net(model_filename);
state.set_current_step(current_step_);
snapshot_filename = filename + ".solverstate";
Expand Down

0 comments on commit 4d9b5d1

Please sign in to comment.