zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Remove Element
    C++ 一些STL
    Two Pointers/hash/3Sum/4Sum类题目
    动态规划
    UVa 12657 双向链表
    并行运行环境
    多线程编程
    HTML XML CSS JS 迅速学习
    UVa 11988 数组模拟链表
    静态链表
  • 原文地址:https://www.cnblogs.com/ymjyqsx/p/9221180.html
Copyright © 2011-2022 走看看