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.