Caffe2 - Python API
A deep learning, cross platform ML framework
Public Member Functions | List of all members
net_builder.Operations Class Reference
Inheritance diagram for 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 task_init (self)
 
def task_exit (self)
 
def local_init (self)
 
def local_exit (self)
 
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 105 of file net_builder.py.

Member Function Documentation

◆ __getattr__()

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

Definition at line 126 of file net_builder.py.

◆ If()

def 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 222 of file net_builder.py.

◆ local_exit()

def net_builder.Operations.local_exit (   self)
Similar to `task_init`, but executes at TaskGroup's exit instead,
after all tasks of the group finished execution.

Definition at line 276 of file net_builder.py.

◆ local_init()

def 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.

Definition at line 267 of file net_builder.py.

◆ local_reporter()

def 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 298 of file net_builder.py.

◆ loop()

def 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 174 of file net_builder.py.

◆ net()

def 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 109 of file net_builder.py.

◆ stop()

def 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 150 of file net_builder.py.

◆ stop_guard()

def 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 200 of file net_builder.py.

◆ stop_if()

def 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' lower or equal to 0.

Definition at line 161 of file net_builder.py.

◆ task_exit()

def net_builder.Operations.task_exit (   self)
Define operations to be executed at task shutdown.
Useful when implementing processors, that don't have access to the Task
top-level structure.
    Example:
def read_queue(queue):
    with ops.task_exit():
        queue.close(ops.net())
    return queue.read(ops.net())

Definition at line 252 of file net_builder.py.

◆ task_group()

def 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 137 of file net_builder.py.

◆ task_init()

def 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.
    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 235 of file net_builder.py.

◆ task_reporter()

def 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 285 of file net_builder.py.


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