Caffe2 - Python API
A deep learning, cross platform ML framework
Classes | Functions | Variables
core Namespace Reference

Module caffe2.python.core. More...

Classes

class  BlobReference
 
class  DataType
 
class  ExecutionStep
 
class  GradientRegistry
 
class  IR
 
class  Net
 
class  Plan
 

Functions

def RefreshRegisteredOperators ()
 
def GlobalInit (args)
 
def GetGlobalInitArgs ()
 
def worker_init_func (func)
 
def GetWorkerInitCalls ()
 
def IsOperator (op_type)
 
def IsOperatorWithEngine (op_type, engine)
 
def DeviceOption (device_type, cuda_gpu_id=0, random_seed=None)
 
def ScopedName (name)
 
def ScopedBlobReference (name, args, kwargs)
 
def CreateOperator (operator_type, inputs, outputs, name='', control_input=None, device_option=None, arg=None, engine=None, kwargs)
 
def CreatePythonOperator (f, inputs, outputs, grad_f=None, pass_workspace=False, args, kwargs)
 
def GetIndexFromGradientList (g_list, name)
 
def get_ssa (net, blob_versions=None)
 
def get_undefined_blobs (ssa)
 
def get_output_producers (ssa)
 
def get_op_ids_in_path (ssa, blob_versions, inputs, outputs)
 
def clone_and_bind_net (net, name, prefix, blob_remap=None, inputs=None, keep_schema=True)
 
def get_net_name (netlike)
 
def output_to_list (op_output)
 
def add_nets_in_order (step, net_list)
 
def to_execution_step (step_or_nets, default_name=None)
 
def execution_step (default_name, steps_or_nets, num_iter=None, report_net=None, report_interval=None, concurrent_substeps=None, should_stop_blob=None, only_once=None)
 
def scoped_execution_step (name, args, kwargs)
 

Variables

 DeviceScope = scope.DeviceScope
 
 NameScope = scope.NameScope
 
 basestring = str
 
 GradientSlice = namedtuple('GradientSlice', ['indices', 'values'])
 
 OpSSA = namedtuple('OpSSA', ['op', 'in_versions', 'out_versions'])
 
 GradGenMeta = namedtuple('GradGenMeta', ['grad_op', 'idx', 'gradient'])
 
 SparseGradGenMeta
 

Detailed Description

Module caffe2.python.core.

Function Documentation

◆ clone_and_bind_net()

def core.clone_and_bind_net (   net,
  name,
  prefix,
  blob_remap = None,
  inputs = None,
  keep_schema = True 
)
Clone the given Net, binding its input schema to the given `inputs` record.
Blob names defined by the net are prepended with the given `prefix`.

Args:
    net:        the net to clone
    name:       the name of the new net
    prefix:     the prefix to append to local blobs
    blob_remap: (optional) dict with additional blob name remapping.
    inputs:     (optional) input record that will provide actual input
                values for the cloned net. Must be compatible with the
                net's input schema or be a strict superset of it
    keep_schema: by default (True), the original schema will be kept and
                 remapped accordingly. otherwise, the schema will be set as
                 inputs or left empty if inputs is not given.
Returns:
    Tuple (cloned_net, blob_remap)
    clone_net:  the cloned Net
    blob_remap: a map from original blob names into remapped blob names

Definition at line 1057 of file core.py.

◆ CreateOperator()

def core.CreateOperator (   operator_type,
  inputs,
  outputs,
  name = '',
  control_input = None,
  device_option = None,
  arg = None,
  engine = None,
  kwargs 
)
A function wrapper that allows one to create operators based on the
operator type. The type should be a string corresponding to an operator
registered with Caffe2.

Definition at line 259 of file core.py.

◆ CreatePythonOperator()

def core.CreatePythonOperator (   f,
  inputs,
  outputs,
  grad_f = None,
  pass_workspace = False,
  args,
  kwargs 
)
`f` should have a signature (inputs, outputs)

If `pass_workspace` is True, the signature is changed to
(inputs, outputs, workspace) where `workspace` is the workspace the op
is going to run on. This is potentially dangerous (as the op can manipulate
the workspace directly), use on your own risk.

Definition at line 322 of file core.py.

◆ execution_step()

def core.execution_step (   default_name,
  steps_or_nets,
  num_iter = None,
  report_net = None,
  report_interval = None,
  concurrent_substeps = None,
  should_stop_blob = None,
  only_once = None 
)
Helper for creating an ExecutionStep.
- steps_or_nets can be:
  - None
  - Net
  - ExecutionStep
  - list<Net>
  - list<ExecutionStep>
- should_stop_blob is either None or a scalar boolean blob.
  - This blob is checked AFTER every substeps/subnets.
  - If specified and true, then this step will return immediately.
  - Be sure to handle race conditions if setting from concurrent threads.
- if no should_stop_blob or num_iter is provided, defaults to num_iter=1

Definition at line 2018 of file core.py.

◆ get_op_ids_in_path()

def core.get_op_ids_in_path (   ssa,
  blob_versions,
  inputs,
  outputs 
)
Given a ssa and blob_versions as produced by get_ssa(), returns the list
of op indices that are necessary in order to generate the blobs in
`outputs`, given blobs in `inputs`.
Consider that the `inputs` are given in their latest version.

Definition at line 1034 of file core.py.

◆ get_output_producers()

def core.get_output_producers (   ssa)
Given a ssa in the format produced by get_ssa(), returns a map from
versioned blob into the operator index that produces that version of
the blob. A versioned blob is a tuple (blob_name, version).

Definition at line 1021 of file core.py.

◆ get_ssa()

def core.get_ssa (   net,
  blob_versions = None 
)
Given a net, return a structure containing the version of each input and
output blob used by each operator.

Args:
    net:            either a Net or a NetDef
    blob_versions:  (optional) map with current version number for given
                    blob names. If not provided or blob not found, start
                    from version 0.
Returns:
    Tuple (ssa, blob_versions)
    ssa:            list of tuples (versioned_inputs, versioned_outputs)
                    for each op in the net. A versioned input is a tuple
                    (blob_name, version).
    blob_versions:  updated map with latest version of each blob found in
                    the net.

Definition at line 969 of file core.py.

◆ get_undefined_blobs()

def core.get_undefined_blobs (   ssa)
Given a ssa in the format produced by get_ssa(), return a set of blobs that
are used before they are defined, which corresponds to inputs at version 0.

Definition at line 1010 of file core.py.

◆ GetIndexFromGradientList()

def core.GetIndexFromGradientList (   g_list,
  name 
)
A helper function to get the index from a gradient list, None if not
matching.

Definition at line 337 of file core.py.

◆ output_to_list()

def core.output_to_list (   op_output)
Ensures that the output of an operator is a list.
Use when an operator has a variable number of outputs, but a list of
outputs is desired even when number of outputs is 1.

Args:
    op_output: Either a BlobReferenece or an iterable of BlobReferences.

Returns:
    A list of BlobReferences.

Definition at line 1771 of file core.py.

◆ scoped_execution_step()

def core.scoped_execution_step (   name,
  args,
  kwargs 
)
Same as execution_step() except that the step name is scoped.

Definition at line 2066 of file core.py.

◆ ScopedBlobReference()

def core.ScopedBlobReference (   name,
  args,
  kwargs 
)
Returns a blob reference with scope prefixed.

Definition at line 212 of file core.py.

◆ ScopedName()

def core.ScopedName (   name)
prefix the name with the current scope.

Definition at line 207 of file core.py.

◆ worker_init_func()

def core.worker_init_func (   func)
By decorating a function with this, each call to the function will be
recorded at workflow time and replayed in each of the works at startup.
Used for example for registering caffe python operators.

Definition at line 78 of file core.py.

Variable Documentation

◆ SparseGradGenMeta

core.SparseGradGenMeta
Initial value:
1 = namedtuple('SparseGradGenMeta', [
2  'grad_op_indices', 'idx_indices',
3  'grad_op_values', 'idx_values',
4  'gradient',
5 ])

Definition at line 351 of file core.py.