|
|
@ -1209,6 +1209,32 @@ class IfElseBlockGuard(object):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class IfElse(object):
|
|
|
|
class IfElse(object):
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
if-else control flow.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
|
|
cond (Variable): condition used to compare.
|
|
|
|
|
|
|
|
name (str, default None): The name of this layer.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
limit = layers.fill_constant_batch_size_like(
|
|
|
|
|
|
|
|
input=label, dtype='int64', shape=[1], value=5.0)
|
|
|
|
|
|
|
|
cond = layers.less_than(x=label, y=limit)
|
|
|
|
|
|
|
|
ie = layers.IfElse(cond)
|
|
|
|
|
|
|
|
with ie.true_block():
|
|
|
|
|
|
|
|
true_image = ie.input(image)
|
|
|
|
|
|
|
|
hidden = layers.fc(input=true_image, size=100, act='tanh')
|
|
|
|
|
|
|
|
prob = layers.fc(input=hidden, size=10, act='softmax')
|
|
|
|
|
|
|
|
ie.output(prob)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with ie.false_block():
|
|
|
|
|
|
|
|
false_image = ie.input(image)
|
|
|
|
|
|
|
|
hidden = layers.fc(input=false_image, size=200, act='tanh')
|
|
|
|
|
|
|
|
prob = layers.fc(input=hidden, size=10, act='softmax')
|
|
|
|
|
|
|
|
ie.output(prob)
|
|
|
|
|
|
|
|
prob = ie()
|
|
|
|
|
|
|
|
"""
|
|
|
|
OUT_IF_ELSE_BLOCKS = 0
|
|
|
|
OUT_IF_ELSE_BLOCKS = 0
|
|
|
|
IN_IF_ELSE_TRUE_BLOCKS = 1
|
|
|
|
IN_IF_ELSE_TRUE_BLOCKS = 1
|
|
|
|
IN_IF_ELSE_FALSE_BLOCKS = 2
|
|
|
|
IN_IF_ELSE_FALSE_BLOCKS = 2
|
|
|
|