Tensorflow partial_run() “Must run 'setup' before performing partial runs!” despite being set up

后端 未结 2 2071
清歌不尽
清歌不尽 2021-01-24 20:29

I am building a proof-of-concept around running sub-graphs without recomputing, using tensorflow\'s partial_run() methods.

Currently I have a simple little python script

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-24 20:54

    This example from API documentation works :

    import tensorflow as tf
    a = tf.placeholder(tf.float32, shape=[])
    b = tf.placeholder(tf.float32, shape=[])
    c = tf.placeholder(tf.float32, shape=[])
    r1 = tf.add(a, b)
    r2 = tf.multiply(r1, c)
    
    with tf.Session() as sess:
        h = sess.partial_run_setup([r1, r2], [a, b, c])
        res = sess.partial_run(h, r1, feed_dict={a: 1, b: 2})
        res = sess.partial_run(h, r2, feed_dict={c: 2})        
        print(res) #prints 6.0
    

    But if we add on more invocation it doesn't . If this doesn't work what is the points in using partial_run.

    import tensorflow as tf
    a = tf.placeholder(tf.float32, shape=[])
    b = tf.placeholder(tf.float32, shape=[])
    c = tf.placeholder(tf.float32, shape=[])
    r1 = tf.add(a, b)
    r2 = tf.multiply(r1, c)
    
    with tf.Session() as sess:
        h = sess.partial_run_setup([r1, r2], [a, b, c])
        res = sess.partial_run(h, r1, feed_dict={a: 1, b: 2})
        res = sess.partial_run(h, r2, feed_dict={c: 2})
        res = sess.partial_run(h, r2, feed_dict={c: 3})
    
        print(res)
    InvalidArgumentError: Must run 'setup' before performing partial runs!
    

提交回复
热议问题