machine learning - Tensorflow: graph building dependent on evaluation -


i writing tensorflow graph of following format:

def process_label(label):     return some_operation(label.eval())  input: x, label output,state = nn_layers() processed_output = process_data(output) processed_label = process_label(processed_output, label) loss = cross_entropy(processed_output, processed_label) optimize = gradientdescentoptimizer.minimize(loss)  session.run(optimize, feed_dict{x:input, label:label}) 

the problem model need values of output in order process label way want can calculate loss. if try use output.eval(session) here, not work, because session execute whole graph , therefore can call in end.

i wonder if theres way can break graph apart in 2 , still have gradient descent work through network, or if theres other way this.

there may flaw in these, here 2 ideas start with: 1) easy vs. 2) efficient:

1) put in 1 graph, though have labels want. execute once outputs (only feeding placeholders required outputs, tensorflow won't require labels placeholder this). run training op, feeding labels placeholder , again placeholders needed outputs. re-run of ops calculate "outputs", not efficient.

2) 2 separate graphs (two sessions might necessary well?). compute outputs , gradient of outputs respect trainable variables (tf.gradients) in graph 1, compute labels needed, compute gradients of loss respect outputs in graph 2 (tf.gradients) (outputs placeholder in graph 2), multiply gradients gradient of loss respect variables, , optizer.apply_gradients() in graph 1.

edit: actually, can use 1 graph in option 2. can feed output directly in output tensor when go calculate d_loss/d_output, shortcutting operations calculate output. i.e. feed_dict not limited placeholders.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -