/// <summary> /// /// </summary> /// <param name="inputWidth"></param> /// <param name="inputHeight"></param> /// <param name="inputDepth"></param> /// <param name="batchSize"></param> /// <param name="initializtion"></param> /// <param name="random"></param> public void Initialize(int inputWidth, int inputHeight, int inputDepth, int batchSize, Initialization initializtion, Random random) { var fans = WeightInitialization.GetFans(this, inputWidth, inputHeight, inputDepth); var distribution = WeightInitialization.GetWeightDistribution(initializtion, fans, random); Weights = Matrix <float> .Build.Random(fans.FanIn, fans.FanOut, distribution); Bias = Vector <float> .Build.Dense(fans.FanOut, 0.0f); WeightsGradients = Matrix <float> .Build.Dense(fans.FanIn, fans.FanOut); BiasGradients = Vector <float> .Build.Dense(fans.FanOut); OutputActivations = Matrix <float> .Build.Dense(batchSize, fans.FanOut); m_delta = Matrix <float> .Build.Dense(batchSize, fans.FanIn); }
/// <summary> /// /// </summary> /// <param name="inputWidth"></param> /// <param name="inputHeight"></param> /// <param name="inputDepth"></param> /// <param name="batchSize"></param> /// <param name="initializtion"></param> /// <param name="random"></param> public void Initialize(int inputWidth, int inputHeight, int inputDepth, int batchSize, Initialization initializtion, Random random) { InputHeight = inputHeight; InputWidth = inputWidth; InputDepth = inputDepth; var filterGridWidth = ConvUtils.GetFilterGridLength(InputWidth, FilterWidth, m_stride, m_padWidth, BorderMode); var filterGridHeight = ConvUtils.GetFilterGridLength(InputHeight, FilterHeight, m_stride, m_padHeight, BorderMode); // Calculations of dimensions based on: // Nvidia, cuDNN: Efficient Primitives for Deep Learning: https://arxiv.org/pdf/1410.0759.pdf var filterCubeSize = InputDepth * FilterWidth * FilterHeight; var filterGridSize = filterGridWidth * filterGridHeight; Height = filterGridHeight; Width = filterGridWidth; Depth = FilterCount; var fans = WeightInitialization.GetFans(this, InputWidth, InputHeight, inputDepth); var distribution = WeightInitialization.GetWeightDistribution(initializtion, fans, random); Weights = Matrix <float> .Build.Random(FilterCount, filterCubeSize, distribution); WeightsGradients = Matrix <float> .Build.Dense(FilterCount, filterCubeSize); Bias = Vector <float> .Build.Dense(FilterCount, 0.0f); BiasGradients = Vector <float> .Build.Dense(FilterCount); Im2Cols = Matrix <float> .Build.Dense(filterCubeSize, filterGridSize *batchSize); Conv = Matrix <float> .Build.Dense(FilterCount, filterGridSize *batchSize); OutputActivations = Matrix <float> .Build.Dense(batchSize, FilterCount *filterGridSize); m_deltaInReshape = Matrix <float> .Build.Dense(FilterCount, filterGridSize *batchSize); var fanIn = inputWidth * inputHeight * inputDepth; m_delta = Matrix <float> .Build.Dense(batchSize, fanIn); }