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

Public Member Functions

def __init__ (self, name_or_proto)
 
def AppendNet (self, net, device_option=None)
 
def LogInfo (self, msg_or_blobs)
 
def add_attribute (self, name, obj)
 
def get_attributes (self, name)
 
def set_rand_seed (self, seed=100, sequence_seed=True, seed_on_op_def=False)
 
def Name (self)
 
def __str__ (self)
 
def Const (self, array, blob_out=None, dtype=None)
 
def BlobIsDefined (self, blob)
 
def UsesBlob (self, blob)
 
def UsedBlobNames (self)
 
def GetBlobRef (self, blob_name)
 
def Clone (self, name, blob_remap=None, op_id_mask=None, remap_funcs=None, keep_schema=True, update_external_list=False)
 
def ClonePartial (self, name, inputs, outputs, remap_funcs=None)
 
def Proto (self)
 
def insert_op_at_idx (self, op, op_idx)
 
def reroute_tensor (self, tensor, new_producer, can_modify=None)
 
def PopulateProtoWithFileName (self)
 
def NextScopedBlob (self, prefix='unnamed')
 
def NextBlob (self, prefix='unnamed')
 
def NextName (self, prefix=None, output_id=None)
 
def AddGradientOperators (self, ys, skip=0)
 
def AddArgument (self, arg_name, arg_value)
 
def AddExternalInput (self, inputs)
 
def AddExternalOutput (self, outputs)
 
def AddScopedExternalInputs (self, inputs)
 
def AddScopedExternalOutputs (self, outputs)
 
def AddObserver (self, observer_type)
 
def RemoveObserver (self, observer)
 
def NumObservers (self)
 
def external_inputs (self)
 
def external_outputs (self)
 
def set_input_record (self, input_record)
 
def recover_input_record_by_prefix (self, prefix)
 
def set_output_record (self, record)
 
def recover_output_record_by_prefix (self, prefix)
 
def AppendOutputRecordField (self, field_name, record)
 
def input_record (self)
 
def output_record (self)
 
def AddExternalInputs (self, inputs)
 
def AddExternalOutputs (self, outputs)
 
def DeduplicateGradientSlices (self, g, aggregator='sum')
 
def RunAllOnGPU (self, gpu_id=0, use_cudnn=False)
 
def RunAllOnMKL (self)
 
def RunAllOnIDEEP (self)
 
def __getattr__ (self, op_type)
 
def __dir__ (self)
 
def Python (self, f, grad_f=None, python_func_type=None, pass_workspace=False, grad_output_indices=None, grad_input_indices=None)
 
def is_external_input (self, blob)
 
def extend_ops (self, new_ops)
 

Static Public Member Functions

def current_prefix ()
 

Static Public Attributes

dictionary operator_registry_ = {}
 

Detailed Description

Definition at line 1395 of file core.py.

Constructor & Destructor Documentation

def caffe2.python.core.Net.__init__ (   self,
  name_or_proto 
)
Create a Net.
Args:
    name_or_proto:  If a NetDef is provided, clone it. Otherwise,
            create an empty net with the given name.

Definition at line 1417 of file core.py.

Member Function Documentation

def caffe2.python.core.Net.add_attribute (   self,
  name,
  obj 
)
Add `obj` to the list of attributes in this net under the given `name`.
Attributes are user-defined objects and have no pre-defined semantics.

Definition at line 1509 of file core.py.

def caffe2.python.core.Net.AddGradientOperators (   self,
  ys,
  skip = 0 
)
Add the gradient for operators in the net.

Inputs:
  ys: a list or a dictionary specifying what blobs we want to compute
      derivatives of. If the input is a list, we will automatically
      generate their gradients with all-one values; if the input is a
      dictionary, for any dictionary entries that are not None, we will
      take the corresponding blobs as their gradients; for all those
      that are None, we will auto-fill them with 1.
  skip: skips the first n operators. This is provided mainly because a
      lot of nets may use the first few operators for data generation
      like stuff which really do not need to have gradients.

Outputs:
  returns a map from the blob name in the input network to a blob
  containing gradient or a GradientSlice in case of sparse gradient

Currently, this is hard-coded for float operators if there are branches
(i.e. a blob is used as input to multiple operators). This is because
the gradient accumulation (Sum) is float only right now.

Definition at line 1948 of file core.py.

def caffe2.python.core.Net.BlobIsDefined (   self,
  blob 
)
Returns true if the given BlobReference is produced as output of
an operator in this net, or if it is provided as an external input.

Definition at line 1578 of file core.py.

def caffe2.python.core.Net.Clone (   self,
  name,
  blob_remap = None,
  op_id_mask = None,
  remap_funcs = None,
  keep_schema = True,
  update_external_list = False 
)
Clone this net.
Args:
    name:        name of the cloned net
    blob_remap:  optional map with list of blob names to replace
    op_id_mask:  optional list of operator indices to include in
         the cloned net. If not provided, all ops are included.

Definition at line 1633 of file core.py.

def caffe2.python.core.Net.ClonePartial (   self,
  name,
  inputs,
  outputs,
  remap_funcs = None 
)
Clone this net, including only ops that are necessary in order to
compute `outputs` given `inputs`. Return references to the cloned
outputs. Internal blobs (blobs that are produced and consumed inside
the net but not used as outputs) will be remapped to avoid name
conflict.

Args:
    name:    the name of the cloned net
    inputs:  map where the keys correspond to BlobReferences in the
     original net, and the values correspond to external inputs
     in the partially cloned net. If `inputs` is a list, don't
     remap input names.
    outputs: outputs to be produced by the cloned net.

Returns:
    Tuple (new_net, new_outputs)
new_net:       a new Net object.
new_outputs:   list of BlobReferences corresponding to the
               outputs produced by new_net.

Definition at line 1726 of file core.py.

def caffe2.python.core.Net.get_attributes (   self,
  name 
)
Returns the list of attributes in this net for a given `name`.
Attributes are user-defined objects added with `add_attribute'.

Definition at line 1516 of file core.py.

def caffe2.python.core.Net.GetBlobRef (   self,
  blob_name 
)
Given the name of a blob produced by this net, return a BlobReference
to it. If the blob is not produced by any op in this net,
raises KeyError.

Definition at line 1614 of file core.py.

def caffe2.python.core.Net.NextBlob (   self,
  prefix = 'unnamed' 
)
Return the blob that has not been defined or registered in the
current net. It returns `BlobReference(prefix)`, if it's valid,
otherwise `BlobReference(prefix) + '_auto_' + ?`. Different calls
is guaranteed to return blob with different names.

Definition at line 1876 of file core.py.

def caffe2.python.core.Net.NextName (   self,
  prefix = None,
  output_id = None 
)
Returns the next name to be used, if you do not want to explicitly
name your blob. [Deprecated, use NextBlob, NextScopedBlob instead]

Definition at line 1892 of file core.py.

def caffe2.python.core.Net.NextScopedBlob (   self,
  prefix = 'unnamed' 
)
Return the blob that has not been defined or registered in the
current net. It returns `ScopedBlobReference(prefix)`, if it's valid,
otherwise `ScopedBlobReference(prefix) + '_auto_' + ?`. Different calls
is guaranteed to return blob with different names.

Definition at line 1867 of file core.py.

def caffe2.python.core.Net.Python (   self,
  f,
  grad_f = None,
  python_func_type = None,
  pass_workspace = False,
  grad_output_indices = None,
  grad_input_indices = None 
)
Registers and returns a python operator.

`f` and `grad_f` can be one of the following:
    - a function with signature (inputs, outputs), where inputs and
      outputs are a list of CPUTensor objects. This function will be
      called from C++ everytime the operator is executed.
    - a tuple (func, args, kwargs), here `func` is a callable, args is
      an argument list, and kwargs is a dict list. The call:
  f = func(*args, kwargs)
      will be performed locally at node initialization time, on all of
      the nodes of the job, returning `f`, a callable that will be used
      as the python operator function to be called during Net execution.
      This is to be used when using python operator in a distributed
      context, and allows to create and keep local python state across
      calls to the operator.

`python_func_type` is a type of an object that constructed as
python_func_type(f) and provides an implementation to forward and
backward functions. Its useful in such a case where users needs
a statefull PythonOp (ex: use autograd for computing grad_f).

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.

If a gradient function is specified (`grad_f`), by default its inputs
will be: (1) all inputs to `f`, (2) followed by all outputs of `f`, (3)
and then all gradient outputs of `f`. The outputs of `grad_f` will be
(by default) all gradient inputs to `f`. If a subset of the gradient
outputs or gradient inputs is desired instead, then the subsets can be
specified by providing `grad_output_indices` and/or `grad_input_indices`
which identify the indices of `f`'s inputs and outputs which have
gradients.

Definition at line 2219 of file core.py.

def caffe2.python.core.Net.recover_input_record_by_prefix (   self,
  prefix 
)
Tries to recover input record by taking a subset of external_inputs with
a given prefix name and interpreting them as schema column names

Definition at line 2055 of file core.py.

def caffe2.python.core.Net.recover_output_record_by_prefix (   self,
  prefix 
)
Tries to recover out record by taking a subset of external_outputs with
a given prefix name and interpreting them as schema column names

Definition at line 2076 of file core.py.

def caffe2.python.core.Net.RunAllOnGPU (   self,
  gpu_id = 0,
  use_cudnn = False 
)
A convenient function to run everything on the GPU.

Definition at line 2138 of file core.py.

def caffe2.python.core.Net.RunAllOnIDEEP (   self)
A convenient function to run everything using IDEEP.

Definition at line 2150 of file core.py.

def caffe2.python.core.Net.RunAllOnMKL (   self)
A convenient function to run everything using MKLDNN.

Definition at line 2144 of file core.py.

def caffe2.python.core.Net.set_rand_seed (   self,
  seed = 100,
  sequence_seed = True,
  seed_on_op_def = False 
)
Adds a random seed to each op in the net.
If sequence_seed is set, the i-th op has rand_seed=`seed + i`
If seed_on_op_def is set, the op rand_seed=hash(str(op))
sequence_seed and seed_on_op_def cannot be both set to True.

Definition at line 1523 of file core.py.

def caffe2.python.core.Net.UsedBlobNames (   self)
Returns a set of blob names used in the net

Definition at line 1600 of file core.py.

def caffe2.python.core.Net.UsesBlob (   self,
  blob 
)
Returns true iff the given BlobReference is used by any operator
or this net, or if it is one of the external inputs of the net.

Definition at line 1588 of file core.py.


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