MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
GaussianFiller.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using MyCaffe.basecode;
6using MyCaffe.param;
7using MyCaffe.common;
8
9namespace MyCaffe.fillers
10{
18 public class GaussianFiller<T> : Filler<T>
19 {
20 SyncedMemory<T> m_randVec = null;
21
29 : base(cuda, log, p)
30 {
31 m_randVec = new SyncedMemory<T>(m_cuda, m_log);
32 }
33
44 public override void Fill(int nCount, long hMem, int nNumAxes = 1, int nNumOutputs = 1, int nNumChannels = 1, int nHeight = 1, int nWidth = 1)
45 {
46 m_log.CHECK(nCount > 0, "There is no data to fill!");
47 m_cuda.rng_gaussian(nCount, m_param.mean, m_param.std, hMem);
48
49 int nSparse = m_param.sparse;
50 m_log.CHECK_GE(nSparse, -1, "The sparse value should be >= -1.");
51
52 if (nSparse >= 0)
53 {
54 // Sparse initialization is implemented for 'weight' blobs; i.e. matrices.
55 // These have num == channels == 1; width is number of inputs; height is
56 // number of outputs. The 'sparse' variable specifies the mean number
57 // of non-zero input weights for a given output.
58 m_log.CHECK_GE(nNumAxes, 1, "The blob must have at least one axis.");
59
60 double dfNonZeroProbability = (double)nSparse / (double)nNumOutputs;
61 T fNonZeroProbability = (T)Convert.ChangeType(dfNonZeroProbability, typeof(T));
62
63 m_randVec.Allocate(nCount);
64 m_cuda.rng_bernoulli(nCount, fNonZeroProbability, m_randVec.gpu_data);
65 m_cuda.mul(nCount, hMem, m_randVec.gpu_data, hMem);
66 }
67 }
68 }
69}
The Log class provides general output in text form.
Definition: Log.cs:13
void CHECK(bool b, string str)
Test a flag for true.
Definition: Log.cs:227
void CHECK_GE(double df1, double df2, string str)
Test whether one number is greater than or equal to another.
Definition: Log.cs:287
The CudaDnn object is the main interface to the Low-Level Cuda C++ DLL.
Definition: CudaDnn.cs:969
The SyncedMemory manages the low-level connection between the GPU and host memory.
Definition: SyncedMemory.cs:18
Abstract Filler class used to fill blobs with values.
Definition: Filler.cs:19
FillerParameter m_param
Specifies the filler parameters.
Definition: Filler.cs:31
CudaDnn< T > m_cuda
Specifies the CudaDnn instance used to communicate to the low-level Cuda Dnn DLL.
Definition: Filler.cs:23
Log m_log
Specifies the output log.
Definition: Filler.cs:27
Fills a Blob with Gaussian-distributed values .
GaussianFiller(CudaDnn< T > cuda, Log log, FillerParameter p)
Constructor.
override void Fill(int nCount, long hMem, int nNumAxes=1, int nNumOutputs=1, int nNumChannels=1, int nHeight=1, int nWidth=1)
Fill the memory with random numbers from a guassian distribution.
Specifies the filler parameters used to create each Filler.
int sparse
Specifies the sparcity value to use with the 'guassian' filler.
double mean
Specifies the mean value to use with the 'gaussian' filler.
double std
Specifies the standard deviation value to use with the 'gaussian' filler.
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
The MyCaffe.fillers namespace contains all fillers including the Filler class.
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