2using System.Collections.Generic;
40 Blob<T> m_blobContextAdd =
null;
43 Blob<T> m_blobGatePlusResidual =
null;
60 m_blobResidual =
new Blob<T>(cuda, log);
62 m_blobIp1 =
new Blob<T>(cuda, log);
64 m_blobIp2 =
new Blob<T>(cuda, log);
66 m_blobGate =
new Blob<T>(cuda, log);
68 m_blobGatePlusResidual =
new Blob<T>(cuda, log);
69 m_blobGatePlusResidual.
Name = p.
name +
".gate_p_res";
70 m_blobBtm =
new Blob<T>(cuda, log);
83 dispose(ref m_blobGatePlusResidual);
102 if (m_blobContext !=
null)
103 col.
Add(m_blobContext);
104 if (m_blobContextAdd !=
null)
105 col.
Add(m_blobContextAdd);
106 if (m_blobResidual !=
null)
107 col.
Add(m_blobResidual);
111 col.
Add(m_blobGatePlusResidual);
161 if (m_ipSkipLayer ==
null)
170 addBtmTop(colBottom[0], m_blobResidual);
171 m_ipSkipLayer.Setup(m_colBtm, m_colTop);
172 blobs.Add(m_ipSkipLayer.blobs);
186 addBtmTop(colBottom[0], m_blobIp1);
187 m_ipFc1.
Setup(m_colBtm, m_colTop);
193 if (colBottom.
Count > 1)
195 if (m_ipContext ==
null)
208 addBtmTop(colBottom[1], m_blobContext);
209 m_ipContext.
Setup(m_colBtm, m_colTop);
214 blobIp1 = m_blobContext;
233 addBtmTop(blobIp1, blobIp1);
234 m_act.
Setup(m_colBtm, m_colTop);
251 addBtmTop(blobIp1, m_blobIp2);
252 m_ipFc2.
Setup(m_colBtm, m_colTop);
262 if (m_dropout ==
null)
268 addBtmTop(m_blobIp2, m_blobIp2);
269 m_dropout.
Setup(m_colBtm, m_colTop);
282 addBtmTop(m_blobIp2, m_blobGate);
283 m_gate.
Setup(m_colBtm, m_colTop);
287 if (m_layerNorm ==
null)
293 addBtmTop(m_blobGate, colTop[0]);
294 m_layerNorm.
Setup(m_colBtm, m_colTop);
307 if (m_ipSkipLayer !=
null)
309 addBtmTop(colBottom[0], m_blobResidual);
310 m_ipSkipLayer.Reshape(m_colBtm, m_colTop);
313 addBtmTop(colBottom[0], m_blobIp1);
314 m_ipFc1.
Reshape(m_colBtm, m_colTop);
317 if (colBottom.
Count > 1)
319 addBtmTop(colBottom[1], m_blobContext);
320 m_ipContext.
Reshape(m_colBtm, m_colTop);
322 blobIp1 = m_blobContext;
325 addBtmTop(blobIp1, blobIp1);
326 m_act.
Reshape(m_colBtm, m_colTop);
328 addBtmTop(blobIp1, m_blobIp2);
329 m_ipFc2.
Reshape(m_colBtm, m_colTop);
331 if (m_dropout !=
null)
333 addBtmTop(m_blobIp2, m_blobIp2);
334 m_dropout.
Reshape(m_colBtm, m_colTop);
337 addBtmTop(m_blobIp2, m_blobGate);
338 m_gate.
Reshape(m_colBtm, m_colTop);
342 addBtmTop(m_blobGate, colTop[0]);
343 m_layerNorm.
Reshape(m_colBtm, m_colTop);
361 Blob<T> blobResidual = colBottom[0];
363 if (m_ipSkipLayer !=
null)
365 addBtmTop(colBottom[0], m_blobResidual);
366 m_ipSkipLayer.Forward(m_colBtm, m_colTop);
367 blobResidual = m_blobResidual;
370 addBtmTop(colBottom[0], m_blobIp1);
371 m_ipFc1.
Forward(m_colBtm, m_colTop);
374 if (colBottom.
Count > 1)
376 addBtmTop(colBottom[1], m_blobContext);
377 m_ipContext.
Forward(m_colBtm, m_colTop);
380 blobIp1 = m_blobContextAdd;
384 addBtmTop(blobIp1, blobIp1);
385 m_act.
Forward(m_colBtm, m_colTop);
388 addBtmTop(blobIp1, m_blobIp2);
389 m_ipFc2.
Forward(m_colBtm, m_colTop);
392 if (m_dropout !=
null)
394 addBtmTop(m_blobIp2, m_blobIp2);
395 m_dropout.
Forward(m_colBtm, m_colTop);
399 addBtmTop(m_blobIp2, m_blobGate);
400 m_gate.
Forward(m_colBtm, m_colTop);
406 addBtmTop(m_blobGatePlusResidual, colTop[0]);
407 m_layerNorm.
Forward(m_colBtm, m_colTop);
427 addBtmTop(m_blobGatePlusResidual, colTop[0]);
428 m_layerNorm.
Backward(m_colTop, rgbPropagateDown, m_colBtm);
431 if (m_ipSkipLayer !=
null)
432 m_blobResidual.
CopyFrom(m_blobGatePlusResidual,
true);
434 colBottom[0].
CopyFrom(m_blobGatePlusResidual,
true,
false, 0,
true);
436 m_blobGate.
CopyFrom(m_blobGatePlusResidual,
true,
false, 0,
true);
439 addBtmTop(m_blobIp2, m_blobGate);
440 m_gate.
Backward(m_colTop, rgbPropagateDown, m_colBtm);
443 if (m_dropout !=
null)
445 addBtmTop(m_blobIp2, m_blobIp2);
446 m_dropout.
Backward(m_colTop, rgbPropagateDown, m_colBtm);
450 if (colBottom.
Count > 1)
451 blobIp1 = m_blobContextAdd;
454 addBtmTop(blobIp1, m_blobIp2);
455 m_ipFc2.
Backward(m_colTop, rgbPropagateDown, m_colBtm);
458 addBtmTop(blobIp1, blobIp1);
459 m_act.
Backward(m_colTop, rgbPropagateDown, m_colBtm);
461 if (colBottom.
Count > 1)
463 m_blobContext.
CopyFrom(m_blobContextAdd,
true);
464 m_blobIp1.
CopyFrom(m_blobContextAdd,
true);
466 addBtmTop(colBottom[1], m_blobContext);
467 m_ipContext.
Backward(m_colTop, rgbPropagateDown, m_colBtm);
471 addBtmTop(m_blobBtm, m_blobIp1);
472 m_ipFc1.
Backward(m_colTop, rgbPropagateDown, m_colBtm);
474 m_cuda.add(colBottom[0].count(), colBottom[0].gpu_diff, m_blobBtm.
gpu_diff, colBottom[0].mutable_gpu_diff);
476 if (m_ipSkipLayer !=
null)
478 addBtmTop(m_blobBtm, m_blobResidual);
479 m_ipSkipLayer.Backward(m_colTop, rgbPropagateDown, m_colBtm);
480 m_cuda.add(colBottom[0].count(), colBottom[0].gpu_diff, m_blobBtm.
gpu_diff, colBottom[0].mutable_gpu_diff);
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.
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.
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.
BlobCollection< T > m_colInternalBlobs
Specifies internal blobs 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 GrnLayer implements the Gated Linear Unit layer.
override void LayerSetUp(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Setup the layer.
override int ExactNumTopBlobs
Returns the exact number of required top (output) Blobs: y
override int MinBottomBlobs
Returns the min number of required bottom (input) Blobs: x
override int MaxBottomBlobs
Returns the max number of required bottom (input) Blobs: x, context
GrnLayer(CudaDnn< T > cuda, Log log, LayerParameter p)
The constructor.
override void backward(BlobCollection< T > colTop, List< bool > rgbPropagateDown, BlobCollection< T > colBottom)
Computes the error gradient w.r.t. the stacked embedding numeric and categorical value inputs.
override void Reshape(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Reshape the top (output) blobs.
override void setup_internal_blobs(BlobCollection< T > col)
Derivative layers should add all internal blobws to the 'col' provided.
override void dispose()
Releases all GPU and host resources used by the Layer.
override void forward(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Forward computation
double dropout_ratio
Specifies the dropout ratio. (e.g. the probability that values will be dropped out and set to zero....
double alpha
Described in Fast and Accurate Deep Network Learning by Exponential Linear Units (ELUs) by Clevert,...
Specifies whether to use the NVIDIA cuDnn version or Caffe version of a given forward/backward operat...
Engine engine
Specifies the Engine in use.
Engine
Defines the type of engine to use.
FillerParameter weight_filler
The filler for the weights.
int axis
Specifies the first axis to be lumped into a single inner product computation; all preceding axes are...
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.
string name
Specifies the name of this LayerParameter.
LayerNormParameter layer_norm_param
Returns the parameter set when initialized with LayerType.LAYERNORM
GluParameter glu_param
Returns the parameter set when initialized with LayerType.GLU
GrnParameter grn_param
Returns the parameter set when initialized with LayerType.GLU
EluParameter elu_param
Returns the parameter set when initialized with LayerType.ELU
InnerProductParameter inner_product_param
Returns the parameter set when initialized with LayerType.INNERPRODUCT
LayerType
Specifies the layer type.
DropoutParameter dropout_param
Returns the parameter set when initialized with LayerType.DROPOUT
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
The MyCaffe.common namespace contains common MyCaffe classes.
The MyCaffe.layers.tft namespace contains all TFT 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-...