...weights already exists, disallowed. Did you mean to set reuse=True...(解決辦法)

model.inference(train_batch, BATCH_SIZE, N_CLASSES)這個裏面應該有with tf.variable_scope(‘layer1’):這樣的代碼,改爲with tf.variable_scope(‘layer1’, reuse = tf.AUTO_REUSE):

解決:

1 若想要繼續使用並共享當前的TensorFlow模型結構或變量:

按照報錯的提示信息加上reuse=True,例如:

with tf.variable_scope(“a”,reuse=True):
b = tf**.get_variable**(“b”,[0])

2 若想要繼續使用但不共享當前的TensorFlow模型結構或變量:

修改變量名,使其和默認的變量不重名。

3 若想丟棄當前TensorFlow的圖,重新開始構圖:

在報錯位置前加上一行:

tf.reset_default_graph() # 清除默認圖像的堆棧,並重置默認圖

強調:上面方法不行的話:
W = tf.Variable(tf.truncated_normal(filter_shape, stddev=0.1), name=“W”)
b = tf.Variable(tf.consta
nt(0.1, shape=[num_filters]), name=“b”)

————————————————
版權聲明:本文爲CSDN博主「折工大子」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/qq_38262728/article/details/90581445

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章