1.报如下错误:
tensorflow.python.framework.errors_impl.InvalidArgumentError: assertion failed: [predictions must be >= 0] [Condition x >= y did not hold element-wise:] [x (sub_2:0) = ] [[-nan][-nan][-nan]...] [y (Cast_2/x:0) = ] [0]
[[{{node assert_greater_equal/Assert/AssertGuard/else/_1/assert_greater_equal/Assert/AssertGuard/Assert}}]] [Op:__inference_train_function_1223]
Function call stack:
train_function
训练模型是想要绘制AUC曲线,报上面这个错误。错误表明predictions value 为非负。
但是实际的情况是好像为0也不可以,应该在计算AUC时候,用了tf.sqrt()函数,所以报错。使用sigmod(x)函数作为最后一层的激活函数时,因为x过小,导致函数值为0(由于计算机自身进行相关取舍)。
2.解决办法:
outputs = tf.clip_by_value(outputs, 1e-10, 0.9999)
对输出值进行了相关限制,保证输出值>0。
3.参考资料:
https://blog.csdn.net/u011630575/article/details/113893585
https://stackoverflow.com/questions/63170518/assertion-failed-predictions-must-be-0-condition-x-y-did-not-hold-elemen(该链接中的解决办法链接无法打开)
https://blog.csdn.net/snowleopard_bin/article/details/115655143
https://blog.csdn.net/DD_PP_JJ/article/details/115612220
https://blog.csdn.net/baidu_38008726/article/details/110680083