1

I try to make a very simple loop in TensorFlow, using the 5 basic Operations (Enter, Merge, Switch, Exit, NextIteration. The problem is, that when a Node (Operation) is added to the Graph, all its inputs have to be given. Since it is a loop (Merge-Switch-NextIteration-Merge) somewhere in the process I have to make a Node without having its Input been available.

The only documentation I found was in a blog (https://blog.csdn.net/mydear_11000/article/details/53693065), saying:

During the graph construction, the inputs to the "Merge" nodes are two copies of each enter node; when the NextIteration nodes are constructed, the Merge nodes are fixed by replacing one of the Enter inputs with a NextIteration input.

It does not say, however how to "fix" it. All documentation and SO answers (e.g. Is it possible to modify an existing TensorFlow computation graph?) say that a Node once added, cannot be changed any more. Can someone help, how to make a loop from these 5 operations (not other higher level while_loop structures and alike)?

As requested, a kind of meta code, what I try to achieve:

Graph.AddPlaceholder('input');
Graph.AddEnter('input','myframe');
Graph.AddMerge(['enteroutput','nextiterationoutput'],2);
Graph.AddGreater('mergeoutput','ten');
Graph.AddSwitch('mergeoutput','greateroutput');
Graph.AddExit('swithtrueoutput');
Graph.AddAdd('switchfalseoutput','one');
Graph.AddNextIteration('addoutput');

The problem, that AddMerge fails, because at that time the NextIteration node is not yet created, so the TF_AddInput function, (what is inside Graph.AddMerge) cannot add the input. This is why the quoted blog suggested to create the Merge node with some "temporary" value, e.g.

Graph.AddMerge(['enteroutput','enteroutput'],2);

and once NextIteration is added to the Graph in the last step, "fix" the Merge node. This is what I cannot do.

jollytall
  • 117
  • 8
  • Why do you have both `C` and `Python` tags? In which language are you most interested in seeing a response? And also, very important that you provide some of your code to show exactly what you have tried, to illustrated exactly where it failed. ( [mcve] ). – ryyker Feb 21 '20 at 18:21
  • Actually I use Pascal, but do not see people doing the same. I use it with an interface, based on the C interface (c_api.h). Anyway, this is not specific to the language it is used with, this seems to me general TensorFlow, but there is no such tag as "elementary operation", or alike. This is also the reason, why I cannot give a code (it uses my own interface, that would not be much help. I try to add a metacode, anyway. – jollytall Feb 21 '20 at 19:58

0 Answers0