0
$\begingroup$
encoding_dim = 3
enc_1=Dense(encoding_dim,activation='sigmoid')
enc_mean=Dense(2)
enc_log_var=Dense(2)
dec_2=Dense(encoding_dim,activation='sigmoid')
dec_1=Dense(myinput_dim,activation='softmax')
x =Input(shape=(myinput_dim,))
enc_x=enc_1(x)
z_mean=enc_mean(enc_x)
z_log_var=enc_log_var(enc_x)
def sampling(args):
    z_mean,z_log_var=args
    epsilon=K.random_normal(shape=(2,),mean=0.,
                            stddev=1)
    return z_mean+K.exp(z_log_var/2)*epsilon
z=Lambda(sampling,output_shape=(2,))([z_mean, z_log_var])
dec_x=dec_2(z)
x_reconstructed=dec_1(dec_x)
VAE=Model(x,x_reconstructed)
VAE.summary()

def vae_loss(x,x_recon):

    recovery_loss = myinput_dim* metrics.binary_crossentropy(x,x_recon)
    kl_loss= -0.5*K.sum(1+z_log_var-K.square(z_mean)-K.exp(z_log_var),axis=-1)

    return recovery_loss + kl_loss

VAE.compile(loss=vae_loss,optimizer='Nadam')
VAE.fit(X_normal_train,X_normal_train,batch_size=12,epochs=100)
predictions = VAE.predict(test1)

I can get prediction result but how can I get VAE reconstruction loss or reconstruction probability?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.