2016-12-26 45 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