首页 > 代码库 > 神经网络caffe框架源码解析--softmax_layer.cpp类代码研究

神经网络caffe框架源码解析--softmax_layer.cpp类代码研究



// Copyright 2013 Yangqing Jia
//
#include <algorithm>
#include <vector>

#include "caffe/layer.hpp"
#include "caffe/vision_layers.hpp"
#include "caffe/util/math_functions.hpp"

using std::max;

namespace caffe {

/**
 * 建立softmax网络层
 */
template <typename Dtype>
void SoftmaxLayer<Dtype>::SetUp(const vector<Blob<Dtype>*>& bottom,
      vector<Blob<Dtype>*>* top) {
  CHECK_EQ(bottom.size(), 1) << "Softmax Layer takes a single blob as input.";
  CHECK_EQ(top->size(), 1) << "Softmax Layer takes a single blob as output.";
  //输出分配空间
  (*top)[0]->Reshape(bottom[0]->num(), bottom[0]->channels(),
      bottom[0]->height(), bottom[0]->width());
  //sum_multiplier_这里都是1,用于辅助计算,可以看作一个行向量,或者行数为1的矩阵
  sum_multiplier_.Reshape(1, bottom[0]->channels(),
      bottom[0]->height(), bottom[0]->width());
  Dtype* multiplier_data = http://www.mamicode.com/sum_multiplier_.mutable_cpu_data();>