简体   繁体   English

如何在 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.我经常读到这些噪音被建模为均匀分布的噪音。

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?我有一个使用 Keras 实现的编码/解码网络(输入数据是时间序列原始数据),在 Keras 中实现了一个层,您可以使用它添加高斯噪声(GaussianNoise 层),我可以使用该层来创建均匀噪声吗?

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)

This code works in the latest Tensorflow 2.0.此代码适用于最新的 Tensorflow 2.0。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM