caffe rpn layer 中的 reshape layer

Reshape层:(改变blob的形状,N,C,W,H)

    layer {  
        name: "reshape"  
        type: "Reshape"  
        bottom: "input"  
        top: "output"  
        reshape_param {  
          shape {  
            dim: 0  # copy the dimension from below  
            dim: 2  
            dim: 3  
            dim: -1 # infer it from the other dimensions  
          }  
        }  
      }  
      
    #有一个可选的参数组shape, 用于指定blob数据的各维的值(blob是一个四维的数据:n*c*w*h)。  
      
    #dim:0  表示维度不变,即输入和输出是相同的维度。  
      
    #dim:2 或 dim:3 将原来的维度变成2或3  
      
    #dim:-1 表示由系统自动计算维度。数据的总量不变,系统会根据blob数据的其它三维来自动计算当前维的维度值 。  
      
    #假设原数据为:32*3*28*28, 表示32张3通道的28*28的彩色图片  
    #   shape {  
    #   dim: 0  32-32  
    #   dim: 0  3-3  
    #   dim: 14 28-14  
    #   dim: -1 #让其推断出此数值  
    #   }  
      
    #输出数据为:32*3*14*56  

Reshape layer只改变输入数据的维度,但内容不变,也没有数据复制的过程,与Flatten layer类似。

输出维度由reshape_param 指定,正整数直接指定维度大小,下面两个特殊的值:

  • 0 => 表示copy the respective dimension of the bottom layer,复制输入相应维度的值。
  • -1 => 表示infer this from the other dimensions,根据其他维度自动推测维度大小。reshape_param中至多只能有一个-1。

再举一个例子:如果指定reshape_param参数为:{ shape { dim: 0 dim: -1 } } ,那么输出和Flattening layer的输出是完全一样的。

Flatten层和Reshape层想似:

类型:Flatten

Flatten层是把一个输入的大小为n * c * h * w变成一个简单的向量,其大小为 n * (c*h*w)。