【发布时间】:2018-11-07 21:55:27
【问题描述】:
虽然严格来说不是一个编程问题,但我在这个网站上没有找到任何关于这个主题的信息。我目前正在处理(变分)自动编码器((V)AE),并计划部署它们来检测异常。出于测试目的,我在 tensorflow 中实现了一个 VAE 来检测手写数字。
训练进行得很顺利,重建的图像与原始图像非常相似。但是对于实际使用自动编码器,我必须通过将其与阈值进行比较来确定输入自动编码器的新图像是否为数字。
此时,我有两个主要问题:
1.) 对于训练,我使用了由两个组件组成的损失。第一个是重构误差,它是一个交叉熵函数:
# x: actual input
# x_hat: reconstructed input
epsilon = 1e-10 # <-- small number for numeric stability within log
recons_loss = - f.reduce_sum( x * tf.log( epsilon + x_hat) + (1 - x) * tf.log( epsilon + 1 - x_hat),
axis=1)
第二个是 KL 散度,它衡量两个概率分布的相似程度,因为我们要求潜在变量空间是类似于高斯分布的分布。
# z_mean: vector representing the means of the latent distribution
# z_log_var: vector representing the variances of the latent distribution
KL_div = -0.5 * tf.reduce_sum( 1 + z_log_var - tf.square(z_mean) - tf.exp(z_log_var),
axis=1)
为了确定新图像的重建误差,我是否必须使用训练损失的两个部分?直观地说,我会说不,直接使用 recon_loss。
2.) 如何确定阈值?是否已经实现了我可以使用的 tf 功能?
如果您有任何相关的好资源,请分享链接!
谢谢!
【问题讨论】:
标签: python tensorflow threshold autoencoder