Caffe2 - Python API
A deep learning, cross platform ML framework
Public Member Functions | List of all members
caffe2.python.net_builder.Operations Class Reference
Inheritance diagram for caffe2.python.net_builder.Operations:

Public Member Functions

def net (self, net=None, name=None)
 
def __getattr__ (self, op_type)
 
def task_group (self)
 
def stop (self)
 
def stop_if (self, blob)
 
def loop (self, iters=None, name=None)
 
def stop_guard (self, has_stopped_blob=None, name=None)
 
def If (self, cond, name=None)
 
def IfNet (self, cond, name=None)
 
def Else (self, name=None)
 
def WhileNet (self, name=None)
 
def Condition (self, name=None)
 
def task_init (self)
 
def task_exit (self)
 
def task_instance_init (self)
 
def task_instance_exit (self)
 
def local_init (self)
 
def local_exit (self, name=None)
 
def task_reporter (self, interval_ms=1000, name=None)
 
def local_reporter (self, interval_ms=1000, name=None)
 

Detailed Description

Operations to be used in the context of a NetBuilder.

Definition at line 205 of file net_builder.py.

Member Function Documentation

def caffe2.python.net_builder.Operations.__getattr__ (   self,
  op_type 
)
Adds an operator call to the currently active Net.

Definition at line 226 of file net_builder.py.

def caffe2.python.net_builder.Operations.Condition (   self,
  name = None 
)
Loop's condition, executed within WhileNet context

Definition at line 358 of file net_builder.py.

def caffe2.python.net_builder.Operations.Else (   self,
  name = None 
)
Else branch of IfNet, has to be specified immediately after IfNet.
    Example:
with ops.IfNet(ops.LT([x, y])):
    ...
with ops.Else():
    ...

Definition at line 341 of file net_builder.py.

def caffe2.python.net_builder.Operations.If (   self,
  cond,
  name = None 
)
Creates a NetBuilder that will execute once as the next step of the
current NetBuilder if the blob `cond` is True.
    Example:
with ops.If(ops.Const(True)):
    ops.Print(ops.Const('Will print'))
with ops.If(ops.Const(False)):
    ops.Print(ops.Const('Wont print'))
    The example will print 'Will print' once.

Definition at line 322 of file net_builder.py.

def caffe2.python.net_builder.Operations.IfNet (   self,
  cond,
  name = None 
)
Same as If, but uses 'If' operator instead of execution step logic

Definition at line 335 of file net_builder.py.

def caffe2.python.net_builder.Operations.local_exit (   self,
  name = None 
)
Similar to `task_exit`, but executes at TaskGroup's exit instead,
after all tasks of the group finished execution.
This will run only once on each node.

Definition at line 444 of file net_builder.py.

def caffe2.python.net_builder.Operations.local_init (   self)
Similar to `task_init`, but executes at TaskGroup's startup instead,
before any task of the group starts executing. This will run only
once on each node, before initialization of any task, so it can be
used e.g. to initialize blobs shared across tasks.

Definition at line 433 of file net_builder.py.

def caffe2.python.net_builder.Operations.local_reporter (   self,
  interval_ms = 1000,
  name = None 
)
Similar to task_report, but operations defined within this block
will run repeatedly for as long as any of the tasks in the current
TaskGroup have not finished.

Definition at line 467 of file net_builder.py.

def caffe2.python.net_builder.Operations.loop (   self,
  iters = None,
  name = None 
)
Creates a NetBuilder that will execute in a loop as the next step of
the current NetBuilder. If `iters` is provided, the loop will execute
for `iters` iterations and then stop. `iters` can be a constant or a
BlobReference. If `iters` is not provided, the loop will execute
until `ops.stop` or `ops.stop_if` is called.
    Examples:
a = ops.Const(5)
with ops.loop():
    ops.stop_if(ops.LE([a, ops.Const(0)]))
    ops.Print(a, 0)
    ops.Add([a, ops.Const(-1)], [a])
    Above, 'a' will be printed 5 times, with values 5 to 1.

with ops.loop(10) as loop:
    ops.LogInfo(loop.iter())
    This will print the numbers from 0 to 9.

x = ops.Add([ops.Const(10), ops.Const(10)])
with ops.loop(x) as loop:
    ops.LogInfo(loop.iter())
    This will print the numbers from 0 to 19.

Definition at line 274 of file net_builder.py.

def caffe2.python.net_builder.Operations.net (   self,
  net = None,
  name = None 
)
Retrieves the current net, or add a new net to the builder.
Args:
    net:   If provided, add the given net to the active builder.
   Else, returns the current Net or creates a new one as needed.
    name:  if provided, creates a new Net with given name and makes
   it the new current net of the active builder. Cannot
   be provided if net is provided.

Definition at line 209 of file net_builder.py.

def caffe2.python.net_builder.Operations.stop (   self)
Stop execution of the current execution step.
    Example:
ops.Print(a, 0)
ops.stop()
ops.Print(b, 0)
    In the example, 'b' will never be printed.

Definition at line 250 of file net_builder.py.

def caffe2.python.net_builder.Operations.stop_guard (   self,
  has_stopped_blob = None,
  name = None 
)
Creates a NetBuilder that will execute once as the next step of the
current NetBuilder. After execution, a bool tensor will indicate
whether the inner execution was halted with `stop` or `stop_if`.
    Example:
a = ops.Const(True)
with ops.stop_guard() as sg1:
    ops.stop_if(a)
    ops.Print(ops.Const('did not stop'))
b = ops.Const(False)
with ops.stop_guard() as sg2:
    ops.stop_if(b)
    ops.Print(ops.Const('did not stop'))
ops.Print(sg1.has_stopped(), [])
ops.Print(sg2.has_stopped(), [])
    In the example, 'did not stop' will be printed once,
    followed by True and False.

Definition at line 300 of file net_builder.py.

def caffe2.python.net_builder.Operations.stop_if (   self,
  blob 
)
Stop execution of the current execution step if the
condition `blob` is met.
    Example:
ops.Print(a, 0)
ops.stop_if(ops.LE([x, ops.Const(0)]))
ops.Print(b, 0)
    In the example, 'b' will only be printed if the value of scalar
    tensor 'x' is greater than 0.

Definition at line 261 of file net_builder.py.

def caffe2.python.net_builder.Operations.task_exit (   self)
Define operations to be executed once at task shutdown.
Useful when implementing processors, that don't have access to the Task
top-level structure.

This shutdown will be run only once, after all concurrent instances of
the task have already finished. For instance-local shutdown,
use `task_instance_exit` instead.

    Example:
def read_queue(queue):
    with ops.task_exit():
        queue.close(ops.net())
    return queue.read(ops.net())

Definition at line 388 of file net_builder.py.

def caffe2.python.net_builder.Operations.task_group (   self)
Creates a local task group which will execute as the next step of
the current NetBuilder.

Definition at line 237 of file net_builder.py.

def caffe2.python.net_builder.Operations.task_init (   self)
Defines operations that will be executed once at task startup.
Useful when implementing processors, that don't have access to the Task
top-level structure.

This setup will be run only once, even if multiple instances of the task
will run in parallel. For instance-local initialization, use
`task_instance_init` instead.

    Example:
def my_processor(rec):
    with ops.task_init():
        one = ops.Const(1)
        two = ops.Const(1)
    return Tuple(
        ops.Add(rec[0](), zero), ops.Add(rec[1](), two))

Definition at line 366 of file net_builder.py.

def caffe2.python.net_builder.Operations.task_instance_exit (   self)
Defines operations that will be executed once at shutdown of each
instance of a task. This can be seen as "thread_local" finalization.

This shutdown will be run concurrently for each instance of a task.
For global task shutdown, use `task_exit` instead.

Definition at line 421 of file net_builder.py.

def caffe2.python.net_builder.Operations.task_instance_init (   self)
Defines operations that will be executed once at startup of each
instance of a task. This can be seen as "thread_local" initialization.
It is guaranteed to run only after all `task_init` logic finishes.

This setup will be run concurrently for each instance of a task.
For global task initialization, use `task_init` instead.

Definition at line 408 of file net_builder.py.

def caffe2.python.net_builder.Operations.task_reporter (   self,
  interval_ms = 1000,
  name = None 
)
Define operations to be executed at every time interval from
task start-up to finish. These operations are guaranteed to
execute at least once after all other operations of the task are
finished.

    Example:
with ops.task_reporter(interval_ms=10000):
    ops.LogInfo('10s elapsed')

Definition at line 454 of file net_builder.py.

def caffe2.python.net_builder.Operations.WhileNet (   self,
  name = None 
)
NetBuilder for 'While' control operator

Definition at line 352 of file net_builder.py.


The documentation for this class was generated from the following file: