// NOTE
// Update the next available ID when you add a new SolverParameter field.
//
-// SolverParameter next available ID: 33 (last added: test_initialization)
+// SolverParameter next available ID: 34 (last added: average_loss)
message SolverParameter {
//////////////////////////////////////////////////////////////////////////////
// Specifying the train and test networks
// the number of iterations between displaying info. If display = 0, no info
// will be displayed.
optional int32 display = 6;
+ // Display the cost averaged over the last average_cost iterations
+ optional int32 average_loss = 33 [default = 1];
optional int32 max_iter = 7; // the maximum number of iterations
optional string lr_policy = 8; // The learning rate decay policy.
optional float gamma = 9; // The parameter to compute the learning rate.
// resume_file above.
const int start_iter = iter_;
+ int average_loss = this->param_.average_loss();
+
+ CHECK_GE(average_loss, 1) << "average_cost should be non-negative.";
+
+ vector<Dtype> losses;
+ Dtype smoothed_loss;
+
// For a network that is trained by the solver, no bottom or top vecs
// should be given, and we will just provide dummy vecs.
vector<Blob<Dtype>*> bottom_vec;
const bool display = param_.display() && iter_ % param_.display() == 0;
net_->set_debug_info(display && param_.debug_info());
Dtype loss = net_->ForwardBackward(bottom_vec);
+ 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;
+ }
if (display) {
- LOG(INFO) << "Iteration " << iter_ << ", loss = " << loss;
+ LOG(INFO) << "Iteration " << iter_ << ", loss = " << smoothed_loss;
const vector<Blob<Dtype>*>& result = net_->output_blobs();
int score_index = 0;
for (int j = 0; j < result.size(); ++j) {