我正在尝试使用Kefar在CIfar-10数据集上实现JSCC自动编码器。但是输出图像的值始终仅为1。
我是Keras的新手,我没有找到解决方法。
model = Sequential()
model.add(Conv2D(16,(5,5),padding = 'same', strides = 2, input_shape=X_train.shape[1:]))
model.add(Activation('relu'))
model.add(Conv2D(32,(5,5),padding = 'same', strides = 2))
model.add(Activation('relu'))
model.add(Conv2D(32,(5,5),padding = 'same'))
model.add(Activation('relu'))
model.add(Conv2D(32,(5,5),padding = 'same'))
model.add(Activation('relu'))
model.add(Flatten())
model.add(Dense(100))
model.add(Activation('relu'))
model.add(keras.layers.GaussianNoise(0.1))
model.add(Dense(2048))
model.add(Activation('relu'))
model.add(Reshape((8,8,32)))
model.add(Conv2DTranspose(32,(5,5), padding = 'same'))
model.add(Activation('relu'))
model.add(Conv2DTranspose(32,(5,5), padding = 'same'))
model.add(Activation('relu'))
model.add(Conv2DTranspose(32,(5,5), strides = 2 ,padding = 'same'))
model.add(Activation('relu'))
model.add(Conv2DTranspose(3,(5,5), strides = 2 ,padding = 'same'))
model.add(Activation('sigmoid'))
model.compile(loss='mse', optimizer='adam')
model.fit(X_train_norm, X_train_norm,
batch_size=128,
epochs=20,
validation_data=(X_test_norm, X_test_norm),
shuffle=True)
该模型将图像压缩为长度为100的矢量,并加上高斯噪声,然后将矢量上采样为原始输入。
Train on 50000 samples, validate on 10000 samples
Epoch 1/20
50000/50000 [==============================] - 7s 138us/step - loss: 0.0245 - val_loss: 0.0226
Epoch 2/20
50000/50000 [==============================] - 6s 120us/step - loss: 0.0225 - val_loss: 0.0222
Epoch 3/20
50000/50000 [==============================] - 6s 121us/step - loss: 0.0220 - val_loss: 0.0216
Epoch 4/20
50000/50000 [==============================] - 6s 121us/step - loss: 0.0214 - val_loss: 0.0211
Epoch 5/20
50000/50000 [==============================] - 6s 119us/step - loss: 0.0208 - val_loss: 0.0207
...
>>>model.predict(X_train[:32])
array([[[[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.],
...,
答案 0 :(得分:1)
您在训练期间使用了标准化数据,但在预测时使用了原始数据。
而不是:
model.predict(X_train[:32])
使用:
model.predict(X_train_norm[:32])