2

假设我有两个 tensorflow 模型(A 和 B),它们的图形完全相同,但每一层的权重不同。我想将 A 中的层 conv1、conv2、conv3 和 B 中的层 conv4、conv5、conv6 合并到一个模型 C 中。模型 C 与 A 和 B 具有相同的结构,但权重不同。我知道如何使用以下代码从每个模型中单独加载层,并制作了两个单独的模型,每个模型仅包含 conv1、2、3 或 4、5、6。但我不知道如何用 conv1,2,3,4,5,6 构建模型 C。

     exclude1=['conv1',...]
     exclude2=['conv4',...]
     variables_to_restore1=slim.get_variables_to_restore(exclude=exclude1)
     variables_to_restore2=slim.get_variables_to_restore(exclude=exclude2)
     saver1 = tf.train.Saver(variables_to_restore1)
     saver2 = tf.train.Saver(variables_to_restore2)
     saver1.restore(sess,args.model)
     saver2.restore(sess,args.model)
     saver1.save(sess, "Model/convlayers1.ckpt")
     saver2.save(sess, "Model/convlayers2.ckpt")    

我已经学习 tensorflow 几个月了,但还没有见过这样的东西。非常感谢!

4

0 回答 0