请问IfElse Block是否支持嵌套?
Created by: zzhzz
我需要使用 IfElse 结构实现一个三选一的逻辑,于是我这样写了一段代码:
ie1 = fluid.layers.IfElse(cond1)
with ie1.true_block():
_in = rk1_in
_eta = rk1_eta
ie1.output(_in, _eta)
with ie1.false_block():
tmp_rk2_in = rk2_in
tmp_rk2_eta = rk2_eta
tmp_rk3_in = rk3_in
tmp_rk3_eta = rk3_eta
cond2 = fluid.layers.less_than(select, third)
ie2 = fluid.layers.IfElse(cond2)
with ie2.true_block():
tmp_in = tmp_rk2_in
tmp_eta = tmp_rk2_eta
ie2.output(tmp_in, tmp_eta)
with ie2.false_block():
tmp_in = tmp_rk3_in
tmp_eta = tmp_rk3_eta
ie2.output(tmp_in, tmp_eta)
_in, _eta = ie2()
ie1.output(_in, _eta)
其中rk1_in, rk1_eta, rk2_in, rk2_eta, rk3_in, rk3_eta均为fluid.layers.data类型,name属性即为变量名 然后运行之后得到如下信息:
> Traceback (most recent call last):
File "tmp.py", line 11, in <module>
network_fc.init_net(30, 6)
File "/home/zzhzz/tbcnn/classifier/tbcnn_fluid/network_fc.py", line 64, in init_net
ie1.output(_in, _eta)
File "/usr/local/lib/python2.7/dist-packages/paddle/v2/fluid/layers/control_flow.py", line 1143, in __exit__
if not self.cond_block.__exit__(exc_type, exc_val, exc_tb):
File "/usr/local/lib/python2.7/dist-packages/paddle/v2/fluid/layers/control_flow.py", line 1060, in __exit__
self.block.complete()
File "/usr/local/lib/python2.7/dist-packages/paddle/v2/fluid/layers/control_flow.py", line 1097, in complete
if each_name not in input_set
File "/usr/local/lib/python2.7/dist-packages/paddle/v2/fluid/framework.py", line 652, in var
raise ValueError("var %s not in this block" % name)
ValueError: var rk2_tree not in this block
所以我想请问IfElse是否支持嵌套?若支持的话有什么需要注意的地方?