2016-12-26 127 views
6

我是caffe的新手,我試圖使用Min-Max Normalization規範0到1之間的卷積輸出。Caffe中的Min-Max規範化圖層

時間= X - Xmin時/(的Xmax - Xmin時)

我已經檢查了許多層(能力,規模批標準化,MVN),但沒有一個是給我最大最小規範化輸出層。誰能幫我 ??

*************我prototxt *****************

name: "normalizationCheck" 
layer { 
    name: "data" 
    type: "Input" 
    top: "data" 
    input_param { shape: { dim: 1 dim: 1 dim: 512 dim: 512 } } 
} 

layer { 
    name: "normalize1" 
    type: "Power" 
    bottom: "data" 
    top: "normalize1" 
    power_param { 
    shift: 0 
    scale: 0.00392156862 
    power: 1 
    } 
} 

layer { 
    bottom: "normalize1" 
    top: "Output" 
    name: "conv1" 
    type: "Convolution" 
    convolution_param { 
     num_output: 1 
     kernel_size: 1 
     pad: 0 
     stride: 1 
     bias_term: false 
     weight_filler { 
     type: "constant" 
     value: 1 
     } 
    } 
} 

卷積層輸出不規範化形式我希望Min-Max規範化輸出爲圖層格式。手動我可以使用代碼,但我需要在圖層中。 謝謝

+1

,如果你能在代碼中這樣做,你可以自己編寫圖層。但你如何區分這種操作? backprop如何看起來像? – Shai

+0

@Shai - 我沒有使用它進行訓練,所以不需要Back propogation。我只是想獲得過濾的輸出。 – AnkitSahu

+0

@Shai - 如何在代碼中編寫圖層。請解釋 ? – AnkitSahu

回答

4

您可以在these guidelines之後編寫自己的C++圖層,您將看到如何在該頁面中實現「只轉發」圖層。

或者,您可以在Python中實現層,並通過在朱古力執行它'"Python"' layer

首先,在Python實現你的層,將其存儲在'/path/to/my_min_max_layer.py'

import caffe 
import numpy as np 

class min_max_forward_layer(caffe.Layer): 
    def setup(self, bottom, top): 
    # make sure only one input and one output 
    assert len(bottom)==1 and len(top)==1, "min_max_layer expects a single input and a single output" 

    def reshape(self, bottom, top): 
    # reshape output to be identical to input 
    top[0].reshape(*bottom[0].data.shape) 

    def forward(self, bottom, top): 
    # YOUR IMPLEMENTATION HERE!! 
    in_ = np.array(bottom[0].data) 
    x_min = in_.min() 
    x_max = in_.max() 
    top[0].data[...] = (in_-x_min)/(x_max-x_min) 

    def backward(self, top, propagate_down, bottom): 
    # backward pass is not implemented! 
    pass 

一旦你的用Python實現層,你可以簡單地把它添加到您的網絡(確保'/path/to'是在你的$PYTHONPATH):

layer { 
    name: "my_min_max_forward_layer" 
    type: "Python" 
    bottom: "name_your_input_here" 
    top: "name_your_output_here" 
    python_param { 
    module: "my_min_max_layer" # name of python file to be imported 
    layer: "min_max_forward_layer" # name of layer class 
    } 
} 
+1

你的方法似乎是正確的,但實際上我不能在cpp窗口中實現,因爲vision_layers.hpp不存在於我的工作區中...你能幫我用cpp嗎? – AnkitSahu

+0

@AnkitSahu你不需要'vision_layers.hpp'它已被棄用。按照[此鏈接](https://github.com/BVLC/caffe/wiki/Development)中的指導原則完成! – Shai