Tensorflow 中是否有一個選項可以設置為忽略Assert我添加到我的所有操作Graph?我正在考慮的用例是使用 添加一堆斷言tf.contrib.framework.with_shape,然后在我的配置文件中切換一個標志,config.fast以決定我是否應該在訓練期間跳過這些斷言。通常我會Asserts首先根據是否config.fast設置來選擇是否生成,但是在使用時with_shape,將此選項鏈接到我的張量似乎更方便,而無需查看我的config.fast.
1 回答

茅侃侃
TA貢獻1842條經驗 獲得超22個贊
我最終使用了類似于@jdehesa 的評論建議的東西,但使用了分支工廠函數而不是tf.cond.
def make_maybe_with_shape(skip_asserts):
if skip_asserts: # identity
return lambda expected_shape, tensor: tensor
else:
return lambda expected_shape, tensor: tf.contrib.framework.with_shape(
expected_shape, tensor)
添加回答
舉報
0/150
提交
取消