如何在张量流中重用占位符?

时间:2018-11-05 05:37:41

标签: python tensorflow

我尝试将占位符重用于不同形状的输入,但是失败了。我在Internet上搜索答案,但我只发现如何通过variable_scope(“”,reuse = tf.AUTO_REUSE)重用变量。我尝试相同的方法,但没有用。 Python引发异常“ ValueError:图形中的节点名称重复:'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)

0 个答案:

没有答案