目的是想要通过ifelse结构 在构建模型的时候,某个tensor赋予不同的值;
我是这样写的:
self.proposals = self.get_proposals()
216 #self.proposals=fluid.layers.Print(self.proposals,message="self.proposals")
217 #one_var = fluid.layers.fill_constant(shape=[1],dtype='float32',value=-1)
218 #_, self.new_proposals = fluid.layers.split(input=self.proposals, num_or_sections=[2,4], dim=1)
219 one_var = fluid.layers.fill_constant_batch_size_like(input=self.proposals[0][0],shape=[1],dtype='float32',value=-1)
220 cond = fluid.layers.equal(self.proposals[0][0],one_var)
221 #fluid.layers.Print(self.new_proposals,message="self.new_proposals1")
222 #with fluid.layers.control_flow.Switch() as switch:
223 # with switch.case(flag):
224 # self.new_proposals = self.proposals
225 ie = fluid.layers.IfElse(cond)
226 with ie.true_block():
227 ie.input(self.proposals)
228 self.new_proposals=self.proposals
229 ie.output(self.new_proposals)
230 with ie.false_block():
231 ie.input(self.proposals)
232 _, self.new_proposals = fluid.layers.split(input=self.proposals, num_or_sections=[2,4], dim=1)
233 ie.output(self.new_proposals)
234 self.new_proposals = ie()
235 fluid.layers.Print(self.new_proposals,message="self.new_proposals")
出现错误:
Traceback (most recent call last):
File "train.py", line 264, in
train()
File "train.py", line 46, in train
model.build_model()
File "/home/vis/duyuting/code/yolov3_drive/models/yolov3.py", line 227, in build_model
ie.input(self.proposals)
File "/home/vis/duyuting/app/python-cuda8-paddle-0.15.1/lib/python2.7/site-packages/paddle/fluid/layers/control_flow.py", line 1616, in input
attrs={'level': 0})
File "/home/vis/duyuting/app/python-cuda8-paddle-0.15.1/lib/python2.7/site-packages/paddle/fluid/framework.py", line 1771, in append_op
attrs=kwargs.get("attrs", None))
File "/home/vis/duyuting/app/python-cuda8-paddle-0.15.1/lib/python2.7/site-packages/paddle/fluid/framework.py", line 1164, ininit
self.desc.infer_shape(self.block.desc)
paddle.fluid.core_avx.EnforceNotMet: Enforce failed. Expected mask_dim.size() == 2, but received mask_dim.size():1 != 2:2.
at [/home/vis/wangjian33/code/Paddle/paddle/fluid/operators/split_lod_tensor_op.cc:159]
PaddlePaddle Call Stacks:
并且想询问一下ifelse是否可以在这种场景下使用
暂无答案!
目前还没有任何答案,快来回答吧!