0

I found that it is easy to use lasagne to make a graph like this.

import lasagne.layers as L
class A:
  def __init__(self):
    self.x = L.InputLayer(shape=(None, 3), name='x')
    self.y = x + 1

  def get_y_sym(self, x_var, **kwargs):
    y = L.get_output(self.y, {self.x: x_var}, **kwargs)
    return y

through the method get_y_sym, we could get a tensor not a value, then I could use this tensor as the input of another graph.

But if I use tensorflow, how could I implement this?

Achintha Ihalage
  • 2,310
  • 4
  • 20
  • 33
Huanyu Liao
  • 137
  • 1
  • 3

1 Answers1

0

I'm not familiar with lasagne but you should know that ALL of TensorFlow uses graph based computation (unless you use tf.Eager, but that's another story). So by default something like:

net = tf.nn.conv2d(...)

returns a reference to a Tensor object. In other words, net is NOT a value, it is a reference to the output of the convolution node created by tf.nn.conv2d(...).

These can then be chained:

net2 = tf.nn.conv2d(net, ...) and so on.

To get "values" one has to open a tf.Session:

with tf.Session() as sess:
  net2_eval = sess.run(net2)
zephyrus
  • 1,266
  • 1
  • 12
  • 29