neural network - about tensorflow backpropagation -


if have 2 neural networks , b, , use output of network feed input(placeholder) of network b. , use optimizer minimize loss of network b, can network a's parameters updated backpropagation?

yes, if "feed" done in tensorflow; no, if manually.

specifically, if evaluate a, train b outputs manually fed in (say, feed dict), not change, because not involved in training stage.

if set input of b network output of op in (instead of tf.placeholder, instance), can train combined network, update a's parameters. in case, though, you're training combined network "ab", not 2 separate networks.

a concrete example:

import numpy np import tensorflow tf  # network a_input = tf.placeholder(tf.float32, [none,100]) a_weights = tf.variable(tf.random_normal([100,10])) a_output = tf.matmul(a_input,a_weights)  # b network b_input = tf.placeholder(tf.float32, [none,10]) b_weights = tf.variable(tf.random_normal([10,5])) b_output = tf.matmul(b_input,b_weights)  # ab network ab_input = a_output ab_weights = tf.variable(tf.random_normal([10,5])) ab_output = tf.matmul(ab_input,ab_weights)  test_inputs = np.random.rand(17,100) sess = tf.session() sess.run(tf.global_variables_initializer()) a_out = sess.run(a_output, feed_dict={a_input: test_inputs}) print 'a output shape:',a_out.shape b_out = sess.run(b_output, feed_dict={b_input: a_out}) print 'b output shape:',b_out.shape  ab_out = sess.run(ab_output, feed_dict={a_input: test_inputs}) print 'ab output shape:',ab_out.shape 

in first case, we've fed network b outputs network using feed_dict. evaluating network in tensorflow, pulling results python, evaluating network b in tensorflow. if try train network b in fashion, you'll update parameters in network b.

in second case, we've fed "b" part of network ab directly connecting outputs of network input of network ab. evaluating network ab never pulls intermediate results of network python, if train network ab in fashion, can update parameters combined network. (note: training inputs feed a_input of network ab, not intermediate tensor ab_input)


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -