caffe源码 之 Relu层

本文主要实现caffe框架中/src/caffe/layers/Relu_layer.cpp文件,该文件实现的是激活函数Relu。

ReLU是近些年非常流行的激活函数。相比于sigmoid与Tanh,它具有一定的优越性,这三者对比可见https://zhuanlan.zhihu.com/p/21462488?refer=intelligentunit,它的函数公式是f(x)=max(0,x)。换句话说,这个激活函数就是一个关于0的阈值。如下图:::
这里写图片描述

下面记录我在看relu层时的代码注释:::

Relu_layer.hpp:::

#ifndef CAFFE_RELU_LAYER_HPP_
#define CAFFE_RELU_LAYER_HPP_

#include <vector>

#include "caffe/blob.hpp"
#include "caffe/layer.hpp"
#include "caffe/proto/caffe.pb.h"

#include "caffe/layers/neuron_layer.hpp"

namespace caffe {

/**
 * @brief Rectified Linear Unit non-linearity @f$ y = \max(0, x) @f$.
 *        The simple max is fast to compute, and the function does not saturate.
 */
 /*Relu层类,派生于NeuronLayer类*/
template <typename Dtype>
class ReLULayer : public NeuronLayer<Dtype> {
 public:
  /**
   * @param param provides ReLUParameter relu_param,
   *     with ReLULayer options:
   *   - negative_slope (\b optional, default 0).
   *     the value @f$ \nu @f$ by which negative values are multiplied.
   */
   /*构造函数,NeuronLayer层的参数显式传递给ReluLayer,这些参数就是protobuf文件中存储的参数*/
  explicit ReLULayer(const LayerParameter& param)
      : NeuronLayer<Dtype>(param) {}

  /*内联函数,将当前层类型返回*/
  virtual inline const char* typ
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值