python - 图中重复的节点名称:'conv2d_0/kernel/Adam'
问题描述
我刚刚通过该代码保存了一个模型:
def train():
with tf.Session() as sess:
saver = tf.train.Saver(max_to_keep = 2)
Loss = myYoloLoss([Scale1,Scale2,Scale3],[Y1, Y2 ,Y3])
opt = tf.train.AdamOptimizer(2e-4).minimize(Loss)
init = tf.global_variables_initializer()
sess.run(init)
imageNum = 0
Num = 0
while(1):
#get batchInput
batchImg,batchScale1,batchScale2,batchScale3 = getBatchImage(batchSize = BATCHSIZE)
for epoch in range(75):
_ , epochloss = sess.run([opt,Loss],feed_dict={X:batchImg,Y1:batchScale1,Y2:batchScale2,Y3:batchScale3})
if(epoch%15 == 0):
print(epochloss)
imageNum = imageNum + BATCHSIZE
Num = Num + 1
if(Num%4 == 0):
saver.save(sess,MODELPATH + 'MyModle__' + str(imageNum))
if(os.path.exists(STOPFLAGPATH)):
saver.save(sess,MODELPATH + 'MyModle__Stop_' + str(imageNum))
print('checked stopfile,stop')
break
return 0
然后我得到一些文件:
MyModle__Stop_288.index
MyModle__Stop_288.meta
MyModle__Stop_288.data-00000-of-00001
检查点
然后我继续训练这个模型:
def reTrain():
with tf.Session() as sess:
loder = tf.train.import_meta_graph('E:/MyYoloModel/MyModle__Stop_288.meta')
loder.restore(sess, tf.train.latest_checkpoint('E:/MyYoloModel/'))
graph = tf.get_default_graph()
X = graph.get_tensor_by_name("X:0")
Y1 = graph.get_tensor_by_name("Y1:0")
Y2 = graph.get_tensor_by_name("Y2:0")
Y3 = graph.get_tensor_by_name("Y3:0")
Scale1 = graph.get_tensor_by_name("Scale1:0")
Scale2 = graph.get_tensor_by_name("Scale2:0")
Scale3 = graph.get_tensor_by_name("Scale3:0")
Loss = myYoloLoss([Scale1,Scale2,Scale3],[Y1, Y2 ,Y3])
#error code
opt = tf.train.AdamOptimizer(2e-4).minimize(Loss)
init = tf.global_variables_initializer()
sess.run(init)
batchImg,batchScale1,batchScale2,batchScale3 = getBatchImage(batchSize = BATCHSIZE)
for epoch in range(10):
_ ,epochloss = sess.run([opt,Loss],feed_dict={X:batchImg,Y1:batchScale1,Y2:batchScale2,Y3:batchScale3})
print(epochloss)
并且会出现这个错误: ValueError: Duplicate node name in graph: 'conv2d_0/kernel/Adam'
如何解决?
解决方案
我有一个类似的错误:
ValueError: Duplicate node name in graph: 'packed/0'
我认为此错误是由于与您正在使用的编程代码不同的 Tensorfow 版本造成的。尝试在导入包时降级 tf 版本:
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
这个微不足道的解决方案能够消除这个问题
推荐阅读
- field - 如何在 ARC GIS Pro 中使用 if-then 条件语句替换属性表中的观察值
- sql - SQL Server - 迁移到内存表期间出现内存配额错误
- html - 将文本链接到 ASP.NET MVC 中的另一个页面
- node.js - TypeError:无法读取未定义的属性“事实”
- mysql - 只从右连接mysql获取一个数据
- python-3.x - 有没有一种简单的方法可以将 Oange3 与 Nvidia GPU 一起使用?
- android - 如何在 Kotlin 的 ble 扫描过滤器中使用设备名称
- git - 避免 vscodes 工作区父文件夹显示更改的文件,包括来自存储库选项卡中特定子文件夹的文件
- html - 屏幕变小时菜单栏不可见
- javascript - 单击按钮后,它会执行它的功能,这也会改变它的外观,我希望外观只改变 2 秒而不是恢复正常