在Keras中对输入数据进行规范化 [英] Normalization of input data in Keras

查看:697
本文介绍了在Keras中对输入数据进行规范化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DL中的一个常见任务是将输入样本归一化为零均值和单位方差.可以使用以下代码手动"执行标准化:

One common task in DL is that you normalize input samples to zero mean and unit variance. One can "manually" perform the normalization using code like this:

mean = np.mean(X, axis = 0)
std = np.std(X, axis = 0)
X = [(x - mean)/std for x in X]

但是,除了要训练的Keras模型外,还必须保持均值和std值左右以标准化测试数据.由于mean和std是可学习的参数,也许Keras可以学习它们?像这样:

However, then one must keep the mean and std values around, to normalize the testing data, in addition to the Keras model being trained. Since the mean and std are learnable parameters, perhaps Keras can learn them? Something like this:

m = Sequential()
m.add(SomeKerasLayzerForNormalizing(...))
m.add(Conv2D(20, (5, 5), input_shape = (21, 100, 3), padding = 'valid'))
... rest of network
m.add(Dense(1, activation = 'sigmoid'))

希望您能理解我的意思.

I hope you understand what I'm getting at.

推荐答案

BatchNormalization ,了解输入的均值和标准差.我没有尝试将其用作网络的第一层,但据我了解,它应该做的事情与您想要的非常相似.

There's BatchNormalization, which learns mean and standard deviation of the input. I haven't tried using it as the first layer of the network, but as I understand it, it should do something very similar to what you're looking for.

这篇关于在Keras中对输入数据进行规范化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆