如何在Keras中向输入数据添加均匀分布的噪声? [英] How to add a noise with uniform distribution to input data in Keras?
问题描述
我需要在输入数据中添加量化噪声.我经常阅读将这些噪声建模为具有均匀分布的噪声.
I need to add quantization noise to my input data. I read often these kinds of noises are modeled as noise with uniform distribution.
我有一个用Keras实现的编码/解码网络(输入数据是时间序列原始数据),在Keras中实现了一个可以添加高斯噪声的层(GaussianNoise层),我可以使用这一层来创建统一的噪音?
I have an encoding/decoding network implemented with Keras (input data is time series raw data), there is a layer implemented in Keras with which you can add Gaussian noise (GaussianNoise layer), can I use this layer to create uniform noise?
如果没有,我还可以使用其他实现的层吗?
If not, are there other implemented layers that I can use?
推荐答案
您可以这样创建自己的图层,
You can create your own layer as such,
import tensorflow as tf
class noiseLayer(tf.keras.layers.Layer):
def __init__(self,mean,std):
super(noiseLayer, self).__init__()
self.mean = mean
self.std = std
def call(self, input):
mean = self.mean
std = self.std
return input + tf.random.normal(tf.shape(input).numpy(),
mean = mean,
stddev = std)
X = tf.ones([10,10,10]) * 100
Y = noiseLayer(mean = 0, std = 0.1)(X)
此代码可在最新的Tensorflow 2.0中使用.
This code works in the latest Tensorflow 2.0.
这篇关于如何在Keras中向输入数据添加均匀分布的噪声?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!