首页 > 解决方案 > 如何在张量流中重用占位符?

问题描述

我试图为不同形状的输入重用占位符但失败了。而我在网上搜索答案,只发现如何通过variable_scope("",reuse=tf.AUTO_REUSE)重用变量。我尝试了同样的方法,但它不起作用。Python 抛出异常“ValueError: Duplicate node name in graph: 'input_image'”。我很困惑,并提前感谢您的帮助。

比如我想训练一个图片为128*128的网络,我想测试一个图片为1080*960的网络:

        with tf.variable_scope('test/', reuse=tf.AUTO_REUSE):
            input_image = tf.placeholder(shape=[batch_size, 128, 128, 3], dtype=tf.float32, name='input_image/')
        aug_image= train_net(input_image)
        sess = tf.Session()
        init = tf.global_variables_initializer()
        sess.run(init)
        for i in range(100000):
           augg = sess.run([aug_image],feed_dict={input_image: tmp})
           if i % 1000 == 0:
               with tf.variable_scope('test/', reuse=True):
                   input_image = tf.placeholder(shape=[1, 1080, 960, 3],dtype=tf.float32,name='input_image/')
                   aug = sess.run([aug_image],{input_image: pic1})
                   show(aug)

标签: pythontensorflow

解决方案


推荐阅读