我希望能够缓慢增加训练过程中KL散度项对成本的影响,权重为“ reg”,从reg = 0.0开始,直到达到1.0。我希望将增加的速率调整为超参数。(到目前为止,我只是将“ reg”参数设置为常数0.5)。
Keras是否有执行此操作的功能?
def vae_loss(y_true,y_pred):
reg = 0.5
# Average cosine distance for all words in a sequence
reconstruction_loss = tf.reduce_mean(mean_squared_error(y_true, y_pred),1)
# Second part of the loss ensures the z probability distribution doesn't stray too far from normal
KL_divergence_loss = tf.reduce_mean(tf.log(z_sigma) + tf.div((1 + tf.square(z_mu)),2*tf.square(z_sigma)) - 0.5,1)
loss = reconstruction_loss + tf.multiply(reg,KL_divergence_loss)
return loss