Minimum normalized layer in coffee

I am new to caffe, I am trying to normalize convolution output between 0 and 1 with minimal normalization.

Out = X - Xmin / (Xmax - Xmin)

I checked many levels (Power, Scale, Batch Normalization, MVN), but nobody gives me min-max Output normalization in layers. Can anyone help me out?

************* my prototype ******************

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 } } } 

The convolution level output is not in normalized form. I want Min-Max Normalized to come out in Layer format. In manual mode, I can use the code, but I need in layers. thanks

+6
source share
1 answer

You can write your own C ++ level following these recommendations , you will see how to implement the "just ahead" on this page.

Alternatively, you can implement a layer in python and execute it in caffe using the "Python layer":

First we implement your layer in python, store it in '/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 

Once you have the python layer implemented, you can simply add it to your network (make sure that '/path/to' is in your $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 } } 
+4
source

Source: https://habr.com/ru/post/1013516/


All Articles