如何抑制 Tensorflow (Python) 中的特定警告 [英] How to suppress specific warning in Tensorflow (Python)
本文介绍了如何抑制 Tensorflow (Python) 中的特定警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个模型,根据某些条件,它有一些不相关的梯度,而这正是我想要的.但是 Tensorflow 每次遇到未连接的梯度时都会打印出警告.
I have a model that, based on certain conditions, has some unconnected gradients, and this is exactly what I want. But Tensorflow is printing out a Warning every time it encounters the unconnected gradient.
WARNING:tensorflow:Gradients do not exist for variables
有没有办法只抑制这个特定的警告?我不想盲目地抑制所有警告,因为我仍在研究我的模型,因此将来可能会出现意外(并且可能有用)的警告.
Is there any way to only suppress this specific warning? I don't want to blindly suppress all warnings since there might be unexpected (and potentially useful) warnings in the future as I'm still working on my model.
推荐答案
有点 hacky 的方式:
Kinda hacky way:
gradients = tape.gradient(loss, model.trainable_variables)
optimizer.apply_gradients([
(grad, var)
for (grad, var) in zip(gradients, model.trainable_variables)
if grad is not None
])
这篇关于如何抑制 Tensorflow (Python) 中的特定警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文