Keras 具有KL发散层的变分自编码器多输出损耗函数

Keras 具有KL发散层的变分自编码器多输出损耗函数,keras,autoencoder,Keras,Autoencoder,我需要为以下模型编写损失函数的帮助: 有5个输入和输出。前两层是分类变量,变量3和4是二进制变量,第五层是连续变量,我将其从0缩放到1。从VAE我想把它们全部重建。你能帮我查一下损失函数的代码吗 KLU散度类看起来像这样: def nll(y_true, y_pred): """ Negative log likelihood (Bernoulli). """ #keras.losses.binary_crossentropy gives the mean #over

我需要为以下模型编写损失函数的帮助:

有5个输入和输出。前两层是分类变量,变量3和4是二进制变量,第五层是连续变量,我将其从0缩放到1。从VAE我想把它们全部重建。你能帮我查一下损失函数的代码吗

KLU散度类看起来像这样:

def nll(y_true, y_pred):
    """ Negative log likelihood (Bernoulli). """
    #keras.losses.binary_crossentropy gives the mean
    #over the last axis. we require the sum
    return K.sum(K.binary_crossentropy(y_true, y_pred), axis=-1)
该层是将KL损耗添加到最终损耗的标识层。 那么你最后的损失可能就是你在上面使用的损失。 类别Kl层(层):

损失函数如下所示:

def nll(y_true, y_pred):
    """ Negative log likelihood (Bernoulli). """
    #keras.losses.binary_crossentropy gives the mean
    #over the last axis. we require the sum
    return K.sum(K.binary_crossentropy(y_true, y_pred), axis=-1)
用这段代码我无法得到正确的重建