inline vector<vector<bool> >& bottom_need_backward() {
return bottom_need_backward_;
}
+ inline vector<Dtype>& blob_loss_weights() {
+ return blob_loss_weights_;
+ }
// returns the parameters
inline vector<shared_ptr<Blob<Dtype> > >& params() { return params_; }
// returns the parameter learning rate multipliers
// top_vecs stores the vectors containing the output for each layer
vector<vector<Blob<Dtype>*> > top_vecs_;
vector<vector<int> > top_id_vecs_;
+ // Vector of weight in the loss (or objective) function of each net blob,
+ // indexed by blob_id.
+ vector<Dtype> blob_loss_weights_;
vector<int> param_owners_;
vector<string> param_display_names_;
vector<pair<int, int> > param_layer_indices_;
LOG(INFO) << "Setting up " << layer_names_[layer_id];
layers_[layer_id]->SetUp(bottom_vecs_[layer_id], &top_vecs_[layer_id]);
for (int top_id = 0; top_id < top_vecs_[layer_id].size(); ++top_id) {
+ if (blob_loss_weights_.size() <= top_id_vecs_[layer_id][top_id]) {
+ blob_loss_weights_.resize(top_id_vecs_[layer_id][top_id] + 1, Dtype(0));
+ }
+ blob_loss_weights_[top_id_vecs_[layer_id][top_id]] = layer->loss(top_id);
LOG(INFO) << "Top shape: " << top_vecs_[layer_id][top_id]->num() << " "
<< top_vecs_[layer_id][top_id]->channels() << " "
<< top_vecs_[layer_id][top_id]->height() << " "
<< top_vecs_[layer_id][top_id]->width() << " ("
<< top_vecs_[layer_id][top_id]->count() << ")";
+ if (layer->loss(top_id)) {
+ LOG(INFO) << " with loss weight " << layer->loss(top_id);
+ }
}
DLOG(INFO) << "Memory required for data: " << memory_used_ * sizeof(Dtype);
const int blobs_lr_size = layer_param.blobs_lr_size();
bool layer_contributes_loss = false;
for (int top_id = 0; top_id < top_vecs_[layer_id].size(); ++top_id) {
const string& blob_name = blob_names_[top_id_vecs_[layer_id][top_id]];
- if (layers_[layer_id]->has_loss(top_id) ||
+ if (layers_[layer_id]->loss(top_id) ||
(blobs_under_loss.find(blob_name) != blobs_under_loss.end())) {
layer_contributes_loss = true;
break;
}
net_params[i].mutable_state()->CopyFrom(net_state);
LOG(INFO)
- << "Creating testing net (#" << i << ") specified by " << sources[i];
+ << "Creating test net (#" << i << ") specified by " << sources[i];
test_nets_[i].reset(new Net<Dtype>(net_params[i]));
}
}
if (display) {
LOG(INFO) << "Iteration " << iter_ << ", loss = " << loss;
const vector<Blob<Dtype>*>& result = net_->output_blobs();
- vector<Dtype> score;
+ int score_index = 0;
for (int j = 0; j < result.size(); ++j) {
const Dtype* result_vec = result[j]->cpu_data();
+ const string& output_name =
+ net_->blob_names()[net_->output_blob_indices()[j]];
+ const Dtype loss_weight =
+ net_->blob_loss_weights()[net_->output_blob_indices()[j]];
for (int k = 0; k < result[j]->count(); ++k) {
- score.push_back(result_vec[k]);
+ ostringstream loss_msg_stream;
+ if (loss_weight) {
+ loss_msg_stream << " (* " << loss_weight
+ << " = " << loss_weight * result_vec[k] << " loss)";
+ }
+ LOG(INFO) << " Train net output #"
+ << score_index++ << ": " << output_name << " = "
+ << result_vec[k] << loss_msg_stream.str();
}
}
- for (int i = 0; i < score.size(); ++i) {
- LOG(INFO) << " Training score #" << i << ": " << score[i];
- }
}
ComputeUpdateValue();
CHECK_NOTNULL(test_nets_[test_net_id].get())->
ShareTrainedLayersWith(net_.get());
vector<Dtype> test_score;
+ vector<int> test_score_output_id;
vector<Blob<Dtype>*> bottom_vec;
+ const shared_ptr<Net<Dtype> >& test_net = test_nets_[test_net_id];
Dtype loss = 0;
for (int i = 0; i < param_.test_iter(test_net_id); ++i) {
Dtype iter_loss;
const vector<Blob<Dtype>*>& result =
- test_nets_[test_net_id]->Forward(bottom_vec, &iter_loss);
+ test_net->Forward(bottom_vec, &iter_loss);
if (param_.test_compute_loss()) {
loss += iter_loss;
}
const Dtype* result_vec = result[j]->cpu_data();
for (int k = 0; k < result[j]->count(); ++k) {
test_score.push_back(result_vec[k]);
+ test_score_output_id.push_back(j);
}
}
} else {
LOG(INFO) << "Test loss: " << loss;
}
for (int i = 0; i < test_score.size(); ++i) {
- LOG(INFO) << " Test score #" << i << ": "
- << test_score[i] / param_.test_iter(test_net_id);
+ const string& output_name = test_net->blob_names()[
+ test_net->output_blob_indices()[test_score_output_id[i]]];
+ const Dtype loss_weight =
+ test_net->blob_loss_weights()[test_net->output_blob_indices()[i]];
+ ostringstream loss_msg_stream;
+ const Dtype mean_score = test_score[i] / param_.test_iter(test_net_id);
+ if (loss_weight) {
+ loss_msg_stream << " (* " << loss_weight
+ << " = " << loss_weight * mean_score << " loss)";
+ }
+ LOG(INFO) << " Test net output #" << i << ": " << output_name << " = "
+ << mean_score << loss_msg_stream.str();
}
Caffe::set_phase(Caffe::TRAIN);
}