Request for Multi Graph composition

153 views
Skip to first unread message

Peng Yu

unread,
Jul 5, 2018, 9:54:24 AM7/5/18
to dis...@tensorflow.org
Hi, 

Let's say we have two graph/model being defined beforehand, and we want to connect the two graph into one.  the output of graph_a redirect into graph_b. 

But since graph_a and graph_b was being defined as fully functionally graph. Which with placeholder there is no way to connect them, except for eval one after the other in memory, which would lose the gradient propagation benefit 

Is there any thoughts on that? 

Martin Wicke

unread,
Jul 5, 2018, 10:50:14 AM7/5/18
to Peng Yu, Discuss
If you load both into the same Graph object, you can pass an output Tensor in a feed_dict. That will implicitly and temporarily connect the two graphs. 

--
You received this message because you are subscribed to the Google Groups "Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss+u...@tensorflow.org.
To post to this group, send email to dis...@tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/discuss/CAOKWFaJPNXuF0a7WYk2Y0QV9T%3DCfEKAGKjs7UJbQv3qQwviCBA%40mail.gmail.com.

Peng Yu

unread,
Jul 5, 2018, 4:13:29 PM7/5/18
to Martin Wicke, Discuss
it doesn't work as if i pass the tensor as value. 

```
In [10]: import tensorflow as tf

In [11]: with tf.Session() as sess:
    ...:     with tf.Graph().as_default() as g:
    ...:         x = tf.placeholder(tf.int32, [None])
    ...:         a = x + 1
    ...:         y = tf.placeholder(tf.int32, [None])
    ...:         b = y + 1
    ...:         print(b.eval({y:a, x: [1]}))
    ...:
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-11-551942816e5d> in <module>()
      5         y = tf.placeholder(tf.int32, [None])
      6         b = y + 1
----> 7         print(b.eval({y:a, x: [1]}))
      8

/Users/pengyu/.pyenv/versions/2.7.13/lib/python2.7/site-packages/tensorflow/python/framework/ops.pyc in eval(self, feed_dict, session)
    708
    709     """
--> 710     return _eval_using_default_session(self, feed_dict, self.graph, session)
    711
    712

/Users/pengyu/.pyenv/versions/2.7.13/lib/python2.7/site-packages/tensorflow/python/framework/ops.pyc in _eval_using_default_session(tensors, feed_dict, graph, session)
   5169                        "`eval(session=sess)`")
   5170     if session.graph is not graph:
-> 5171       raise ValueError("Cannot use the default session to evaluate tensor: "
   5172                        "the tensor's graph is different from the session's "
   5173                        "graph. Pass an explicit session to "

ValueError: Cannot use the default session to evaluate tensor: the tensor's graph is different from the session's graph. Pass an explicit session to `eval(session=sess)`.
```

On Thu, Jul 5, 2018 at 10:49 AM, Martin Wicke <wi...@google.com> wrote:
If you load both into the same Graph object, you can pass an output Tensor in a feed_dict. That will implicitly and temporarily connect the two graphs. 

On Thu, Jul 5, 2018, 06:54 'Peng Yu' via Discuss <dis...@tensorflow.org> wrote:
Hi, 

Let's say we have two graph/model being defined beforehand, and we want to connect the two graph into one.  the output of graph_a redirect into graph_b. 

But since graph_a and graph_b was being defined as fully functionally graph. Which with placeholder there is no way to connect them, except for eval one after the other in memory, which would lose the gradient propagation benefit 

Is there any thoughts on that? 

--
You received this message because you are subscribed to the Google Groups "Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss+unsubscribe@tensorflow.org.

Peng Yu

unread,
Jul 5, 2018, 4:15:41 PM7/5/18
to Martin Wicke, Discuss
```

In [13]: with tf.Session() as sess:
    ...:     with tf.Graph().as_default() as g:
    ...:         x = tf.placeholder(tf.int32, [None])
    ...:         a = x + 1
    ...:         y = tf.placeholder(tf.int32, [None])
    ...:         b = y + 1
    ...:         print(sess.run(b, feed_dict={y:a, x:[1]}))
    ...:
    ...:
    ...:
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-13-b28a8dc00625> in <module>()
      5         y = tf.placeholder(tf.int32, [None])
      6         b = y + 1
----> 7         print(sess.run(b, feed_dict={y:a, x:[1]}))
      8
      9

/Users/pengyu/.pyenv/versions/2.7.13/lib/python2.7/site-packages/tensorflow/python/client/session.pyc in run(self, fetches, feed_dict, options, run_metadata)
    898     try:
    899       result = self._run(None, fetches, feed_dict, options_ptr,
--> 900                          run_metadata_ptr)
    901       if run_metadata:
    902         proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)

/Users/pengyu/.pyenv/versions/2.7.13/lib/python2.7/site-packages/tensorflow/python/client/session.pyc in _run(self, handle, fetches, feed_dict, options, run_metadata)
   1058       raise RuntimeError('Attempted to use a closed Session.')
   1059     if self.graph.version == 0:
-> 1060       raise RuntimeError('The Session graph is empty.  Add operations to the '
   1061                          'graph before calling run().')
   1062

RuntimeError: The Session graph is empty.  Add operations to the graph before calling run().
```

Martin Wicke

unread,
Jul 5, 2018, 4:54:51 PM7/5/18
to Peng Yu, Discuss
Don't to .eval, use session.run. 

To unsubscribe from this group and stop receiving emails from it, send an email to discuss+u...@tensorflow.org.

Peng Yu

unread,
Jul 6, 2018, 10:01:36 AM7/6/18
to Martin Wicke, Discuss
yeah, i did that, check the latest reply ^ still it would complain  
RuntimeError: The Session graph is empty.  Add operations to the graph before calling run().

To unsubscribe from this group and stop receiving emails from it, send an email to discuss+unsubscribe@tensorflow.org.

Martin Wicke

unread,
Jul 6, 2018, 11:04:59 AM7/6/18
to Peng Yu, Discuss
And remove the "with graph" statement. 

To unsubscribe from this group and stop receiving emails from it, send an email to discuss+u...@tensorflow.org.

Peng Yu

unread,
Jul 6, 2018, 1:34:39 PM7/6/18
to Martin Wicke, Discuss
In [3]: with tf.Session() as sess:
   ...:     x = tf.placeholder(tf.int32, [None])
   ...:     a = x + 1
   ...:     y = tf.placeholder(tf.int32, [None])
   ...:     b = y + 1
   ...:     print(sess.run(b, feed_dict={y:a, x:[1]}))
   ...:
2018-07-06 13:34:00.518855: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.2 AVX AVX2 FMA
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-47eee1c199ef> in <module>()
      4     y = tf.placeholder(tf.int32, [None])
      5     b = y + 1
----> 6     print(sess.run(b, feed_dict={y:a, x:[1]}))
      7

~/.pyenv/virtualenvs/image-vectorization/3.6.1/lib/python3.6/site-packages/tensorflow/python/client/session.py in run(self, fetches, feed_dict, options, run_metadata)
    893     try:
    894       result = self._run(None, fetches, feed_dict, options_ptr,
--> 895                          run_metadata_ptr)
    896       if run_metadata:
    897         proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)

~/.pyenv/virtualenvs/image-vectorization/3.6.1/lib/python3.6/site-packages/tensorflow/python/client/session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
   1074
   1075           if isinstance(subfeed_val, ops.Tensor):
-> 1076             raise TypeError('The value of a feed cannot be a tf.Tensor object. '
   1077                             'Acceptable feed values include Python scalars, '
   1078                             'strings, lists, numpy ndarrays, or TensorHandles.')

TypeError: The value of a feed cannot be a tf.Tensor object. Acceptable feed values include Python scalars, strings, lists, numpy ndarrays, or TensorHandles.


To unsubscribe from this group and stop receiving emails from it, send an email to discuss+unsubscribe@tensorflow.org.

Martin Wicke

unread,
Jul 6, 2018, 1:35:41 PM7/6/18
to Peng Yu, Derek Murray, Discuss
+Derek Murray Now I'm confused.

To unsubscribe from this group and stop receiving emails from it, send an email to discuss+u...@tensorflow.org.
Reply all
Reply to author
Forward
0 new messages