Caffe之网络输出

1、fc层

例如caffenet的fc8层:

[plain]  view plain  copy
  1. layer {    
  2.   name: "fc8"    
  3.   type: "InnerProduct"    
  4.   bottom: "fc7"    
  5.   top: "fc8"    
  6.   param {    
  7.     lr_mult: 1    
  8.     decay_mult: 1    
  9.   }    
  10.   param {    
  11.     lr_mult: 2    
  12.     decay_mult: 0    
  13.   }    
  14.   inner_product_param {    
  15.     num_output: 1000    
  16.     weight_filler {    
  17.       type: "gaussian"    
  18.       std: 0.01    
  19.     }    
  20.     bias_filler {    
  21.       type: "constant"    
  22.       value: 0    
  23.     }    
  24.   }    
  25. }  

最后一个全连接层:神经元个数 = 类别数, 输出值位于区间[−∞,∞],并不是概率值,输出数值最大的值的index就是样本的预测类别;


2、Accuracy层

例如caffenet的accuracy层:

[plain]  view plain  copy
  1. layer {    
  2.   name: "accuracy"    
  3.   type: "Accuracy"    
  4.   bottom: "fc8"    
  5.   bottom: "label"    
  6.   top: "accuracy"    
  7.   include {    
  8.     phase: TEST    
  9.   }    
  10. }  

Accuracy = fc8层 输出 对比 数据集的labels,在AccuracyLayer中实现;

3、Softmax function

[plain]  view plain  copy
  1. layer {    
  2.   name: "prob"    
  3.   type: "Softmax"    
  4.   bottom: "fc8"    
  5.   top: "prob"    
  6. }  

为了使输出具有统计意义,需要加入softmax function输出似然值。

softmax function是增函数,它使前面的全连接层输出(fc8)具有了概率意义,并不改变这些输出之前的大小关系; 


4、loss function

[plain]  view plain  copy
  1. layer {  
  2.   name: "loss"  
  3.   type: "SoftmaxWithLoss"  //loss fucntion的类型  
  4.   bottom: "pred"  //loss fucntion的输入数据blob,即网络的预测值lable  
  5.   bottom: "label"  //loss function的另外一个输入数据blob,即数据集的真实label  
  6.   top: "loss" //loss的输出blob,即分类器的loss 值  
  7. }  

为了利用误差反向传播,还需要构造loss function,利用softmax function的输出,即输入样本属于每一类的概率值;

粗略地讲,loss function用来衡量估计值和真实值之间的误差情况,在caffe中,包含常用的loss function主要有以下几种:

(1)softmax:图像多类分类问题中主要就是用它; 

  • Layer type: SoftmaxWithLoss

(2)Sum-of-Squares / Euclidean:主要用在线性回归中;

  • Layer type: EuclideanLoss

(3)Hinge / Margin:主要用在SVM分类器中;

  • Layer type: HingeLoss

(4)Sigmoid Cross-Entropy

  • Layer type: SigmoidCrossEntropyLoss

(5)Infogain

  • Layer type: InfogainLoss

猜你喜欢

转载自blog.csdn.net/jdk_yxs/article/details/79816960