在tf.GradientTape上下文中澄清有条件的with语句

问题描述

我有以下代码

with tf.GradientTape() as tape:
    # some code in which the object tape doesn't appear

我意识到只有在满足某些tape的情况下,我才想向此condition添加项目。因此,我必须使用带条件的with语句。我找到了this post about conditional with statements,但不确定是否正确。以下代码正确吗?

from contextlib import ExitStack
(...)
with tf.GradientTape() if condition else ExitStack() as tape:
    # some code in which the object tape doesn't appear

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)