Keras:增加噪音后无法进行训练和测试

时间:2018-08-04 10:00:46

标签: python keras deep-learning autoencoder

我建立了一个用于训练和测试的去噪自动编码器,我不得不将数据集(图像)拆分为训练集和测试集。如果我在添加噪点之前分裂了它的工作,但是如果我在添加噪点之后分裂了它不起作用。添加噪声后,我需要拆分。这是什么问题

train_size = int(images.shape[0]*0.8)
x_train = images[0:train_size]
x_test = images[train_size:]

x_train = x_train.astype('float32') / 255.
x_test = x_test.astype('float32') / 255.
x_train = np.reshape(x_train, (len(x_train), 64, 64, 1)) 
x_test = np.reshape(x_test, (len(x_test), 64, 64, 1))  

noise_factor = 0.3
x_train_noisy = x_train + noise_factor * np.random.normal(loc=0.0, scale=2.0, size=x_train.shape) 
x_test_noisy = x_test + noise_factor * np.random.normal(loc=0.0, scale=2.0, size=x_test.shape) 

x_train_noisy = np.clip(x_train_noisy, 0., 1.)
x_test_noisy = np.clip(x_test_noisy, 0., 1.)

这正在工作

noisy_set = images[0:].astype('float32') / 255.
noisy_set = np.reshape(noisy_set, (len(noisy_set), 64, 64, 1)) 

noise_factor = 0.3
noisy_set = noisy_set + noise_factor * np.random.normal(loc=0.0, scale=2.0, size=noisy_set.shape) 


noisy_set = np.clip(noisy_set, 0., 1.)

train_size = int(images.shape[0]*0.8)
x_train = images[0:train_size]
x_train_noisy = noisy_set[0:train_size]
x_test = images[train_size:]
x_test_noisy = noisy_set[train_size:]

这不起作用

0 个答案:

没有答案