virtual void RestoreSolverStateFromHDF5(const string& state_file) = 0;
virtual void RestoreSolverStateFromBinaryProto(const string& state_file) = 0;
void DisplayOutputBlobs(const int net_id);
+ void UpdateSmoothedLoss(Dtype loss, int start_iter, int average_loss);
SolverParameter param_;
int iter_;
shared_ptr<Net<Dtype> > net_;
vector<shared_ptr<Net<Dtype> > > test_nets_;
vector<Callback*> callbacks_;
+ vector<Dtype> losses_;
+ Dtype smoothed_loss_;
// The root solver that holds root nets (actually containing shared layers)
// in data parallelism
const int start_iter = iter_;
const int stop_iter = iter_ + iters;
int average_loss = this->param_.average_loss();
- vector<Dtype> losses;
- Dtype smoothed_loss = 0;
+ losses_.clear();
+ smoothed_loss_ = 0;
while (iter_ < stop_iter) {
// zero-init the params
}
loss /= param_.iter_size();
// average the loss across iterations for smoothed reporting
- if (losses.size() < average_loss) {
- losses.push_back(loss);
- int size = losses.size();
- smoothed_loss = (smoothed_loss * (size - 1) + loss) / size;
- } else {
- int idx = (iter_ - start_iter) % average_loss;
- smoothed_loss += (loss - losses[idx]) / average_loss;
- losses[idx] = loss;
- }
+ UpdateSmoothedLoss(loss, start_iter, average_loss);
if (display) {
LOG_IF(INFO, Caffe::root_solver()) << "Iteration " << iter_
- << ", loss = " << smoothed_loss;
+ << ", loss = " << smoothed_loss_;
const vector<Blob<Dtype>*>& result = net_->output_blobs();
int score_index = 0;
for (int j = 0; j < result.size(); ++j) {
// For a network that is trained by the solver, no bottom or top vecs
// should be given, and we will just provide dummy vecs.
+ int start_iter = iter_;
Step(param_.max_iter() - iter_);
// If we haven't already, save a snapshot after optimization, unless
// overridden by setting snapshot_after_train := false
// updated the parameters "max_iter" times -- this final pass is only done to
// display the loss, which is computed in the forward pass.
if (param_.display() && iter_ % param_.display() == 0) {
+ int average_loss = this->param_.average_loss();
Dtype loss;
net_->ForwardPrefilled(&loss);
- LOG(INFO) << "Iteration " << iter_ << ", loss = " << loss;
+
+ UpdateSmoothedLoss(loss, start_iter, average_loss);
+
+ LOG(INFO) << "Iteration " << iter_ << ", loss = " << smoothed_loss_;
}
if (param_.test_interval() && iter_ % param_.test_interval() == 0) {
TestAll();
}
}
+template <typename Dtype>
+void Solver<Dtype>::UpdateSmoothedLoss(Dtype loss, int start_iter,
+ int average_loss) {
+ if (losses_.size() < average_loss) {
+ losses_.push_back(loss);
+ int size = losses_.size();
+ smoothed_loss_ = (smoothed_loss_ * (size - 1) + loss) / size;
+ } else {
+ int idx = (iter_ - start_iter) % average_loss;
+ smoothed_loss_ += (loss - losses_[idx]) / average_loss;
+ losses_[idx] = loss;
+ }
+}
+
INSTANTIATE_CLASS(Solver);
} // namespace caffe