euclidean loss

个人感觉相当于L2范式开平方,也相当于针对两个向量的欧氏距离开平方

说的更直白点就是两个向量对应位置相减得到每个位置的差,然后把每个位置的差开平方再相加

前向传播cpp代码:


template <typename Dtype>
void EuclideanLossLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
    const vector<Blob<Dtype>*>& top) {
  int count = bottom[0]->count();
  caffe_sub(
      count,
      bottom[0]->cpu_data(),
      bottom[1]->cpu_data(),
      diff_.mutable_cpu_data());
  Dtype dot = caffe_cpu_dot(count, diff_.cpu_data(), diff_.cpu_data());
  Dtype loss = dot / bottom[0]->num() / Dtype(2);
  top[0]->mutable_cpu_data()[0] = loss;
}

注意:caffe_cpu_dot做的是点积,点积对应点相乘后还要把所有这些乘积结果相加,不只是做乘积

将bottom0和bottom1按照对应位置相减赋值给diff_这个blob,对这个blob中所有数字开平方相加起来就是loss

相关文章:

  • 2021-08-06
  • 2021-07-06
  • 2022-12-23
  • 2021-04-21
  • 2021-08-17
  • 2022-12-23
  • 2021-12-02
猜你喜欢
  • 2021-12-11
  • 2021-07-17
  • 2021-06-13
  • 2021-12-30
  • 2021-06-18
  • 2021-09-30
  • 2021-07-21
相关资源
相似解决方案