在内积层,我需要乘以(top_diff * bottom_data) .* (2*weight)
. 首先,我们将 ( result = top_diff * bottom_data
) 计算为矩阵乘法,caffe_cpu_gemm
然后在 和之间进行dot product
计算。weight
result
更多解释定义如下:
const Dtype* weight = this->blobs_[0]->cpu_data();
if (this->param_propagate_down_[0]) {
const Dtype* top_diff = top[0]->cpu_diff();
const Dtype* bottom_data = bottom[0]->cpu_data();
caffe_cpu_gemm<Dtype>(CblasTrans, CblasNoTrans, N_, K_, M_, (Dtype)1.,
top_diff, bottom_data, (Dtype)1., this->blobs_[0]->mutable_cpu_diff());
}
为了进一步了解,我检查了math_function.c
. 它的实现如下:
template<>
void caffe_cpu_gemm<float>(const CBLAS_TRANSPOSE TransA,
const CBLAS_TRANSPOSE TransB, const int M, const int N, const int K,
const float alpha, const float* A, const float* B, const float beta,
float* C) {
int lda = (TransA == CblasNoTrans) ? K : M;
int ldb = (TransB == CblasNoTrans) ? N : K;
cblas_sgemm(CblasRowMajor, TransA, TransB, M, N, K, alpha, A, lda, B,
ldb, beta, C, N);
}
我认为我应该在之后执行乘法 ( result = top_diff * bottom_data
)和. 我应该怎么做?!caffe_cpu_gemm()
dot product
weight
非常感谢!!!!任何意见,将不胜感激!