【tensorflow】重置/清除計算圖


調用tf.reset_default_graph()重置計算圖

當在搭建網絡查看計算圖時,如果重復運行程序會導致重定義報錯。為了可以在同一個線程或者交互式環境中(ipython/jupyter)重復調試計算圖,就需要使用這個函數來重置計算圖,隨后修改計算圖再次運行。

#重置計算圖,清理當前定義節點
import tensorflow as tf
tf.reset_default_graph()

#Your model defined below
#

需要注意的是,下面三種情況使用這個函數會報錯:

#1
with graph.as_default():
	#不能用

#2
with tf.Session(): block.
	#不能用
#3
tf.InteractiveSession() 
#Your regions
#不能用
sess.close().

也就是說這個函數需要在with tf.session()外部調用。

在這里插入圖片描述
pic from pexels.com


ref:
https://stackoverflow.com/questions/46893824/do-not-use-tf-reset-default-graph-to-clear-nested-graphs
https://www.w3cschool.cn/tensorflow_python/tensorflow_python-nmgf2idd.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM