MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
VarSelNetLayer.cs
1using System;
2using System.Collections.Generic;
3using System.Diagnostics;
4using System.Linq;
5using System.Net.Http.Headers;
6using System.Reflection;
7using System.Text;
8using MyCaffe.basecode;
9using MyCaffe.common;
10using MyCaffe.param;
11
12namespace MyCaffe.layers.tft
13{
28 public class VarSetNetLayer<T> : Layer<T>
29 {
30 Layer<T> m_grnFlatten;
31 Blob<T> m_blobSparseWts;
32 Layer<T> m_softmax;
33 Blob<T> m_blobSparseWtsSmx;
34 Layer<T> m_transpose;
35 Blob<T> m_blobSparseWtsSmxT;
36 Blob<T> m_blobGrn1;
37 Blob<T> m_blobProcessedInputs;
38 Blob<T> m_blobProcessedInputsT;
39 Blob<T> m_blobProcessedInputs1;
40 Blob<T> m_blobBtm;
41 List<Layer<T>> m_rgSingleVarGrn = new List<Layer<T>>();
42 BlobCollection<T> m_colSingleVarGrn = new BlobCollection<T>();
43 BlobCollection<T> m_colTop = new BlobCollection<T>();
44 BlobCollection<T> m_colBtm = new BlobCollection<T>();
45 List<int> m_rgShape = new List<int>(4);
46 List<int> m_rgShapeOringal = new List<int>(4);
47
55 : base(cuda, log, p)
56 {
58
59 m_blobSparseWts = new Blob<T>(cuda, log);
60 m_blobSparseWts.Name = p.name + ".spwts";
61 m_blobSparseWtsSmx = new Blob<T>(cuda, log);
62 m_blobSparseWtsSmx.Name = p.name + ".spwts_smx";
63 m_blobSparseWtsSmxT = new Blob<T>(cuda, log);
64 m_blobSparseWtsSmxT.Name = p.name + ".spwts_smxT";
65 m_blobGrn1 = new Blob<T>(cuda, log);
66 m_blobGrn1.Name = p.name + ".grn1";
67 m_blobProcessedInputs = new Blob<T>(cuda, log);
68 m_blobProcessedInputs.Name = p.name + ".proc_in";
69 m_blobProcessedInputsT = new Blob<T>(cuda, log);
70 m_blobProcessedInputsT.Name = p.name + ".proc_inT";
71 m_blobProcessedInputs1 = new Blob<T>(cuda, log);
72 m_blobProcessedInputs1.Name = p.name + ".proc_in1";
73 m_blobBtm = new Blob<T>(cuda, log);
74 m_blobBtm.Name = p.name + ".btm";
75 }
76
78 protected override void dispose()
79 {
80 dispose(ref m_blobSparseWts);
81 dispose(ref m_blobSparseWtsSmx);
82 dispose(ref m_blobSparseWtsSmxT);
83 dispose(ref m_blobGrn1);
84 dispose(ref m_blobProcessedInputs);
85 dispose(ref m_blobProcessedInputsT);
86 dispose(ref m_blobProcessedInputs1);
87 dispose(ref m_blobBtm);
88
89 if (m_colSingleVarGrn != null)
90 {
91 m_colSingleVarGrn.Dispose();
92 m_colSingleVarGrn = null;
93 }
94
95 dispose(ref m_grnFlatten);
96
97 if (m_rgSingleVarGrn != null)
98 {
99 foreach (Layer<T> layer in m_rgSingleVarGrn)
100 {
101 layer.Dispose();
102 }
103 m_rgSingleVarGrn = null;
104 }
105 }
106
108 protected override void setup_internal_blobs(BlobCollection<T> col)
109 {
110 if (col.Count > 0)
111 return;
112
113 col.Add(m_blobSparseWts);
114 col.Add(m_blobSparseWtsSmx);
115 col.Add(m_blobSparseWtsSmxT);
116 col.Add(m_blobGrn1);
117 col.Add(m_blobProcessedInputs);
118 col.Add(m_blobProcessedInputsT);
119 col.Add(m_blobProcessedInputs1);
120 col.Add(m_blobBtm);
121 }
122
126 public override int MinBottomBlobs
127 {
128 get { return 1; }
129 }
130
134 public override int MaxBottomBlobs
135 {
136 get { return 2; }
137 }
138
142 public override int MinTopBlobs
143 {
144 get { return 1; }
145 }
146
150 public override int MaxTopBlobs
151 {
152 get { return 2; }
153 }
154
155 private void addBtmTop(Blob<T> btm, Blob<T> top)
156 {
157 m_colBtm.Clear();
158 m_colBtm.Add(btm);
159 m_colTop.Clear();
160 m_colTop.Add(top);
161 }
162
168 public override void LayerSetUp(BlobCollection<T> colBottom, BlobCollection<T> colTop)
169 {
170 List<int> rgShape = new List<int>();
171 Blob<T> blobStaticSelection = null;
172
173 if (colBottom.Count > 1)
174 blobStaticSelection = colBottom[1];
175
176 // This GRN is applied on the flat concatenation of the input representation (all inputs together),
177 // possibly provided with context information.
178 if (m_grnFlatten == null)
179 {
181 p.grn_param.axis = m_param.varselnet_param.axis;
182 p.grn_param.batch_first = m_param.varselnet_param.batch_first;
183 p.grn_param.bias_filler = m_param.varselnet_param.bias_filler;
184 p.grn_param.weight_filler = m_param.varselnet_param.weight_filler;
185 p.grn_param.input_dim = m_param.varselnet_param.num_inputs * m_param.varselnet_param.input_dim;
186 p.grn_param.hidden_dim = m_param.varselnet_param.hidden_dim;
187 p.grn_param.output_dim = m_param.varselnet_param.num_inputs;
188 p.grn_param.context_dim = m_param.varselnet_param.context_dim;
189 m_grnFlatten = Layer<T>.Create(m_cuda, m_log, convertLayerParam(p, m_param), null);
190
191 addBtmTop(colBottom[0], m_blobSparseWts);
192 if (blobStaticSelection != null)
193 m_colBtm.Add(blobStaticSelection);
194 m_grnFlatten.Setup(m_colBtm, m_colTop);
195 blobs.Add(m_grnFlatten.blobs);
196 }
197
198 // Activation for transforming the GRN output to weights.
199 if (m_softmax == null)
200 {
204 m_softmax = Layer<T>.Create(m_cuda, m_log, convertLayerParam(p, m_param), null);
205
206 addBtmTop(m_blobSparseWts, m_blobSparseWtsSmx);
207 m_softmax.Setup(m_colBtm, m_colTop);
208 }
209
210 rgShape = Utility.Clone<int>(m_blobSparseWtsSmx.shape());
211 rgShape.Add(1);
212 rgShape.Add(1);
213 m_blobSparseWtsSmx.Reshape(rgShape);
214
215 // Setup transpose applied to smx.
216 if (m_transpose == null)
217 {
219 p.transpose_param.dim[1] = 2;
220 p.transpose_param.dim[2] = 1;
221 m_transpose = Layer<T>.Create(m_cuda, m_log, convertLayerParam(p, m_param), null);
222
223 addBtmTop(m_blobSparseWtsSmx, m_blobSparseWtsSmxT);
224 m_transpose.Setup(m_colBtm, m_colTop);
225 }
226
227 // Each input variable (after transformation into its wide represenation) goes through its own GRN
228 rgShape.Clear();
229 rgShape.Add(colBottom[0].num);
230 rgShape.Add(colBottom[0].channels / m_param.varselnet_param.num_inputs);
231 m_blobGrn1.Reshape(rgShape);
232
233 if (m_rgSingleVarGrn.Count < m_param.varselnet_param.num_inputs)
234 {
235 for (int i = 0; i < m_param.varselnet_param.num_inputs; i++)
236 {
237 LayerParameter p = new LayerParameter(LayerParameter.LayerType.GRN, m_param.name + ".grn" + i.ToString());
238 p.grn_param.axis = m_param.varselnet_param.axis;
239 p.grn_param.batch_first = m_param.varselnet_param.batch_first;
240 p.grn_param.bias_filler = m_param.varselnet_param.bias_filler;
241 p.grn_param.weight_filler = m_param.varselnet_param.weight_filler;
242 p.grn_param.input_dim = m_param.varselnet_param.input_dim;
243 p.grn_param.hidden_dim = m_param.varselnet_param.hidden_dim;
244 p.grn_param.output_dim = m_param.varselnet_param.hidden_dim;
245 p.grn_param.dropout_ratio = m_param.varselnet_param.dropout_ratio;
247
248 Blob<T> blobGrn = new Blob<T>(m_cuda, m_log);
249 blobGrn.ReshapeLike(m_blobGrn1);
250
251 m_rgSingleVarGrn.Add(grn);
252 m_colSingleVarGrn.Add(blobGrn);
253
254 addBtmTop(m_blobGrn1, m_colSingleVarGrn[i]);
255 m_rgSingleVarGrn[i].Setup(m_colBtm, m_colTop);
256 blobs.Add(grn.blobs);
257 }
258 }
259
260 rgShape.Clear();
261 rgShape.Add(colBottom[0].num);
262 rgShape.Add(colBottom[0].channels / m_param.varselnet_param.num_inputs);
263 rgShape.Add(m_param.varselnet_param.num_inputs);
264 m_blobProcessedInputs.Reshape(rgShape);
265 m_blobProcessedInputs1.Reshape(rgShape);
266 }
267
273 public override void Reshape(BlobCollection<T> colBottom, BlobCollection<T> colTop)
274 {
275 List<int> rgShape;
276 Blob<T> blobStaticSelection = null;
277
278 if (colBottom.Count > 1)
279 blobStaticSelection = colBottom[1];
280
281 m_blobBtm.ReshapeLike(colBottom[0]);
282
283 m_rgShape.Clear();
284 m_rgShapeOringal.Clear();
285
286 addBtmTop(colBottom[0], m_blobSparseWts);
287 if (colBottom.Count > 1)
288 m_colBtm.Add(blobStaticSelection);
289 m_grnFlatten.Reshape(m_colBtm, m_colTop);
290
291 addBtmTop(m_blobSparseWts, m_blobSparseWtsSmx);
292 m_softmax.Reshape(m_colBtm, m_colTop);
293
294 rgShape = Utility.Clone<int>(m_blobSparseWtsSmx.shape());
295 rgShape.Add(1);
296 rgShape.Add(1);
297 m_blobSparseWtsSmx.Reshape(rgShape);
298
299 addBtmTop(m_blobSparseWtsSmx, m_blobSparseWtsSmxT);
300 m_transpose.Reshape(m_colBtm, m_colTop);
301
302 rgShape.Clear();
303 rgShape.Add(colBottom[0].num);
304 rgShape.Add(colBottom[0].channels / m_param.varselnet_param.num_inputs);
305 m_blobGrn1.Reshape(rgShape);
306
307 for (int i = 0; i < m_param.varselnet_param.num_inputs; i++)
308 {
309 m_colSingleVarGrn[i].ReshapeLike(m_blobGrn1);
310
311 addBtmTop(m_blobGrn1, m_colSingleVarGrn[i]);
312 m_rgSingleVarGrn[i].Reshape(m_colBtm, m_colTop);
313 }
314
315 rgShape = Utility.Clone<int>(m_colSingleVarGrn[0].shape());
316 rgShape.Add(m_param.varselnet_param.num_inputs);
317 m_blobProcessedInputs.Reshape(rgShape);
318 m_blobProcessedInputs1.Reshape(rgShape);
319
320 colTop[0].ReshapeLike(m_colSingleVarGrn[0]);
321 if (colTop.Count > 1)
322 {
323 colTop[1].ReshapeLike(m_blobSparseWts);
324 colTop[1].type = BLOB_TYPE.WEIGHT;
325 }
326 }
327
339 protected override void forward(BlobCollection<T> colBottom, BlobCollection<T> colTop)
340 {
341 m_blobBtm.CopyFrom(colBottom[0]);
342 Blob<T> blobStaticSelection = null;
343
344 if (colBottom.Count > 1)
345 blobStaticSelection = colBottom[1];
346
347 // Infer variable selection weights using flattened embedding run through GRN. The flattened embedding
348 // should have shape [(num_samples * num_temporal_steps) x (num_inputs x input_dim)] where the
349 // input_dim represents the model_dim or the state_dim. With static variable selection, num_temporal_Steps
350 // is set to 1.
351 addBtmTop(colBottom[0], m_blobSparseWts);
352 if (colBottom.Count > 1)
353 m_colBtm.Add(blobStaticSelection);
354 m_grnFlatten.Forward(m_colBtm, m_colTop);
355
356 // Sparse weights are of shape [(num_samples * num_temporal_steps) x num_inputs x 1]
357 addBtmTop(m_blobSparseWts, m_blobSparseWtsSmx);
358 m_softmax.Forward(m_colBtm, m_colTop);
359
360 // Unsqueeze by 2
361 List<int> rgShape = Utility.Clone<int>(m_blobSparseWtsSmx.shape());
362 rgShape.Add(1);
363 rgShape.Add(1);
364 m_blobSparseWtsSmx.Reshape(rgShape);
365
366 // Before weighting the variables, a GRN is applied ot each transformed input.
367 for (int i = 0; i < m_param.varselnet_param.num_inputs; i++)
368 {
369 // Copy the variable specific data to the GRN input.
370 m_cuda.channel_copy(m_blobGrn1.count(), m_blobGrn1.num, 1, m_param.varselnet_param.num_inputs, m_blobGrn1.channels, i, colBottom[0].gpu_data, m_blobGrn1.mutable_gpu_data, DIR.FWD);
371
372 // Each element in the resulting list is of size [(num_samples * num_temporal_steps) x state_size],
373 // and each element corresponds to a single input variable.
374 addBtmTop(m_blobGrn1, m_colSingleVarGrn[i]);
375 m_rgSingleVarGrn[i].Forward(m_colBtm, m_colTop);
376
377 // Combine the outputs of the state var GRNs along an additional axis with
378 // dimension [(num_samples * num_temporal_steps) x state_size x num_inputs]
379 m_cuda.channel_copy(m_blobGrn1.count(), m_blobGrn1.num, m_blobGrn1.channels, m_param.varselnet_param.num_inputs, 1, i, m_blobProcessedInputs.mutable_gpu_data, m_colSingleVarGrn[i].gpu_data, DIR.BWD);
380 }
381
382 // Weigh the processed inputs with the weights viewed as [(num_samples * num_temporal_steps) x 1 x num_inputs]
383 // so that the weight given to each variable (for each time-step/observation) multiplies the entire state
384 // vector representing the specific input variable on the specific time-step
385 addBtmTop(m_blobSparseWtsSmx, m_blobSparseWtsSmxT);
386 m_transpose.Forward(m_colBtm, m_colTop);
387
388 // Apply the transposed smx weightings to the processed inputs
389 int nInnerNum = m_blobProcessedInputs.count(2);
390 m_cuda.channel_mulv(m_blobProcessedInputs.count(), m_blobProcessedInputs.num, m_blobProcessedInputs.channels, nInnerNum, m_blobProcessedInputs.gpu_data, m_blobSparseWtsSmxT.gpu_data, m_blobProcessedInputs1.mutable_gpu_data);
391
392 // Sum up the weights to create a weighted sum representation of width state_size for each time-step and
393 // dimension [(num_samples * num_temporal_steps) x state_size x num_inputs]
394 m_cuda.channel_sum(m_blobProcessedInputs1.count(), m_blobProcessedInputs1.num, m_blobProcessedInputs1.channels, nInnerNum, m_blobProcessedInputs1.gpu_data, colTop[0].mutable_gpu_data, false);
395 if (colTop.Count > 1)
396 colTop[1].CopyFrom(m_blobSparseWts);
397 }
398
399 private void copyShape(List<int> rg, Blob<T> b)
400 {
401 rg.Clear();
402
403 for (int i = 0; i < b.shape().Count; i++)
404 {
405 rg.Add(b.shape(i));
406 }
407 }
408
423 protected override void backward(BlobCollection<T> colTop, List<bool> rgbPropagateDown, BlobCollection<T> colBottom)
424 {
425 // Expand the top(0) diff to each channel in the processed inputs.
426 int nInnerNum = m_blobProcessedInputs.count(2);
427 m_cuda.channel_fillfrom(m_blobProcessedInputs1.count(), m_blobProcessedInputs1.num, m_blobProcessedInputs1.channels, nInnerNum, colTop[0].gpu_diff, m_blobProcessedInputs1.mutable_gpu_diff, DIR.FWD);
428
429 // Apply the transposed smx weightings to the processed inputs.
430 m_cuda.channel_mulv(m_blobProcessedInputs.count(), m_blobProcessedInputs.num, m_blobProcessedInputs.channels, nInnerNum, m_blobProcessedInputs1.gpu_diff, m_blobSparseWtsSmxT.gpu_data, m_blobProcessedInputs.mutable_gpu_diff);
431
432 // Calculate the SparseWtsT gradient as
433 // sparseWtsT.grad = ProcessedInput.dataT * colTop[0].diff
434 copyShape(m_rgShapeOringal, m_blobProcessedInputs);
435 copyShape(m_rgShape, m_blobProcessedInputs);
436 m_rgShape.Insert(1, 1);
437 m_blobProcessedInputs.Reshape(m_rgShape);
438 m_blobProcessedInputsT.CopyFromAndTransposeHeightWidth(m_blobProcessedInputs);
439 m_blobProcessedInputs.Reshape(m_rgShapeOringal);
440
441 copyShape(m_rgShapeOringal, colTop[0]);
442 copyShape(m_rgShape, colTop[0]);
443 m_rgShape.Insert(1, 1);
444 m_rgShape.Add(1);
445 colTop[0].Reshape(m_rgShape);
446
447 m_blobSparseWtsSmxT.MatMul(m_blobProcessedInputsT, colTop[0], true, false, false, 1, false, true, true);
448 colTop[0].Reshape(m_rgShapeOringal);
449
450 // Apply the transposed smx weightings to the processed inputs.
451 // GRN is applied ot each transformed input.
452 for (int i = 0; i < m_param.varselnet_param.num_inputs; i++)
453 {
454 // Copy the variable specific data to the GRN input.
455 m_cuda.channel_copy(m_blobGrn1.count(), m_blobGrn1.num, 1, m_param.varselnet_param.num_inputs, m_blobGrn1.channels, i, colBottom[0].gpu_data, m_blobGrn1.mutable_gpu_data, DIR.FWD);
456 // Combine the outputs of the state var GRNs along an additional axis with
457 // dimension [(num_samples * num_temporal_steps) x state_size x num_inputs]
458 m_cuda.channel_copy(m_blobGrn1.count(), m_blobGrn1.num, m_blobGrn1.channels, m_param.varselnet_param.num_inputs, 1, i, m_blobProcessedInputs.mutable_gpu_diff, m_colSingleVarGrn[i].gpu_diff, DIR.FWD);
459
460 // Each element in the resulting list is of size [(num_samples * num_temporal_steps) x state_size],
461 // and each element corresponds to a single input variable.
462 addBtmTop(m_blobGrn1, m_colSingleVarGrn[i]);
463 m_rgSingleVarGrn[i].Backward(m_colTop, rgbPropagateDown, m_colBtm);
464
465 // Copy the variable specific data to the GRN input.
466 m_cuda.channel_copy(m_blobGrn1.count(), m_blobGrn1.num, 1, m_param.varselnet_param.num_inputs, m_blobGrn1.channels, i, m_blobBtm.gpu_diff, m_blobGrn1.mutable_gpu_diff, DIR.BWD);
467 }
468
469 // Weigh the processed inputs with the weights viewed as [(num_samples * num_temporal_steps) x 1 x num_inputs]
470 // so that the weight given to each variable (for each time-step/observation) multiplies the entire state
471 // vector representing the specific input variable on the specific time-step
472 addBtmTop(m_blobSparseWtsSmx, m_blobSparseWtsSmxT);
473 m_transpose.Backward(m_colTop, rgbPropagateDown, m_colBtm);
474
475 // Sparse weights are of shape [(num_samples * num_temporal_steps) x num_inputs x 1]
476 addBtmTop(m_blobSparseWts, m_blobSparseWtsSmx);
477 m_softmax.Backward(m_colTop, rgbPropagateDown, m_colBtm);
478
479 // Infer variable selection weights using flattened embedding run through GRN. The flattened embedding
480 // should have shape [(num_samples * num_temporal_steps) x (num_inputs x input_dim)] where the
481 // input_dim represents the model_dim or the state_dim. With static variable selection, num_temporal_Steps
482 // is set to 1.
483 addBtmTop(colBottom[0], m_blobSparseWts);
484 if (colBottom.Count > 1)
485 m_colBtm.Add(colBottom[1]);
486 m_grnFlatten.Backward(m_colTop, rgbPropagateDown, m_colBtm);
487
488 // Add gradient accumulation from individual variable GRN's.
489 m_cuda.add(colBottom[0].count(), colBottom[0].gpu_diff, m_blobBtm.gpu_diff, colBottom[0].mutable_gpu_diff);
490 }
491 }
492}
The Log class provides general output in text form.
Definition: Log.cs:13
The Utility class provides general utility funtions.
Definition: Utility.cs:35
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 ReshapeLike(BlobCollection< T > src)
Reshapes all blobs in the collection to the sizes of the source.
void Reshape(int[] rgShape)
Reshapes all blobs in the collection to the given shape.
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.
Definition: Blob.cs:25
int channels
DEPRECIATED; legacy shape accessor channels: use shape(1) instead.
Definition: Blob.cs:800
void MatMul(Blob< T > blobA, Blob< T > blobB, bool bReshape=false, bool bTransA=false, bool bTransB=false, double dfScale=1.0, bool bADiff=false, bool bBDiff=false, bool bCDiff=false)
MatMul blobA with blobB and place the result in this blob (e.g. this = matmul(A, B))....
Definition: Blob.cs:3922
long mutable_gpu_diff
Returns the diff GPU handle used by the CudaDnn connection.
Definition: Blob.cs:1555
long mutable_gpu_data
Returns the data GPU handle used by the CudaDnn connection.
Definition: Blob.cs:1487
void CopyFromAndTransposeHeightWidth(Blob< T > blobSrc, bool bCopyDiff=false, bool bUseCuda=true)
Copy from a source Blob and transpose the height and width of the copy.
Definition: Blob.cs:1002
void Reshape(int nNum, int nChannels, int nHeight, int nWidth, bool? bUseHalfSize=null)
DEPRECIATED; use
Definition: Blob.cs:442
void CopyFrom(Blob< T > src, int nSrcOffset, int nDstOffset, int nCount, bool bCopyData, bool bCopyDiff)
Copy from a source Blob.
Definition: Blob.cs:903
List< int > shape()
Returns an array where each element contains the shape of an axis of the Blob.
Definition: Blob.cs:684
int count()
Returns the total number of items in the Blob.
Definition: Blob.cs:739
void ReshapeLike(Blob< T > b, bool? bUseHalfSize=null)
Reshape this Blob to have the same shape as another Blob.
Definition: Blob.cs:648
string Name
Get/set the name of the Blob.
Definition: Blob.cs:2184
long gpu_diff
Returns the diff GPU handle used by the CudaDnn connection.
Definition: Blob.cs:1541
int num
DEPRECIATED; legacy shape accessor num: use shape(0) instead.
Definition: Blob.cs:792
long gpu_data
Returns the data GPU handle used by the CudaDnn connection.
Definition: Blob.cs:1479
The CudaDnn object is the main interface to the Low-Level Cuda C++ DLL.
Definition: CudaDnn.cs:969
An interface for the units of computation which can be composed into a Net.
Definition: Layer.cs:31
Log m_log
Specifies the Log for output.
Definition: Layer.cs:43
LayerParameter m_param
Specifies the LayerParameter describing the Layer.
Definition: Layer.cs:47
void Backward(BlobCollection< T > colTop, List< bool > rgbPropagateDown, BlobCollection< T > colBottom)
Given the top Blob error gradients, compute the bottom Blob error gradients.
Definition: Layer.cs:815
double Forward(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Given the bottom (input) Blobs, this function computes the top (output) Blobs and the loss.
Definition: Layer.cs:728
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.
Definition: Layer.cs:180
CudaDnn< T > m_cuda
Specifies the CudaDnn connection to Cuda.
Definition: Layer.cs:39
void Setup(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Implements common Layer setup functionality.
Definition: Layer.cs:439
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.
Definition: Layer.cs:1468
LayerParameter.LayerType m_type
Specifies the Layer type.
Definition: Layer.cs:35
BlobCollection< T > blobs
Returns the collection of learnable parameter Blobs for the Layer.
Definition: Layer.cs:875
LayerParameter convertLayerParam(LayerParameter pChild, LayerParameter pParent)
Called to convert a parent LayerParameterEx, used in blob sharing, with a child layer parameter.
Definition: Layer.cs:1134
The VarSetNetLayer implements the Variable Selection Network
override void forward(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Forward computation
override void Reshape(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Reshape the top (output) blobs.
override int MinBottomBlobs
Returns the min number of required bottom (input) Blobs: flattened_embedding
override int MinTopBlobs
Returns the exact number of required top (output) Blobs: outputs_sum
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 LayerSetUp(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Setup the layer.
VarSetNetLayer(CudaDnn< T > cuda, Log log, LayerParameter p)
The constructor.
override void setup_internal_blobs(BlobCollection< T > col)
Derivative layers should add all internal blobws to the 'col' provided.
override int MaxTopBlobs
Returns the exact number of required top (output) Blobs: outputs_sum, sparse_wts
override void dispose()
Releases all GPU and host resources used by the Layer.
override int MaxBottomBlobs
Returns the min number of required bottom (input) Blobs: flattened_embedding, context
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.
Specifies the base parameter for all layers.
string name
Specifies the name of this LayerParameter.
SoftmaxParameter softmax_param
Returns the parameter set when initialized with LayerType.SOFTMAX
GrnParameter grn_param
Returns the parameter set when initialized with LayerType.GLU
TransposeParameter transpose_param
Returns the parameter set when initialized with LayerType.TRANSPOSE
VarSelNetParameter varselnet_param
Returns the parameter set when initialized with LayerType.VARSELNET
LayerType
Specifies the layer type.
int axis
The axis along which to perform the softmax – may be negative to index from the end (e....
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
The MyCaffe.common namespace contains common MyCaffe classes.
Definition: BatchInput.cs:8
DIR
Defines the direction of data flow.
Definition: CudaDnn.cs:22
BLOB_TYPE
Defines the tpe of data held by a given Blob.
Definition: Interfaces.cs:62
The MyCaffe.layers.tft namespace contains all TFT related layers.
Definition: LayerFactory.cs:15
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-...
Definition: Annotation.cs:12