Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tensorflow graph editor reroute complex network

I try to wrap operation with customized operation.
I solved input of target operation (A in picture) but fail with wrapping output.

Init network operations looks like it.

 C   D
/ \ /
B  A

and assume every operation has 1 output tensor. I want to add operation 'E'

 C   D
/ \ /
B  E
   |
   A

I'm tried with graph editor(API r0.12),
my strategy was that connect A-E and disconnect (C,D)-A and connect (C,D)-E

  1. ge.connect([E], [C,D]) - fail because op C has 2 input
  2. use ge.swap_inputs 2 times - fail, I can attach E and D but still problem with disconnect C-A and connect C-E

How can I change?
Thanks

like image 853
kwanghoon son Avatar asked Jan 31 '17 13:01

kwanghoon son


1 Answers

You need to do some subgraph remapping to make sure the signatures of the two subgraphs match. To do so it's helpful to print the subgraph.

tf.reset_default_graph()

a = tf.placeholder(dtype=tf.float32, name="a")
b = tf.placeholder(dtype=tf.float32, name="b")
c = tf.add(a, b, name="c")
d = tf.identity(a, name="d")

e = tf.identity(a, name="e")
print(ge.sgv(e.op))
print(ge.sgv(c.op, d.op).remap_inputs([0]))
ge.connect(ge.sgv(e.op), ge.sgv(c.op, d.op).remap_inputs([0]))

Outputs:

SubGraphView (graphid=241109520):
** ops[1]:
  e
** inputs[1]:
  a:0
** outputs[1]:
  e:0

SubGraphView (graphid=241109520):
** ops[2]:
  c
  d
** inputs[1]:
  a:0
** outputs[2]:
  c:0
  d:0
like image 166
frank Avatar answered Sep 17 '22 18:09

frank