MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
MyCaffe.common.ComputeGraph< T > Class Template Reference

The ComputeGraph class provides a simple computation graph of operations used in a forward pass that are stored in an array on each call and then unwound with calls that calculate the gradients on the backward pass. More...

Inheritance diagram for MyCaffe.common.ComputeGraph< T >:

Public Member Functions

 ComputeGraph (CudaDnn< T > cuda, Log log, int nAxis, bool bNeedsBackprop=true, bool bClipGradients=false, bool bCheckNans=false, bool bAddDebug=false)
 The constructor. More...
 
void Dispose ()
 Release all resources used. More...
 
void DebugOp (params Blob< T >[] rgB)
 DebugOp operation places a debug stub in the backpropagation chain for debugging only. More...
 
Blob< T > Round (Blob< T > b, int nDecimals=6)
 Round operation, rounds the values to the nearest specified decimal. More...
 
Blob< T > PeekRow (Blob< T > btm, Blob< T > top, int ix)
 PeeKRow operation copies data and diffs from one row from within the bottom matrix and places it in the top vector. More...
 
void PeekItem (Blob< T > btm, Blob< T > top, int ix)
 PeekItem operation copies a single item from the bottom to the top. More...
 
Blob< T > CopyToRow (Blob< T > btm, Blob< T > top, int ix, bool bCopyDiff=false)
 CopyToRow operation copies the bottom vector into the top matrix. More...
 
void CopyToCache (Blob< T > btm, Cache< T > cache)
 CopyToCache operation copies the blob into the cache. More...
 
Blob< T > tanh (Blob< T > btm, Blob< T > top)
 'tanh' operation runs the tanh on each item in the btm and places the results in the top. More...
 
Blob< T > sigmoid (Blob< T > btm, Blob< T > top)
 'sigmoid' operation runs the sigmoid on each item in the btm and places the results in the top. More...
 
Blob< T > eltmul (Blob< T > btm1, Blob< T > btm2, Blob< T > top)
 'elthmul' operation mutliplies each element of the 'btm1' with the 'btm2' and places the results in 'top'. More...
 
Blob< T > scalemul (Blob< T > btm1, Blob< T > btm2, Blob< T > top, int nIdx=0)
 'scalemul' operation mutliplies each element of the 'btm1' with the first item within 'btm2' and places the results in 'top'. More...
 
Blob< T > mul (Blob< T > btm1, Blob< T > btm2, Blob< T > top, bool bAccumulateGrad=true)
 'mul' operation performs a blas gemm operation on the 'btm1' matrix with the 'btm2' matrix and places the results in 'top'. More...
 
Blob< T > add (Blob< T > btm1, Blob< T > btm2, Blob< T > top, bool bAccumulateGrad=true)
 'elthmul' operation adds each element of the 'btm1' with the 'btm2' and places the results in 'top'. More...
 
Blob< T > clear_grad (Blob< T > b)
 'clear_grad' operation only runs on the backward pass and zeros out the gradients on an input. More...
 
void clear_grad (BlobCollection< T > rg)
 'clear_grad' operation only runs on the backward pass and zeros out the gradients of the inputs. More...
 
Blob< T > softmax (Blob< T > btm, Blob< T > top)
 'softmax' operation runs the softmax on each item in the btm and places the results in the top. More...
 
void BackwardOne (int nIdx)
 Runs a backward operation at a given index. More...
 
void Backward (bool bClear=false)
 Runs a backward operation on all items starting from the last and running through the first. More...
 
void Clear ()
 Clears all backward operations from the list. More...
 

Properties

Dictionary< string, Blob< T >[]> Debug [get]
 Returns a dictionary of Blobs used during each operation, only filled when 'bAddDebug' = true in the constructor. More...
 
string marker [getset]
 Get/set a string marker added to the debug information and used to indicate where in the code a given operation takes place. More...
 
bool needs_backprop [getset]
 Get/set whether or not to back propagate. More...
 
int axis [get]
 Returns the axis on which all operations are performed. More...
 
int BackwardCount [get]
 Returns the backward operation count. More...
 

Detailed Description

The ComputeGraph class provides a simple computation graph of operations used in a forward pass that are stored in an array on each call and then unwound with calls that calculate the gradients on the backward pass.

This class is a re-write of the ComputeGraph originally created by Mohamed Ashmawy in the open-source project mashmawy/Seq2SeqLearn distributed under the MIT license.

Template Parameters
TSpecifies the base type.

Definition at line 21 of file ComputeGraph.cs.

Constructor & Destructor Documentation

◆ ComputeGraph()

MyCaffe.common.ComputeGraph< T >.ComputeGraph ( CudaDnn< T >  cuda,
Log  log,
int  nAxis,
bool  bNeedsBackprop = true,
bool  bClipGradients = false,
bool  bCheckNans = false,
bool  bAddDebug = false 
)

The constructor.

Parameters
cudaSpecifies the connection to CUDA.
logSpecifies the general output log.
nAxisSpecifies the axis under which to perform all of the actions in the graph.
bNeedsBackpropOptionally, specifies whether or not to back propagate (default = true).
bClipGradientsOptionally, specifies whether or not to clip the gradients (default = false, Debug only).
bCheckNansOptionally, specifies whether or not to check for nans (default = false, Debug only).
bAddDebugOptionally, specifies to add debug information (default = false, Debug only).

Definition at line 45 of file ComputeGraph.cs.

Member Function Documentation

◆ add()

Blob< T > MyCaffe.common.ComputeGraph< T >.add ( Blob< T >  btm1,
Blob< T >  btm2,
Blob< T >  top,
bool  bAccumulateGrad = true 
)

'elthmul' operation adds each element of the 'btm1' with the 'btm2' and places the results in 'top'.

Parameters
btm1Specifies the first input.
btm2Specifies the second input.
topSpecifies the output.
bAccumulateGradOptionally, specifies whether or not to acumulate the gradients (default = true).
Returns
The 'top' Blob is returned.

Definition at line 538 of file ComputeGraph.cs.

◆ Backward()

void MyCaffe.common.ComputeGraph< T >.Backward ( bool  bClear = false)

Runs a backward operation on all items starting from the last and running through the first.

Parameters
bClearOptionally, specifies to clear the list of operations upon completing (default = false).

Definition at line 684 of file ComputeGraph.cs.

◆ BackwardOne()

void MyCaffe.common.ComputeGraph< T >.BackwardOne ( int  nIdx)

Runs a backward operation at a given index.

Parameters
nIdxSpecifies the index of the backward operation to run.

Definition at line 675 of file ComputeGraph.cs.

◆ Clear()

void MyCaffe.common.ComputeGraph< T >.Clear ( )

Clears all backward operations from the list.

Definition at line 698 of file ComputeGraph.cs.

◆ clear_grad() [1/2]

Blob< T > MyCaffe.common.ComputeGraph< T >.clear_grad ( Blob< T >  b)

'clear_grad' operation only runs on the backward pass and zeros out the gradients on an input.

Parameters
bSpecifies the input.
Returns
The input Blob is returned.

Definition at line 576 of file ComputeGraph.cs.

◆ clear_grad() [2/2]

void MyCaffe.common.ComputeGraph< T >.clear_grad ( BlobCollection< T >  rg)

'clear_grad' operation only runs on the backward pass and zeros out the gradients of the inputs.

Parameters
rgSpecifies an array of inputs.

Definition at line 594 of file ComputeGraph.cs.

◆ CopyToCache()

void MyCaffe.common.ComputeGraph< T >.CopyToCache ( Blob< T >  btm,
Cache< T >  cache 
)

CopyToCache operation copies the blob into the cache.

Parameters
btmSpecifies the input vector to copy.
cacheSpecifies the cache.

Definition at line 322 of file ComputeGraph.cs.

◆ CopyToRow()

Blob< T > MyCaffe.common.ComputeGraph< T >.CopyToRow ( Blob< T >  btm,
Blob< T >  top,
int  ix,
bool  bCopyDiff = false 
)

CopyToRow operation copies the bottom vector into the top matrix.

Parameters
btmSpecifies the input vector.
topSpecifies the output matrix.
ixSpecifies the row into which the data is copied within the top.
bCopyDiffOptionally, specifies to copy the diff and the data.
Returns
The top blob is returned.

Definition at line 290 of file ComputeGraph.cs.

◆ DebugOp()

void MyCaffe.common.ComputeGraph< T >.DebugOp ( params Blob< T >[]  rgB)

DebugOp operation places a debug stub in the backpropagation chain for debugging only.

Definition at line 186 of file ComputeGraph.cs.

◆ Dispose()

void MyCaffe.common.ComputeGraph< T >.Dispose ( )

Release all resources used.

Definition at line 60 of file ComputeGraph.cs.

◆ eltmul()

Blob< T > MyCaffe.common.ComputeGraph< T >.eltmul ( Blob< T >  btm1,
Blob< T >  btm2,
Blob< T >  top 
)

'elthmul' operation mutliplies each element of the 'btm1' with the 'btm2' and places the results in 'top'.

Parameters
btm1Specifies the first input.
btm2Specifies the second input.
topSpecifies the output.
Returns
The 'top' Blob is returned.

Definition at line 412 of file ComputeGraph.cs.

◆ mul()

Blob< T > MyCaffe.common.ComputeGraph< T >.mul ( Blob< T >  btm1,
Blob< T >  btm2,
Blob< T >  top,
bool  bAccumulateGrad = true 
)

'mul' operation performs a blas gemm operation on the 'btm1' matrix with the 'btm2' matrix and places the results in 'top'.

Parameters
btm1Specifies the first input.
btm2Specifies the second input.
topSpecifies the output.
bAccumulateGradOptionally, specifies to accumulate the gradient (default = true).
Returns
The 'top' Blob is returned.

Definition at line 494 of file ComputeGraph.cs.

◆ PeekItem()

void MyCaffe.common.ComputeGraph< T >.PeekItem ( Blob< T >  btm,
Blob< T >  top,
int  ix 
)

PeekItem operation copies a single item from the bottom to the top.

Parameters
btmSpecifies the input vector.
topSpecifies the output matrix.
ixSpecifies the row into which the data is copied within the top.

Definition at line 264 of file ComputeGraph.cs.

◆ PeekRow()

Blob< T > MyCaffe.common.ComputeGraph< T >.PeekRow ( Blob< T >  btm,
Blob< T >  top,
int  ix 
)

PeeKRow operation copies data and diffs from one row from within the bottom matrix and places it in the top vector.

Parameters
btmSpecifies the input matrix.
topSpecifies the output vector.
ixSpecifies the row within the input matrix to copy.
Returns
The top blob is returned.

Definition at line 232 of file ComputeGraph.cs.

◆ Round()

Blob< T > MyCaffe.common.ComputeGraph< T >.Round ( Blob< T >  b,
int  nDecimals = 6 
)

Round operation, rounds the values to the nearest specified decimal.

Parameters
bSpecifies the blob to round.
nDecimalsOptionally, specifies the decimals (defautl = 6).
Returns
Returns the blob.

Definition at line 209 of file ComputeGraph.cs.

◆ scalemul()

Blob< T > MyCaffe.common.ComputeGraph< T >.scalemul ( Blob< T >  btm1,
Blob< T >  btm2,
Blob< T >  top,
int  nIdx = 0 
)

'scalemul' operation mutliplies each element of the 'btm1' with the first item within 'btm2' and places the results in 'top'.

Parameters
btm1Specifies the first input.
btm2Specifies the second input.
topSpecifies the output.
nIdxSpecifies the index of btm2 to use for scaling.
Returns
The 'top' Blob is returned.

Definition at line 451 of file ComputeGraph.cs.

◆ sigmoid()

Blob< T > MyCaffe.common.ComputeGraph< T >.sigmoid ( Blob< T >  btm,
Blob< T >  top 
)

'sigmoid' operation runs the sigmoid on each item in the btm and places the results in the top.

Parameters
btmSpecifies the input data.
topSpecifies the output data.
Returns
The top blob is returned.

Definition at line 377 of file ComputeGraph.cs.

◆ softmax()

Blob< T > MyCaffe.common.ComputeGraph< T >.softmax ( Blob< T >  btm,
Blob< T >  top 
)

'softmax' operation runs the softmax on each item in the btm and places the results in the top.

Parameters
btmSpecifies the input data.
topSpecifies the output data.
Returns
The top blob is returned.

Definition at line 608 of file ComputeGraph.cs.

◆ tanh()

Blob< T > MyCaffe.common.ComputeGraph< T >.tanh ( Blob< T >  btm,
Blob< T >  top 
)

'tanh' operation runs the tanh on each item in the btm and places the results in the top.

Parameters
btmSpecifies the input data.
topSpecifies the output data.
Returns
The top blob is returned.

Definition at line 343 of file ComputeGraph.cs.

Property Documentation

◆ axis

int MyCaffe.common.ComputeGraph< T >.axis
get

Returns the axis on which all operations are performed.

Definition at line 104 of file ComputeGraph.cs.

◆ BackwardCount

int MyCaffe.common.ComputeGraph< T >.BackwardCount
get

Returns the backward operation count.

Definition at line 666 of file ComputeGraph.cs.

◆ Debug

Dictionary<string, Blob<T>[]> MyCaffe.common.ComputeGraph< T >.Debug
get

Returns a dictionary of Blobs used during each operation, only filled when 'bAddDebug' = true in the constructor.

Definition at line 78 of file ComputeGraph.cs.

◆ marker

string MyCaffe.common.ComputeGraph< T >.marker
getset

Get/set a string marker added to the debug information and used to indicate where in the code a given operation takes place.

Definition at line 86 of file ComputeGraph.cs.

◆ needs_backprop

bool MyCaffe.common.ComputeGraph< T >.needs_backprop
getset

Get/set whether or not to back propagate.

Definition at line 95 of file ComputeGraph.cs.


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