Caffe2 - Python API
A deep learning, cross platform ML framework
Functions
control Namespace Reference

Module caffe2.python.control. More...

Functions

def GetConditionBlobFromNet (condition_net)
 
def BoolNet (blobs_with_bool_value)
 
def NotNet (condition_blob_or_net)
 
def MergeConditionNets (name, condition_nets, relation)
 
def CombineConditions (name, condition_nets, relation)
 
def Do (name, nets_or_steps)
 
def DoParallel (name, nets_or_steps)
 
def For (name, nets_or_steps, iter_num)
 
def While (name, condition_blob_or_net, nets_or_steps)
 
def Until (name, condition_blob_or_net, nets_or_steps)
 
def DoWhile (name, condition_blob_or_net, nets_or_steps)
 
def DoUntil (name, condition_blob_or_net, nets_or_steps)
 
def Switch (name, conditions)
 
def SwitchNot (name, conditions)
 
def If (name, condition_blob_or_net, true_nets_or_steps, false_nets_or_steps=None)
 
def IfNot (name, condition_blob_or_net, true_nets_or_steps, false_nets_or_steps=None)
 

Detailed Description

Module caffe2.python.control.

Function Documentation

◆ BoolNet()

def control.BoolNet (   blobs_with_bool_value)
A net assigning constant bool values to blobs. It is mainly used for
initializing condition blobs, for example, in multi-task learning, we
need to access reader_done blobs before reader_net run. In that case,
the reader_done blobs must be initialized.

Args:
blobs_with_bool_value: one or more (blob, bool_value) pairs. The net will
assign each bool_value to the corresponding blob.

returns
bool_net: A net assigning constant bool values to blobs.

Examples:
- BoolNet((blob_1, bool_value_1), ..., (blob_n, bool_value_n))
- BoolNet([(blob_1, net1), ..., (blob_n, bool_value_n)])
- BoolNet((cond_1, bool_value_1))

Definition at line 97 of file control.py.

◆ CombineConditions()

def control.CombineConditions (   name,
  condition_nets,
  relation 
)
Combine conditions of multi nets into a single condition nets. Unlike
MergeConditionNets, the actual body of condition_nets is not copied into
the combine condition net.

One example is about multi readers. Each reader net has a reader_done
condition. When we want to check whether all readers are done, we can
use this function to build a new net.

Args:
    name: name of the new condition net.
    condition_nets: a list of condition nets. The last external_output
                    of each condition net must be single bool value.
    relation: can be 'And' or 'Or'.

Returns:
    - A new condition net. Its last external output is relation of all
      condition_nets.

Definition at line 211 of file control.py.

◆ Do()

def control.Do (   name,
  nets_or_steps 
)
Execute the sequence of nets or steps once.

Examples:
- Do('myDo', net1, net2, ..., net_n)
- Do('myDo', list_of_nets)
- Do('myDo', step1, step2, ..., step_n)
- Do('myDo', list_of_steps)

Definition at line 255 of file control.py.

◆ DoParallel()

def control.DoParallel (   name,
  nets_or_steps 
)
Execute the nets or steps in parallel, waiting for all of them to finish

Examples:
- DoParallel('pDo', net1, net2, ..., net_n)
- DoParallel('pDo', list_of_nets)
- DoParallel('pDo', step1, step2, ..., step_n)
- DoParallel('pDo', list_of_steps)

Definition at line 274 of file control.py.

◆ DoUntil()

def control.DoUntil (   name,
  condition_blob_or_net,
  nets_or_steps 
)
Similar to DoWhile() but execute nets_or_steps when
condition_blob_or_net returns false. It will execute
nets_or_steps before evaluating condition_blob_or_net.

Special case: if condition_blob_or_net is a blob and is pre-set to
true, then only the first net/step of nets_or_steps will be executed and
loop is exited. So you need to be careful about the initial value the
condition blob when using DoUntil(), esp when DoUntil() is called twice.

Definition at line 462 of file control.py.

◆ DoWhile()

def control.DoWhile (   name,
  condition_blob_or_net,
  nets_or_steps 
)
Execute nets_or_steps when condition_blob_or_net returns true. It will
execute nets_or_steps before evaluating condition_blob_or_net.

Args:
condition_blob_or_net: if it is an instance of Net, tts last external_output
  must be a single bool.
nets_or_steps: a ExecutionStep or a Net or a list of ExecutionSteps or
               a list nets.

Returns:
A ExecutionStep instance.

Definition at line 429 of file control.py.

◆ For()

def control.For (   name,
  nets_or_steps,
  iter_num 
)
Execute nets_or_steps iter_num times.

Args:
nets_or_steps: a ExecutionStep or a Net or a list of ExecutionSteps or
               a list nets.
iter_num:    the number times to execute the nets_or_steps.

Returns:
A ExecutionStep instance.

Definition at line 346 of file control.py.

◆ GetConditionBlobFromNet()

def control.GetConditionBlobFromNet (   condition_net)
The condition blob is the last external_output that must
be a single bool

Definition at line 83 of file control.py.

◆ If()

def control.If (   name,
  condition_blob_or_net,
  true_nets_or_steps,
  false_nets_or_steps = None 
)
condition_blob_or_net is first evaluated or executed. If the condition is
true, true_nets_or_steps is then executed, otherwise, false_nets_or_steps
is executed.

If condition_blob_or_net is Net, the condition is its last external_output
that must be a single bool. And this Net will be executred before both
true/false_nets_or_steps so as to get the condition.

Definition at line 527 of file control.py.

◆ IfNot()

def control.IfNot (   name,
  condition_blob_or_net,
  true_nets_or_steps,
  false_nets_or_steps = None 
)
If condition_blob_or_net returns false, executes true_nets_or_steps,
otherwise executes false_nets_or_steps

Definition at line 555 of file control.py.

◆ MergeConditionNets()

def control.MergeConditionNets (   name,
  condition_nets,
  relation 
)
Merge multi condition nets into a single condition nets.

Args:
    name: name of the new condition net.
    condition_nets: a list of condition nets. The last external_output
                    of each condition net must be single bool value.
    relation: can be 'And' or 'Or'.

Returns:
    - A new condition net. Its last external output is relation of all
      condition_nets.

Definition at line 170 of file control.py.

◆ NotNet()

def control.NotNet (   condition_blob_or_net)
Not of a condition blob or net

Args:
condition_blob_or_net can be either blob or net. If condition_blob_or_net
is Net, the condition is its last external_output
that must be a single bool.

returns
not_net: the net NOT the input
out_blob: the output blob of the not_net

Definition at line 129 of file control.py.

◆ Switch()

def control.Switch (   name,
  conditions 
)
Execute the steps for which the condition is true.
Each condition is a tuple (condition_blob_or_net, nets_or_steps).
Note:
  1. Multi steps can be executed if their conditions are true.
  2. The conditions_blob_or_net (if it is Net) of all steps will be
     executed once.

Examples:
- Switch('name', (cond_1, net_1), (cond_2, net_2), ..., (cond_n, net_n))
- Switch('name', [(cond_1, net1), (cond_2, net_2), ..., (cond_n, net_n)])
- Switch('name', (cond_1, net_1))

Definition at line 495 of file control.py.

◆ SwitchNot()

def control.SwitchNot (   name,
  conditions 
)
Similar to Switch() but execute the steps for which the condition is False.

Definition at line 515 of file control.py.

◆ Until()

def control.Until (   name,
  condition_blob_or_net,
  nets_or_steps 
)
Similar to While() but execute nets_or_steps when
condition_blob_or_net returns false

Definition at line 412 of file control.py.

◆ While()

def control.While (   name,
  condition_blob_or_net,
  nets_or_steps 
)
Execute nets_or_steps when condition_blob_or_net returns true.

Args:
condition_blob_or_net: If it is an instance of Net, its last
  external_output must be a single bool.
nets_or_steps: a ExecutionStep or a Net or a list of ExecutionSteps or
               a list nets.

Returns:
A ExecutionStep instance.

Definition at line 372 of file control.py.