【问题标题】:How to add a noise with uniform distribution to input data in Keras?如何在 Keras 中为输入数据添加均匀分布的噪声?
【发布时间】:2019-10-21 10:38:53
【问题描述】:

我需要在输入数据中添加量化噪声。我经常读到这些噪音被建模为均匀分布的噪音。

我有一个使用 Keras 实现的编码/解码网络(输入数据是时间序列原始数据),在 Keras 中实现了一个层,您可以使用它添加高斯噪声(GaussianNoise 层),我可以使用该层创建统一噪音?

如果没有,我可以使用其他实现的层吗?

【问题讨论】:

    标签: python keras noise uniform-distribution


    【解决方案1】:

    您可以这样创建自己的图层,

    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。

    【讨论】:

    • 我正在尝试向我的数据增强层添加泊松噪声。我已经定义了与上面类似的类,但是当我这样做时: data_augmentation = keras.Sequential([ keras.layers.experimental.preprocessing.RandomFlip(), noiseLayer(mean = 1)(x) ], name='DataAugm' ) 我得到错误:添加的层必须是类层的实例。找到:Tensor("noise_layer_7/Identity:0", shape=(None, 29, 29, 1), dtype=float32) 你能帮忙吗?
    • 尝试删除 "(x) " 你不应该在 keras.Sequential 中运行函数
    猜你喜欢
    • 2012-03-21
    • 1970-01-01
    • 2021-07-23
    • 2023-03-11
    • 1970-01-01
    • 2012-12-24
    • 1970-01-01
    • 1970-01-01
    • 2011-04-04
    相关资源
    最近更新 更多