why the code '''this->loss ...''' makes sense in layer.hpp?

11 views
Skip to first unread message

chenchr

unread,
Aug 30, 2017, 8:32:49 AM8/30/17
to Caffe Users
Hello. I've just read the source code of caffe. In layer.cpp, the function inline Dtype Layer<Dtype>::Forward(const vector<Blob<Dtype>*>& bottom,
    const vector<Blob<Dtype>*>& top), there are the code:
template <typename Dtype>
inline Dtype Layer<Dtype>::Forward(const vector<Blob<Dtype>*>& bottom,
   const vector<Blob<Dtype>*>& top) {
 Dtype loss = 0;
 Reshape(bottom, top);
 switch (Caffe::mode()) {
 case Caffe::CPU:
   Forward_cpu(bottom, top);
   for (int top_id = 0; top_id < top.size(); ++top_id) {
     if (!this->loss(top_id)) { continue; }
     const int count = top[top_id]->count();
     const Dtype* data = top[top_id]->cpu_data();
     const Dtype* loss_weights = top[top_id]->cpu_diff();
     loss += caffe_cpu_dot(count, data, loss_weights);
   }
   break;
 case Caffe::GPU:
   Forward_gpu(bottom, top);
#ifndef CPU_ONLY
   for (int top_id = 0; top_id < top.size(); ++top_id) {
     if (!this->loss(top_id)) { continue; }
     const int count = top[top_id]->count();
     const Dtype* data = top[top_id]->gpu_data();
     const Dtype* loss_weights = top[top_id]->gpu_diff();
     Dtype blob_loss = 0;
     caffe_gpu_dot(count, data, loss_weights, &blob_loss);
     loss += blob_loss;
   }
#endif
   break;
 default:
   LOG(FATAL) << "Unknown caffe mode.";
 }
 return loss;
}
I think the protected member of the class layer should be loss_, whose name ends with underline, however, in the code above, there is a line of code '''if (!this->loss(top_id)) { continue; }''', in the line 421 and 432 of the layer.cpp, where the member loss do not end with underline. I want to know where is the mistake I've made. Thanks!


Reply all
Reply to author
Forward
0 new messages