小编Ola*_*nto的帖子

Keras GaussianNoise 层没有效果?

我想使用 keras 的功能 API 为我的 CNN 中的图像添加一些高斯噪声,但是在测试一些不同的 stddev 值时,我注意到高斯层对输入数据没有任何作用。我使用以下代码进行测试:

import tensorflow as tf
import numpy as np
import cv2

stddev = 0.1
image = cv2.imread(<img_path>)
image = (image.astype('float32') - 127.5) / 127.5

input_layer = tf.keras.layers.Input(shape=(128,128,3))
gaus = tf.keras.layers.GaussianNoise(stddev)(input_layer)
model = tf.keras.models.Model(inputs=input_layer, outputs=gaus)

noisy_image = model(image)

print(f'Pixel value at 0,0: {image[0,0]}')
print(f'Pixel value at 0,0: {noisy_image.numpy()[0,0]}')
# Output
# Pixel value at 0,0: [ 0.09803922 -0.30980393 -0.56078434]
# Pixel value at 0,0: [ 0.09803922 -0.30980393 -0.56078434]
Run Code Online (Sandbox Code Playgroud)

我为stddev输入什么值并不重要(尝试了从 0.001 到 …

python keras tensorflow

6
推荐指数
1
解决办法
2784
查看次数

标签 统计

keras ×1

python ×1

tensorflow ×1