gpt4 book ai didi

c++ - Caffe 中的最小-最大归一化层

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:36:50 24 4
gpt4 key购买 nike

我是 caffe 的新手,我正在尝试使用 Min-Max Normalization 对 0 到 1 之间的卷积输出进行归一化。

输出 = X - Xmin/(Xmax - Xmin)

我已经检查了很多层(幂、比例、批量归一化、MVN),但没有人在层中给我最小-最大归一化输出。任何人都可以帮助我吗??

************* 我的原型(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
}
}
}

卷积层输出不是标准化形式我想要层格式的最小-最大标准化输出。手动我可以使用代码,但我需要在图层中。谢谢

最佳答案

您可以按照these guidelines 编写自己的c++ 层,您将看到如何在该页面中实现“仅向前”层。

或者,您可以在 python 中实现该层并通过 '"Python"' layer 在 caffe 中执行它:

首先,在 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
}
}

关于c++ - Caffe 中的最小-最大归一化层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41328129/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com