2using System.Collections.Generic;
36 double m_dfClippingThreshold;
109 m_blobBiasMultiplier.
Dispose();
128 col.
Add(m_blobBiasMultiplier);
131 col.
Add(m_blobPreGate);
137 col.
Add(m_blob_H_to_Gate);
138 col.
Add(m_blob_H_to_H);
148 base.ReInitializeParameters(target);
169 for (
int i = m_nH; i < 2 * m_nH; i++)
192 m_nI = (int)(colBottom[0].count() / colBottom[0].num);
208 List<int> rgShape1 =
new List<int>() { 4 * m_nH, m_nI };
215 blobWeights_I_H.
Reshape(rgShape1);
216 weight_filler.
Fill(blobWeights_I_H);
222 List<int> rgShape2 =
new List<int>() { 4 * m_nH, m_nH };
229 blobWeights_H_H.
Reshape(rgShape2);
230 weight_filler.
Fill(blobWeights_H_H);
235 List<int> rgShape3 =
new List<int>() { 4 * m_nH };
243 bias_filler.
Fill(blobBias);
254 for (
int i=m_nH; i<2*m_nH; i++)
265 List<int> rgCellShape =
new List<int>() { m_nN, m_nH };
266 m_blob_C_0.
Reshape(rgCellShape);
267 m_blob_H_0.
Reshape(rgCellShape);
268 m_blob_C_T.
Reshape(rgCellShape);
269 m_blob_H_T.
Reshape(rgCellShape);
270 m_blob_H_to_H.
Reshape(rgCellShape);
272 List<int> rgGateShape =
new List<int>() { m_nN, 4, m_nH };
273 m_blob_H_to_Gate.
Reshape(rgGateShape);
285 m_nN = colBottom[0].num;
290 m_nT = colBottom[0].num / m_nN;
291 m_log.
CHECK_EQ(colBottom[0].num % m_nN, 0,
"The inputs size should be a multiple of the batch size.");
292 m_log.
CHECK_EQ(colBottom[0].count() / m_nT / m_nN, m_nI,
"The input size is incompatible with inner product parameters.");
294 List<int> rgOriginalTopShape =
new List<int>() { m_nT * m_nN, m_nH };
295 colTop[0].
Reshape(rgOriginalTopShape);
298 List<int> rgGateShape =
new List<int>() { m_nT, m_nN, 4, m_nH };
299 m_blobPreGate.
Reshape(rgGateShape);
300 m_blobGate.
Reshape(rgGateShape);
301 m_blob_H_to_Gate.
Reshape(rgGateShape);
303 List<int> rgTopShape =
new List<int>() { m_nT, m_nN, m_nH };
304 m_blobCell.
Reshape(rgTopShape);
310 List<int> rgMultiplierShape =
new List<int>() { m_nN * m_nT };
311 m_blobBiasMultiplier.
Reshape(rgMultiplierShape);
312 m_blobBiasMultiplier.
SetData(1.0);
314 List<int> rgCellShape =
new List<int>() { m_nN, m_nH };
315 m_blob_C_0.
Reshape(rgCellShape);
316 m_blob_H_0.
Reshape(rgCellShape);
317 m_blob_C_T.
Reshape(rgCellShape);
318 m_blob_H_T.
Reshape(rgCellShape);
319 m_blob_H_to_H.
Reshape(rgCellShape);
334 m_log.
CHECK_EQ(colTop[0].gpu_data, m_blobTop.
gpu_data,
"The top[0].gpu_data should equal the blobTop.gpu_data.");
336 long hBottomData = colBottom[0].gpu_data;
339 if (colBottom.
Count > 1)
341 hClipData = colBottom[1].gpu_data;
342 m_log.
CHECK_EQ(colBottom[1].num, colBottom[1].count(),
"The bottom[1].num should equal the bottom[1].count.");
366 m_cuda.gemm(
false,
true, m_nT * m_nN, 4 * m_nH, m_nI,
m_tOne, hBottomData, hWeight_i,
m_tZero, hPreGateData);
370 for (
int t = 0; t < m_nT; t++)
372 int nTopOffset = m_blobTop.
offset(t);
373 int nCellOffset = m_blobCell.
offset(t);
374 int nPreGateOffset = m_blobPreGate.
offset(t);
375 int nGateOffset = m_blobGate.
offset(t);
376 int nClipOffset = (hClipData != 0) ? colBottom[1].offset(t) : 0;
392 nHT1Offset = -m_blobTop.
offset(1);
394 nCT1Offset = -m_blobCell.
offset(1);
438 long hBottomData = colBottom[0].gpu_data;
441 if (colBottom.
Count > 1)
443 hClipData = colBottom[1].gpu_data;
444 m_log.
CHECK_EQ(colBottom[1].num, colBottom[1].count(),
"The bottom[1].num should equal the bottom[1].count.");
449 long hGateData = m_blobGate.
gpu_data;
450 long hCellData = m_blobCell.
gpu_data;
460 for (
int t = m_nT - 1; t >= 0; t--)
462 int nTopOffset = m_blobTop.
offset(t);
463 int nCellOffset = m_blobCell.
offset(t);
464 int nGateOffset = m_blobGate.
offset(t);
465 int nPreGateOffset = m_blobPreGate.
offset(t);
466 int nClipOffset = (hClipData == 0) ? 0 : colBottom[1].offset(t);
485 nCT1Offset = m_blobCell.
offset(t - 1);
486 hCT1Data = hCellData;
487 nDHT1Offset = m_blobTop.
offset(t - 1);
488 hDHT1Diff = hTopDiff;
489 nDCT1Offset = m_blobCell.
offset(t - 1);
490 hDCT1Diff = hCellDiff;
497 m_dfClippingThreshold,
529 m_cuda.gemm(
true,
false, 4 * m_nH, m_nH, (m_nT - 1) * m_nN,
m_tOne, hPreGateDiff, hTopData,
m_tOne,
m_colBlobs[1].mutable_gpu_diff, m_blobPreGate.
offset(1));
541 if (rgbPropagateDown[0])
544 m_cuda.gemm(
false,
false, m_nT * m_nN, m_nI, 4 * m_nH,
m_tOne, hPreGateDiff, hWeight_i,
m_tZero, colBottom[0].mutable_gpu_diff);
The Log class provides general output in text form.
void WriteLine(string str, bool bOverrideEnabled=false, bool bHeader=false, bool bError=false, bool bDisable=false)
Write a line of output.
void CHECK_EQ(double df1, double df2, string str)
Test whether one number is equal to another.
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 Reshape(int[] rgShape)
Reshapes all blobs in the collection to the given shape.
The Blob is the main holder of data that moves through the Layers of the Net.
void SetData(T[] rgData, int nCount=-1, bool bSetCount=true)
Sets a number of items within the Blob's data.
void ShareData(Blob< T > b)
Set the data to point to the data of the other blob – useful in Layers which simply perform a copy in...
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.
T[] mutable_cpu_data
Get data from the GPU and bring it over to the host, or Set data from the Host and send it over to th...
void Reshape(int nNum, int nChannels, int nHeight, int nWidth, bool? bUseHalfSize=null)
DEPRECIATED; use
BLOB_TYPE type
Returns the BLOB_TYPE of the Blob.
int count()
Returns the total number of items in the Blob.
void ShareDiff(Blob< T > b)
Set the diff to point to the diff of the other blob – useful in Layers which simply perform a copy in...
string Name
Get/set the name of the Blob.
int offset(int n, int c=0, int h=0, int w=0)
Returns the flat offset given the number, channel, height and width.
long gpu_diff
Returns the diff GPU handle used by the CudaDnn connection.
virtual void Dispose(bool bDisposing)
Releases all resources used by the Blob (including both GPU and Host).
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.
Abstract Filler class used to fill blobs with values.
void Fill(Blob< T > b)
Fill the blob with values based on the actual filler used.
static Filler< T > Create(CudaDnn< T > cuda, Log log, FillerParameter p)
Create a new Filler instance.
[DEPRECIATED - use LSTMAttentionLayer instead with enable_attention = false] The LSTMSimpleLayer is a...
override void setup_internal_blobs(BlobCollection< T > col)
Derivative layers should add all internal blobws to the 'col' provided.
override bool ReInitializeParameters(WEIGHT_TARGET target)
Re-initialize the parameters of the layer.
override void forward(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Forward computation.
override void dispose()
Releases all GPU and host resources used by the Layer.
override void backward(BlobCollection< T > colTop, List< bool > rgbPropagateDown, BlobCollection< T > colBottom)
Computes the error gradient w.r.t. the inputs.
override void Reshape(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Reshape the bottom (input) and top (output) blobs.
override void LayerSetUp(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Setup the layer.
LSTMSimpleLayer(CudaDnn< T > cuda, Log log, LayerParameter p)
The LSTMSimpleLayer constructor.
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 convert(BlobCollection< T > col)
Convert a collection of blobs from / to half size.
T m_tZero
Specifies a generic type equal to 0.0.
T m_tOne
Specifies a generic type equal to 1.0.
bool shareParameter(Blob< T > b, List< int > rgMinShape, bool bAllowEndsWithComparison=false)
Attempts to share a parameter Blob if another parameter Blob with the same name and accpetable size i...
double convertD(T df)
Converts a generic to a double value.
CudaDnn< T > m_cuda
Specifies the CudaDnn connection to Cuda.
LayerParameter.LayerType m_type
Specifies the Layer type.
BlobCollection< T > m_colBlobs
Specifies the learnable parameter Blobs of the Layer.
DictionaryMap< bool > m_rgbParamPropagateDown
Specifies whether or not to compute the learnable diff of each parameter Blob.
bool m_bNetReshapeRequest
Specifies whether the reshape is requested from a Net.Reshape call or not.
double clipping_threshold
Specifies the gradient clipping threshold, default = 0.0 (i.e. no clipping).
FillerParameter weight_filler
Specifies the filler parameters for the weight filler.
uint num_output
Specifies the number of outputs for the layer.
FillerParameter bias_filler
Specifies the filler parameters for the bias filler.
uint batch_size
Specifies the batch size, default = 1.
bool enable_clockwork_forgetgate_bias
When enabled, the forget gate bias is set to 5.0.
Specifies the base parameter for all layers.
string name
Specifies the name of this LayerParameter.
LSTMSimpleParameter lstm_simple_param
[DEPRECIATED] Returns the parameter set when initialized with LayerType.LSTM_SIMPLE
LayerType
Specifies the layer type.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
The MyCaffe.common namespace contains common MyCaffe classes.
BLOB_TYPE
Defines the tpe of data held by a given Blob.
WEIGHT_TARGET
Defines the type of weight to target in re-initializations.
The MyCaffe.fillers namespace contains all fillers including the Filler class.
The MyCaffe.layers namespace contains all layers that have a solidified code base,...
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-...