变分自动编码器丢失正在增加

时间:2018-02-01 12:49:03

标签: image-processing tensorflow keras convolution autoencoder

这是我创建异常卷积自动编码器的特殊代码,我的问题是丢失函数根本无法收敛到任何东西。我尝试过不同的优化器来计算损失。我的AutoEncoder有什么根本性的错误吗?

import keras
import numpy as np
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dropout, UpSampling2D
from keras.layers import Activation, GlobalAveragePooling2D
from keras.layers.convolutional import Conv2D, Deconv2D
from keras.layers.normalization import BatchNormalization
from keras.utils import np_utils
from keras.layers.advanced_activations import LeakyReLU

(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train = np.reshape(x_train, (60000, 28, 28, 1))
x_train = x_train.astype('float32') / 255.
x_test = np.reshape(x_test, (10000, 28, 28, 1))
x_test = x_test.astype('float32') / 255.
def base_model():
    model = Sequential()
    model.add(Conv2D(64, (3, 3), padding = 'same', name = 'encode_first', input_shape = (28, 28, 1)))
    model.add(LeakyReLU())
    model.add(Conv2D(64, (3, 3), padding = 'same', name = 'encode_second'))
    model.add(LeakyReLU())
    model.add(Conv2D(64, (3, 3), padding = 'same', name = 'encode_third_downsample', strides = 2))
    model.add(LeakyReLU())
    model.add(Conv2D(128, (3, 3), padding = 'same', name = 'encode_fourth'))
    model.add(LeakyReLU())
    model.add(Conv2D(128, (3, 3), padding = 'same', name = 'encode_fifth'))
    model.add(LeakyReLU())
    model.add(Conv2D(128, (3, 3), padding = 'same', name = 'encode_sixth_downsample', strides = 2))
    model.add(LeakyReLU())
    model.add(Deconv2D(128, (3, 3), padding = 'same', name = 'decode_first'))
    model.add(LeakyReLU())
    model.add(Deconv2D(128, (3, 3), padding = 'same', name = 'decode_second'))
    model.add(LeakyReLU())
    model.add(UpSampling2D((2, 2)))
    model.add(LeakyReLU())
    model.add(Deconv2D(64, (3, 3), padding = 'same', name = 'decode_fourth'))
    model.add(LeakyReLU())
    model.add(Deconv2D(64, (3, 3), padding = 'same', name = 'decode_fifth'))
    model.add(LeakyReLU())
    model.add(UpSampling2D((2, 2)))
    model.add(LeakyReLU())
    model.add(Conv2D(1, (28, 28), padding = 'same', name = 'final_layer'))
    model.add(LeakyReLU())
    model.summary()
    model.compile(optimizer = 'adam', loss = 'binary_crossentropy')
    return model

encoder = base_model()
encoder_hist = encoder.fit(x_train, x_train, epochs=50,
                batch_size=256,
                shuffle=True,
                validation_data=(x_test, x_test))

这是我的输出

runfile('D:/Datasets/Siddhesh/Fraud Face/Face-Disguise-Dataset-master/autencoder.py', wdir='D:/Datasets/Siddhesh/Fraud Face/Face-Disguise-Dataset-master')
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
encode_first (Conv2D)        (None, 28, 28, 64)        640       
_________________________________________________________________
leaky_re_lu_14 (LeakyReLU)   (None, 28, 28, 64)        0         
_________________________________________________________________
encode_second (Conv2D)       (None, 28, 28, 64)        36928     
_________________________________________________________________
leaky_re_lu_15 (LeakyReLU)   (None, 28, 28, 64)        0         
_________________________________________________________________
encode_third_downsample (Con (None, 14, 14, 64)        36928     
_________________________________________________________________
leaky_re_lu_16 (LeakyReLU)   (None, 14, 14, 64)        0         
_________________________________________________________________
encode_fourth (Conv2D)       (None, 14, 14, 128)       73856     
_________________________________________________________________
leaky_re_lu_17 (LeakyReLU)   (None, 14, 14, 128)       0         
_________________________________________________________________
encode_fifth (Conv2D)        (None, 14, 14, 128)       147584    
_________________________________________________________________
leaky_re_lu_18 (LeakyReLU)   (None, 14, 14, 128)       0         
_________________________________________________________________
encode_sixth_downsample (Con (None, 7, 7, 128)         147584    
_________________________________________________________________
leaky_re_lu_19 (LeakyReLU)   (None, 7, 7, 128)         0         
_________________________________________________________________
decode_first (Conv2DTranspos (None, 7, 7, 128)         147584    
_________________________________________________________________
leaky_re_lu_20 (LeakyReLU)   (None, 7, 7, 128)         0         
_________________________________________________________________
decode_second (Conv2DTranspo (None, 7, 7, 128)         147584    
_________________________________________________________________
leaky_re_lu_21 (LeakyReLU)   (None, 7, 7, 128)         0         
_________________________________________________________________
up_sampling2d_3 (UpSampling2 (None, 14, 14, 128)       0         
_________________________________________________________________
leaky_re_lu_22 (LeakyReLU)   (None, 14, 14, 128)       0         
_________________________________________________________________
decode_fourth (Conv2DTranspo (None, 14, 14, 64)        73792     
_________________________________________________________________
leaky_re_lu_23 (LeakyReLU)   (None, 14, 14, 64)        0         
_________________________________________________________________
decode_fifth (Conv2DTranspos (None, 14, 14, 64)        36928     
_________________________________________________________________
leaky_re_lu_24 (LeakyReLU)   (None, 14, 14, 64)        0         
_________________________________________________________________
up_sampling2d_4 (UpSampling2 (None, 28, 28, 64)        0         
_________________________________________________________________
leaky_re_lu_25 (LeakyReLU)   (None, 28, 28, 64)        0         
_________________________________________________________________
final_layer (Conv2D)         (None, 28, 28, 1)         50177     
_________________________________________________________________
leaky_re_lu_26 (LeakyReLU)   (None, 28, 28, 1)         0         
=================================================================
Total params: 899,585
Trainable params: 899,585
Non-trainable params: 0
_________________________________________________________________
Train on 60000 samples, validate on 10000 samples
Epoch 1/50
60000/60000 [==============================] - 456s - loss: 0.3532 - val_loss: 0.2613
Epoch 2/50
60000/60000 [==============================] - 438s - loss: 0.1636 - val_loss: 0.1176
Epoch 3/50
60000/60000 [==============================] - 436s - loss: 1.9351 - val_loss: 2.1359
Epoch 4/50
60000/60000 [==============================] - 435s - loss: 2.1060 - val_loss: 2.1359
Epoch 5/50
16640/60000 [=======>......................] - ETA: 297s - loss: 2.1002Traceback (most recent call last):

1 个答案:

答案 0 :(得分:0)

您的损失功能正在增加。原因可能是您使用的是非常大的学习率。