Layer.hpp中的问题
看了Layer.hpp,有2个地方还不大清楚,请教一下
template <typename Dtype>
inline Dtype Layer<Dtype>::Forward(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top) {
// Lock during forward to ensure sequential forward
Lock();
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.";
}
Unlock();
return loss;
}
代码中“loss += caffe_cpu_dot(count, data, loss_weights);”的loss_weights表示的是SetLossWeights()方法中模板函数caffe_set()所初始化的loss_weight吗?
template <typename Dtype>
inline Dtype Layer<Dtype>::Forward(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top) 里面调用了caffe_gpu_dot函数,我只在math_functions.hpp中找到了它的声明,却没找到它的定义,math_functions.cpp里也没有,请问它的定义在哪里?
2 个回复
孙琳钧
赞同来自: xinmiao 、uestc_yang 、andrewsu90116 、alex68
对于caffe中的loss层,计算出的loss放在top[0]指向的blob里,该blob里的diff存放的就是loss对应的loss_weight,传递过程在Layer的SetUp里通过调用SetLossWeights(top)完成
李扬 - 密码六个一
赞同来自: