我正在尝试在VAE中输出kl损失。我的代码基于以下链接中的代码:https://colab.research.google.com/github/tensorflow/probability/blob/master/tensorflow_probability/examples/jupyter_notebooks/Probabilistic_Layers_VAE.ipynb
他们使用
tfpl.MultivariateNormalTriL(
encoded_size,
activity_regularizer=tfpl.KLDivergenceRegularizer(prior, weight=1.0)),
])
为模型损失添加KL散度正则化器。我更改了解码器的输出,现在有几个输出,所有输出都来自编码器的输出(作为解码器的输入),带有一些密集的lstm层,然后像下面那样编译模型
vae.compile(optimizer=optimizer,
loss=['categorical_crossentropy', 'categorical_crossentropy',
'sparse_categorical_crossentropy',
'sparse_categorical_crossentropy',
'sparse_categorical_crossentropy'
],
metrics=[[keras.metrics.CategoricalAccuracy()],
[keras.metrics.CategoricalAccuracy()],
[keras.metrics.SparseCategoricalAccuracy()],
[keras.metrics.SparseCategoricalAccuracy()],
[keras.metrics.SparseCategoricalAccuracy()],
],
)
vae.metrics_names是
[['loss',
'decoder_loss',
'decoder_1_loss',
'decoder_2_loss',
'decoder_3_loss',
'decoder_4_loss',
'decoder_categorical_accuracy',
'decoder_1_categorical_accuracy',
'decoder_2_sparse_categorical_accuracy',
'decoder_3_sparse_categorical_accuracy',
'decoder_4_sparse_categorical_accuracy']]
编译后。而encoder.losses是
[<tf.Tensor 'encoder_output/ActivityRegularizer/truediv:0' shape=() dtype=float32>,
<tf.Tensor 'encoder_output/ActivityRegularizer/truediv_1:0' shape=() dtype=float32>]
解码器损耗为[]
。
vae.losses是
[<tf.Tensor 'encoder_output/ActivityRegularizer/truediv:0' shape=() dtype=float32>,
<tf.Tensor 'encoder_output/ActivityRegularizer/truediv_1:0' shape=() dtype=float32>,
<tf.Tensor 'encoder/encoder_output/ActivityRegularizer/truediv:0' shape=() dtype=float32>,
<tf.Tensor 'encoder/encoder_output/ActivityRegularizer/truediv_1:0' shape=() dtype=float32>,
<tf.Tensor 'encoder_1/encoder_output/ActivityRegularizer/truediv:0' shape=() dtype=float32>,
<tf.Tensor 'encoder_1/encoder_output/ActivityRegularizer/truediv_1:0' shape=() dtype=float32>]
vae.metrics是
[<tensorflow.python.keras.metrics.CategoricalAccuracy at 0x7f475d0209e8>,
<tensorflow.python.keras.metrics.CategoricalAccuracy at 0x7f475d020b70>,
<tensorflow.python.keras.metrics.SparseCategoricalAccuracy at 0x7f475d020d68>,
<tensorflow.python.keras.metrics.SparseCategoricalAccuracy at 0x7f475cd17cf8>,
<tensorflow.python.keras.metrics.SparseCategoricalAccuracy at 0x7f475cd17da0>]
我想记录所有5个交叉熵损失以及kl损失。如何在此处记录KL损失?为什么vae.losss有6个活动调节器损失,而编码器只有2个?这里是第一个损失输出的kl损失吗?
在制作模型之后并在编译之前,我还可以更改KL损失权重吗?我想尝试一些减肥减肥法。