在变分自动编码器上获得越来越多的损失和糟糕的性能

时间:2018-06-12 19:39:03

标签: python tensorflow machine-learning keras autoencoder

我是神经网络的初学者,目前正致力于利用神经网络分析蛋白质序列比对数据。数据被转换为单热编码二进制数据。我正在使用keras来构建我的变分自动编码器。我的模型有4个“密集”层,用于编码器和解码器。输入通过“BatchNormalization”进行标准化,Dropout图层也会添加到模型中。亚当是优化者。问题是我变得非常巨大而且还在增加损失,他们很快就达到了南方。我尝试使用学习率= 0.1,0.2或0.8并使用衰减来降低学习率。但它没有帮助。我被困在这个模型上一个星期......几乎崩溃了。谢谢你的帮助!

x = Input(shape=(original_dim,))
dr = Dropout(0.7)
h1z = BatchNormalization(mode = 0)(x)
h1 = Dense(intermediate_dim, activation='elu')(h1z)
h2 = dr(Dense(intermediate_dim2, activation='elu')(h1))
h3 = Dense(intermediate_dim3, activation = 'elu')(h2)
h4 = Dense(intermediate_dim4, activation = 'elu')(h3)

z_mean = Dense(latent_dim)(h4)
z_log_var = Dense(latent_dim)(h4)

def sampling(args):
    z_mean, z_log_var = args
    epsilon = K.random_normal(shape=(K.shape(z_mean)[0], latent_dim), 
             mean=0.,stddev=epsilon_std)
return z_mean + K.exp(z_log_var / 2) * epsilon

z = Lambda(sampling, output_shape=(latent_dim,))([z_mean, z_log_var])
decoder_h4 = Dense(intermediate_dim4, activation = 'elu')
decoder_h3 = Dense(intermediate_dim3, activation='elu')
decoder_h2 = Dense(intermediate_dim2, activation='elu')
decoder_h1 = Dense(intermediate_dim, activation='elu')
drd = Dropout(0.7)  
decoder_mean = Dense(original_dim, activation='sigmoid')

h_decoded4 = BatchNormalization(mode = 0)(decoder_h4(z))
h_decoded3 = decoder_h3(h_decoded4)
h_decoded2 = drd(decoder_h2(h_decoded3))
h_decoded1 = decoder_h1(h_decoded2)
x_decoded_mean = decoder_mean(h_decoded1)

def vae_loss(x, x_decoded_mean):
    xent_loss = original_dim * metrics.binary_crossentropy(x,
           x_decoded_mean)
    kl_loss = - 0.5 * K.sum(1 + z_log_var - K.square(z_mean) - 
            K.exp(z_log_var), axis=-1)
    return K.mean(xent_loss + kl_loss)

vae = Model(x, x_decoded_mean)
vae.compile(optimizer=Adam(lr = 0, decay = 0), loss=vae_loss, metrics= 
      `enter code here`["categorical_accuracy","top_k_categorical_accuracy"])

0 个答案:

没有答案