2using System.Collections.Concurrent;
3using System.Collections.Generic;
27 Layer<T>[] m_rgActivationLayers =
null;
80 for (
int i = 0; i < m_nNumLayers; i++)
83 m_rgLinearBtms.
Add(blobBtm);
86 blobTop.
Name =
"bb_" + i.ToString();
88 m_rgLinearTops.
Add(blobTop);
92 m_rgActivationBtms.
Add(blobBtm);
95 blobTop.
Name =
"bb_act_" + i.ToString();
97 m_rgActivationTops.
Add(blobTop);
101 m_rgLinearLayers =
new Layer<T>[m_nNumLayers];
102 m_rgActivationLayers =
new Layer<T>[m_nNumLayers];
105 m_rgDropoutLayers =
new Layer<T>[m_nNumLayers];
107 for (
int i = 0; i < m_nNumLayers; i++)
145 if (i > 0 && m_rgDropoutLayers !=
null)
166 m_blobFF1.
Name =
"ff1";
181 m_blobFF2.
Name =
"ff2";
192 m_blobTimeA.
Name =
"time_a";
203 m_blobTimeB.
Name =
"time_b";
211 m_blobTInterp.
Name =
"t-interp";
214 m_blobTInterpInv.
Name =
"t-interpinv";
217 m_blobTInterp1.
Name =
"t-interp1";
219 m_blobTInterpOnes.
Name =
"t_interp_ones";
222 m_blobTs.
Name =
"ts";
225 m_blobTop1.
Name =
"top1";
227 m_blobTop2.
Name =
"top2";
235 if (m_rgLinearLayers !=
null)
237 for (
int i = 0; i < m_rgLinearLayers.Length; i++)
241 m_rgLinearLayers =
null;
245 dispose_internal_blobs();
247 clear_internal_blobs();
249 dispose(ref m_blobTInterpOnes);
260 private void dispose_internal_blobs(
bool bSetToNull =
true)
262 dispose(ref m_rgLinearBtms, bSetToNull);
263 dispose(ref m_rgLinearTops, bSetToNull);
264 dispose(ref m_rgActivationBtms, bSetToNull);
265 dispose(ref m_rgActivationTops, bSetToNull);
280 private void clear_internal_blobs()
282 m_rgLinearBtms.
Clear();
283 m_rgLinearTops.
Clear();
284 m_rgActivationBtms.
Clear();
285 m_rgActivationTops.
Clear();
302 dispose_internal_blobs(
false);
305 blobFF1.
Name =
"ff1_" + nIdx.ToString();
309 blobFF2.
Name =
"ff2_" + nIdx.ToString();
313 blobTimeA.
Name =
"timeA_" + nIdx.ToString();
317 blobTimeB.
Name =
"timeB_" + nIdx.ToString();
321 blobTInterp.
Name =
"tInterp_" + nIdx.ToString();
322 col.
Add(blobTInterp);
325 blobTInterp1.
Name =
"tInterp1_" + nIdx.ToString();
326 col.
Add(blobTInterp1);
329 blobTInterpInv.
Name =
"tInterpInv_" + nIdx.ToString();
330 col.
Add(blobTInterpInv);
333 blobTs.
Name =
"ts_" + nIdx.ToString();
337 blobX.
Name =
"x_" + nIdx.ToString();
341 blobTop1.
Name =
"top1_" + nIdx.ToString();
345 blobTop2.
Name =
"top2_" + nIdx.ToString();
349 blobBb.
Name =
"bb_" + nIdx.ToString();
355 blobFc.
Name =
"bb_fc" + (i + 1).ToString() +
"_" + nIdx.ToString();
359 blobAct.
Name =
"bb_act" + (i + 1).ToString() +
"_" + nIdx.ToString();
375 m_blobFF1 = col[nIdx];
378 m_blobFF2 = col[nIdx];
381 m_blobTimeA = col[nIdx];
384 m_blobTimeB = col[nIdx];
387 m_blobTInterp = col[nIdx];
390 m_blobTInterp1 = col[nIdx];
393 m_blobTInterpInv = col[nIdx];
396 m_blobTs = col[nIdx];
402 m_blobTop1 = col[nIdx];
405 m_blobTop2 = col[nIdx];
409 while (nIdx < col.
Count)
411 colLin.
Add(col[nIdx]);
415 m_rgLinearBtms.
Clear();
416 m_rgLinearTops.
Clear();
417 m_rgActivationBtms.
Clear();
418 m_rgActivationTops.
Clear();
423 m_rgLinearBtms.
Add(colLin[nIdx]);
425 m_rgLinearTops.
Add(colLin[nIdx]);
426 m_rgActivationBtms.
Add(colLin[nIdx]);
428 m_rgActivationTops.
Add(colLin[nIdx]);
472 base.ReInitializeParameters(target);
483 addBtmTop(colBottom[0], m_rgLinearBtms[0]);
484 m_colBtm.
Add(colBottom[1]);
485 m_cat.Setup(m_colBtm, m_colTop);
487 for (
int i = 0; i < m_nNumLayers; i++)
489 addBtmTop(m_rgLinearBtms[i], m_rgLinearTops[i]);
490 m_rgLinearLayers[i].
Setup(m_colBtm, m_colTop);
493 addBtmTop(m_rgActivationBtms[i], m_rgActivationTops[i]);
494 m_rgActivationLayers[i].
Setup(m_colBtm, m_colTop);
496 if (i > 0 && m_rgDropoutLayers !=
null)
497 m_rgDropoutLayers[i].
Setup(m_colBtm, m_colTop);
500 Blob<T> blobX = m_rgActivationTops[m_nNumLayers - 1];
504 addBtmTop(blobX, m_blobFF1);
505 m_ff1.
Setup(m_colBtm, m_colTop);
509 addBtmTop(m_blobFF1, m_blobFF1);
510 m_tanh.
Setup(m_colBtm, m_colTop);
513 addBtmTop(blobX, m_blobFF2);
514 m_ff2.
Setup(m_colBtm, m_colTop);
517 addBtmTop(m_blobFF2, m_blobFF2);
518 m_tanh.
Setup(m_colBtm, m_colTop);
521 addBtmTop(blobX, m_blobTimeA);
522 m_timeA.
Setup(m_colBtm, m_colTop);
526 addBtmTop(blobX, m_blobTimeB);
527 m_timeB.
Setup(m_colBtm, m_colTop);
536 addBtmTop(m_blobTInterp, colTop[0]);
537 m_sigmoid.
Setup(m_colBtm, m_colTop);
551 addBtmTop(colBottom[0], m_rgLinearBtms[0]);
552 m_colBtm.
Add(colBottom[1]);
553 m_cat.Reshape(m_colBtm, m_colTop);
555 for (
int i = 0; i < m_rgLinearLayers.Length; i++)
557 addBtmTop(m_rgLinearBtms[i], m_rgLinearTops[i]);
558 m_rgLinearLayers[i].
Reshape(m_colBtm, m_colTop);
560 addBtmTop(m_rgActivationBtms[i], m_rgActivationTops[i]);
561 m_rgActivationLayers[i].
Reshape(m_colBtm, m_colTop);
563 if (m_rgDropoutLayers !=
null)
564 m_rgDropoutLayers[i].
Reshape(m_colBtm, m_colTop);
567 Blob<T> blobX = m_rgActivationTops[m_rgLinearLayers.Length - 1];
571 addBtmTop(blobX, m_blobFF1);
572 m_ff1.
Reshape(m_colBtm, m_colTop);
575 addBtmTop(m_blobFF1, m_blobFF1);
576 m_tanh.
Reshape(m_colBtm, m_colTop);
579 addBtmTop(blobX, m_blobFF2);
580 m_ff2.
Reshape(m_colBtm, m_colTop);
582 addBtmTop(m_blobFF2, m_blobFF2);
583 m_tanh.
Reshape(m_colBtm, m_colTop);
586 addBtmTop(blobX, m_blobTimeA);
587 m_timeA.
Reshape(m_colBtm, m_colTop);
594 m_blobTInterpOnes.
SetData(1.0);
597 addBtmTop(blobX, m_blobTimeB);
598 m_timeB.
Reshape(m_colBtm, m_colTop);
601 addBtmTop(m_blobTInterp, colTop[0]);
602 m_sigmoid.
Reshape(m_colBtm, m_colTop);
623 addBtmTop(colBottom[0], m_rgLinearBtms[0]);
624 m_colBtm.
Add(colBottom[1]);
625 m_cat.Forward(m_colBtm, m_colTop);
627 for (
int i = 0; i < m_rgLinearLayers.Length; i++)
629 addBtmTop(m_rgLinearBtms[i], m_rgLinearTops[i]);
630 m_rgLinearLayers[i].
Forward(m_colBtm, m_colTop);
632 addBtmTop(m_rgActivationBtms[i], m_rgActivationTops[i]);
633 m_rgActivationLayers[i].
Forward(m_colBtm, m_colTop);
635 if (m_rgDropoutLayers !=
null)
636 m_rgDropoutLayers[i].
Forward(m_colBtm, m_colTop);
639 Blob<T> blobX = m_rgActivationTops[m_rgLinearLayers.Length - 1];
643 addBtmTop(blobX, m_blobFF1);
644 m_ff1.
Forward(m_colBtm, m_colTop);
647 addBtmTop(m_blobFF1, m_blobFF1);
648 m_tanh.
Forward(m_colBtm, m_colTop);
651 addBtmTop(blobX, m_blobFF2);
652 m_ff2.
Forward(m_colBtm, m_colTop);
654 addBtmTop(m_blobFF2, m_blobFF2);
655 m_tanh.
Forward(m_colBtm, m_colTop);
658 addBtmTop(blobX, m_blobTimeA);
659 m_timeA.
Forward(m_colBtm, m_colTop);
662 addBtmTop(blobX, m_blobTimeB);
663 m_timeB.
Forward(m_colBtm, m_colTop);
674 addBtmTop(m_blobTInterp, m_blobTInterp);
675 m_sigmoid.
Forward(m_colBtm, m_colTop);
720 m_blobFF1.
CopyFrom(colTop[0],
true);
743 m_blobTInterp1.
CopyFrom(m_blobTInterp);
744 addBtmTop(m_blobTInterp, m_blobTInterp1);
745 m_sigmoid.
Backward(m_colTop, rgbPropagateDown, m_colBtm);
748 m_blobTimeB.
CopyFrom(m_blobTInterp,
true);
757 Blob<T> blobX = m_rgActivationTops[m_rgActivationTops.
Count-1];
761 addBtmTop(m_blobX, m_blobTimeB);
762 m_timeB.
Backward(m_colTop, rgbPropagateDown, m_colBtm);
766 addBtmTop(m_blobX, m_blobTimeA);
767 m_timeA.
Backward(m_colTop, rgbPropagateDown, m_colBtm);
771 addBtmTop(m_blobFF2, m_blobFF2);
772 m_tanh.
Backward(m_colTop, rgbPropagateDown, m_colBtm);
774 addBtmTop(m_blobX, m_blobFF2);
775 m_ff2.
Backward(m_colTop, rgbPropagateDown, m_colBtm);
779 addBtmTop(m_blobFF1, m_blobFF1);
780 m_tanh.
Backward(m_colTop, rgbPropagateDown, m_colBtm);
782 addBtmTop(m_blobX, m_blobFF1);
783 m_ff1.
Backward(m_colTop, rgbPropagateDown, m_colBtm);
787 for (
int i = m_rgLinearLayers.Length - 1; i >= 0; i--)
789 addBtmTop(m_rgActivationBtms[i], m_rgActivationTops[i]);
791 if (m_rgDropoutLayers !=
null)
792 m_rgDropoutLayers[i].
Backward(m_colTop, rgbPropagateDown, m_colBtm);
794 m_rgActivationLayers[i].
Backward(m_colTop, rgbPropagateDown, m_colBtm);
796 addBtmTop(m_rgLinearBtms[i], m_rgLinearTops[i]);
797 m_rgLinearLayers[i].
Backward(m_colTop, rgbPropagateDown, m_colBtm);
800 addBtmTop(colBottom[0], m_rgLinearBtms[0]);
801 m_colBtm.
Add(colBottom[1]);
802 m_cat.Backward(m_colTop,
new List<bool>() {
true,
true }, m_colBtm);
The Log class provides general output in text form.
The BlobCollection contains a list of Blobs.
void Add(Blob< T > b)
Add a new Blob to the collection.
int Count
Returns the number of items in the collection.
void Clear(bool bDispose=false)
Remove all items from the collection.
void CopyFrom(BlobCollection< T > bSrc, bool bCopyDiff=false)
Copy the data or diff from another BlobCollection into this one.
The Blob is the main holder of data that moves through the Layers of the Net.
int channels
DEPRECIATED; legacy shape accessor channels: use shape(1) instead.
void SetData(T[] rgData, int nCount=-1, bool bSetCount=true)
Sets a number of items within the Blob's data.
long mutable_gpu_diff
Returns the diff GPU handle used by the CudaDnn connection.
long mutable_gpu_data
Returns the data GPU handle used by the CudaDnn connection.
void CopyFrom(Blob< T > src, int nSrcOffset, int nDstOffset, int nCount, bool bCopyData, bool bCopyDiff)
Copy from a source Blob.
int count()
Returns the total number of items in the Blob.
void ReshapeLike(Blob< T > b, bool? bUseHalfSize=null)
Reshape this Blob to have the same shape as another Blob.
string Name
Get/set the name of the Blob.
long gpu_diff
Returns the diff GPU handle used by the CudaDnn connection.
void SetDiff(double dfVal, int nIdx=-1)
Either sets all of the diff items in the Blob to a given value, or alternatively only sets a single i...
int num
DEPRECIATED; legacy shape accessor num: use shape(0) instead.
long gpu_data
Returns the data GPU handle used by the CudaDnn connection.
The CudaDnn object is the main interface to the Low-Level Cuda C++ DLL.
An interface for the units of computation which can be composed into a Net.
Log m_log
Specifies the Log for output.
LayerParameter m_param
Specifies the LayerParameter describing the Layer.
void Backward(BlobCollection< T > colTop, List< bool > rgbPropagateDown, BlobCollection< T > colBottom)
Given the top Blob error gradients, compute the bottom Blob error gradients.
double Forward(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Given the bottom (input) Blobs, this function computes the top (output) Blobs and the loss.
abstract void Reshape(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Adjust the shapes of top blobs and internal buffers to accomodate the shapes of the bottom blobs.
void Dispose()
Releases all GPU and host resources used by the Layer.
CudaDnn< T > m_cuda
Specifies the CudaDnn connection to Cuda.
void Setup(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Implements common Layer setup functionality.
static Layer< T > Create(CudaDnn< T > cuda, Log log, LayerParameter p, CancelEvent evtCancel, IXDatabaseBase db=null, TransferInput trxinput=null)
Create a new Layer based on the LayerParameter.
LayerParameter.LayerType m_type
Specifies the Layer type.
BlobCollection< T > blobs
Returns the collection of learnable parameter Blobs for the Layer.
LayerParameter convertLayerParam(LayerParameter pChild, LayerParameter pParent)
Called to convert a parent LayerParameterEx, used in blob sharing, with a child layer parameter.
The CfcUnitLayer implements the Closed form Continuous Cell (CfcCell) layer.
override void dispose()
Releases all GPU and host resources used by the Layer.
CfcUnitLayer(CudaDnn< T > cuda, Log log, LayerParameter p)
The CfcUnitLayer constructor.
override BlobCollection< T > CreateInternalSharedBlobs(int nIdx, CudaDnn< T > cuda, Log log)
Create the internal shared blobs used by the layer for a given index.
override void Reshape(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Reshape the bottom (input) and top (output) blobs.
override void forward(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Forward computation
override void LayerSetUp(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Setup the layer.
override void SetInternalSharedBlobs(BlobCollection< T > col)
Set the internal shared blobs to a set of external blobs.
override void setup_internal_blobs(BlobCollection< T > col)
Derivative layers should add all internal blobws to the 'col' provided.
override int ExactNumTopBlobs
Returns the exact number of required top (output) Blobs: attn
override bool ReInitializeParameters(WEIGHT_TARGET target)
Re-initialize the parameters of the layer.
override void backward(BlobCollection< T > colTop, List< bool > rgbPropagateDown, BlobCollection< T > colBottom)
Computes the error gradient w.r.t. the CfcUnit value inputs.
override int ExactNumBottomBlobs
Returns the exact number of required bottom (input) Blobs: input, hx, ts
The LnnUnitLayer implements the base class to the Cfc and Ltc Unit layers.
bool m_bOwnInternalBlobs
Specifies member variable used to track whether or not the internal blobs are owned by this layer.
int axis
The axis along which to concatenate – may be negative to index from the end (e.g.,...
double dropout_ratio
Specifies the dropout ratio. (e.g. the probability that values will be dropped out and set to zero....
Specifies the filler parameters used to create each Filler.
FillerParameter weight_filler
The filler for the weights.
FillerParameter bias_filler
The filler for the bias.
uint num_output
The number of outputs for the layer.
bool bias_term
Whether to have bias terms or not.
Specifies the base parameter for all layers.
InnerProductParameter inner_product_param
Returns the parameter set when initialized with LayerType.INNERPRODUCT
ConcatParameter concat_param
Returns the parameter set when initialized with LayerType.CONCAT
CfcUnitParameter cfc_unit_param
Returns the parameter set when initialized with LayerType.CFC_UNIT
LayerType
Specifies the layer type.
DropoutParameter dropout_param
Returns the parameter set when initialized with LayerType.DROPOUT
Specifies the parameters for the CfcUnitLayer used by the CfCLayer.
ACTIVATION
Defines the activation function used by the backbone.
bool no_gate
Specifies whether to use the gate or not (when true, the no gate mode is used to calculate the forwar...
ACTIVATION backbone_activation
Specifies the backbone activation function.
int hidden_size
Specifies the hidden size used to size the backbone units and other internal layers.
int backbone_units
Specifies the number of backbone units
int backbone_layers
Specifies the number of backbone layers.
float backbone_dropout_ratio
Specifies the backbone dropout ratio.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
The MyCaffe.common namespace contains common MyCaffe classes.
DIR
Defines the direction of data flow.
WEIGHT_TARGET
Defines the type of weight to target in re-initializations.
The MyCaffe.layers.lnn namespace contains all Liquid Neural Network (LNN) related layers.
The MyCaffe.param namespace contains parameters used to create models.
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...