【发布时间】:2019-09-08 14:44:05
【问题描述】:
我想使用 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]
我为 stddev 输入什么值并不重要(尝试了从 0.001 到 10000 的所有值)。我预计这些值会略有不同(或当 stddev=1000 时差异很大)。我做错了吗?
也许我应该提到我在 Windows 10 上使用 tensorflow-gpu==2.0.0-rc0
【问题讨论】:
标签: python tensorflow keras