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

Public Member Functions

def __init__ (self, name_or_proto)
 
def AppendNet (self, net)
 
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 GetBlobRef (self, blob_name)
 
def Clone (self, name, blob_remap=None, op_id_mask=None, remap_funcs=None, keep_schema=True)
 
def ClonePartial (self, name, inputs, outputs, remap_funcs=None)
 
def Proto (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 AddExternalInput (self, inputs)
 
def AddExternalOutput (self, outputs)
 
def AddScopedExternalInputs (self, inputs)
 
def AddScopedExternalOutputs (self, outputs)
 
def external_inputs (self)
 
def external_outputs (self)
 
def set_input_record (self, input_record)
 
def set_output_record (self, record)
 
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 __getattr__ (self, op_type)
 
def Python (self, f, grad_f=None, pass_workspace=False)
 

Static Public Member Functions

def current_prefix ()
 

Static Public Attributes

dictionary operator_registry_ = {}
 

Detailed Description

Definition at line 1119 of file core.py.

Constructor & Destructor Documentation

◆ __init__()

def 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 1140 of file core.py.

Member Function Documentation

◆ add_attribute()

def 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 1220 of file core.py.

◆ AddGradientOperators()

def 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 1543 of file core.py.

◆ BlobIsDefined()

def 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 1287 of file core.py.

◆ Clone()

def core.Net.Clone (   self,
  name,
  blob_remap = None,
  op_id_mask = None,
  remap_funcs = None,
  keep_schema = True 
)
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 1327 of file core.py.

◆ ClonePartial()

def 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 1394 of file core.py.

◆ get_attributes()

def 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 1227 of file core.py.

◆ GetBlobRef()

def 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 1309 of file core.py.

◆ NextBlob()

def 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 1471 of file core.py.

◆ NextName()

def 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 1487 of file core.py.

◆ NextScopedBlob()

def 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 1462 of file core.py.

◆ Python()

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

`f` and `f_grad` 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.

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 1726 of file core.py.

◆ RunAllOnGPU()

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

Definition at line 1676 of file core.py.

◆ set_rand_seed()

def 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 1234 of file core.py.

◆ UsesBlob()

def 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 1297 of file core.py.


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