python - 图形中的重复节点名称 : 'conv2d_0/kernel/Adam'

标签 python tensorflow pre-trained-model

我刚刚通过该代码保存了一个模型:

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:图中重复的节点名称:'conv2d_0/kernel/Adam'
怎么解决?

最佳答案

我有一个类似的错误:

ValueError: Duplicate node name in graph: 'packed/0'

我认为此错误是由于 Tensorfow 版本与您正在使用的代码编写的版本不同所致。 尝试在导入包时降级 tf 版本:

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

这个微不足道的求解器能够消除问题

关于python - 图形中的重复节点名称 : 'conv2d_0/kernel/Adam' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53172215/

相关文章:

python - Python 中的分数

python - 量化 Keras 神经网络模型

python - TensorFlow 中的自定义损失函数用于对训练数据进行加权

python - 访问 PyTorch 中预训练模型中的特定层

python - Pandas 获得每组中最重要的不同记录

Python递归合并排序不起作用

python - Tensorflow如何修改保存为检查点的预训练模型

python - ValueError : `decode_predictions` expects a batch of predictions (i. e。形状的二维数组(样本,1000))。找到形状为 : (1, 的数组 7)

python - 如何在 python 中访问给定变量的名称?

machine-learning - 我可以使用 Kinect 的深度图像重新训练 Inception 的最终层吗?