How to add a noise with uniform distribution to input data in Keras?

北战南征 提交于 2020-07-09 11:49:27

问题


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?

If not, are there other implemented layers that I can use?


回答1:


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.



来源:https://stackoverflow.com/questions/58484545/how-to-add-a-noise-with-uniform-distribution-to-input-data-in-keras

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!