[英]Neural network with 'tanh' as activation and 'cross-entropy' as cost function did not work
[英]CNN algorithm predicts value of 1.0 and thus the cross-entropy cost function gives a divide by zero warning
我正在使用CNN进行二进制分类。
虽然交叉熵函数是由代码计算的:
(-1 / m) * np.sum(np.multiply(Y, np.log(AL)) + np.multiply(1 - Y, np.log(1 - AL)))
当算法预测值为1.0时,此成本函数给出除零警告。 怎么处理呢? 或者有没有办法避免预测变成1.0,就像任何预处理技能一样?
当我使用更高的数值精度时,它工作正常。 但我仍然对这个警告感到好奇。
这看起来像try / except应该处理除零错误。
try:
my_var = (-1 / m) * np.sum(np.multiply(Y, np.log(AL)) + np.multiply(1 - Y, np.log(1 - AL)))
except ZeroDivisionError:
print("I tried to calculate the result, but I got a divide-by-zero error. Maybe you need to use higher precision.")
exit()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.