我正在使用tensorflow来构建一个简单的自动编码器模型,但是这个奇怪的错误我无法诊断我有一个看起来像这样的损失函数:
def loss_func(x,y):
return 0.5 * tf.reduce_mean(tf.pow(x-y, 2 ) )
然后通过以下方式计算总损失:
return self.loss_func(x , input) + self.reg_fac * reg
现在的问题是,当设置 reg_fac
为 0
时,损失返回为正数,模型似乎训练得很好,但是当增加reg_fac时,损失减少并达到负值并持续下降
对于使用的每个自动编码器, reg
计算如下:
return tf.reduce_mean(tf.pow(self.w1, 2)) + tf.reduce_mean(tf.pow(self.w2, 2))
其中 w1
是编码器权重, w2
是解码器权重 . 我知道's a stupid bug, but I can'找到它 .
我的完整代码上传到这里:https://github.com/javaWarrior/dltest
important files:
ae.py: autoencoders model,
sae.py: stacked autoencoders model,
mew.py: testing model on extracted features of nus_wide images using SIFT,
nus_wide.py: just an interface for nuswide
1 回答
我不确定您的错误来自哪里,但我相信您的自动编码器模型通常存在一些问题 . 简单模型应该看起来像这个例子取自the tensorflow models repo .
As it pertains to the question ,关键区别可能是使用reduce_sum()而不是reduce_mean() . 我不确定你为什么要使用它 .
此外,AdamOptimizer应该为您处理正则化 . 作为旁注,如果你想通过从头开始进行正规化来学习,我会推荐this tutorial .