Esempio n. 1
0
 public ConvolutionalNetwork(int matsize, int vecsize, int depth, int labels, params CNNArgs[] args)
 {
     _matsize               = matsize;
     _vecsize               = vecsize;
     _depth                 = depth;
     _labels                = labels;
     _args                  = args;
     InputLayer             = new SpatialLayer(matsize, depth);
     ConvolutionalLayers    = new ConvolutionalLayer[args.Length];
     SubSampleLayers        = new MeanPoolLayer[args.Length];
     ConvolutionalLayers[0] = new ConvolutionalLayer(args[0].FilterSize, args[0].FilterCount, args[0].Stride, InputLayer, Functions.Rectifier2D);
     SubSampleLayers[0]     = new MeanPoolLayer(args[0].PoolLayerSize, ConvolutionalLayers[0]);
     for (int i = 1; i < args.Length; i++)
     {
         ConvolutionalLayers[i] = new ConvolutionalLayer(args[i].FilterSize, args[i].FilterCount, args[i].Stride, SubSampleLayers[i - 1], Functions.Rectifier2D);
         SubSampleLayers[i]     = new MeanPoolLayer(args[i].PoolLayerSize, ConvolutionalLayers[i]);
     }
     FlattenLayer      = new FlattenLayer(SubSampleLayers[SubSampleLayers.Length - 1]);
     VectorInput       = new InputLayer(vecsize);
     LinearHiddenLayer = new DenseLayer(vecsize, VectorInput, Functions.Sigmoid);
     CombinationLayer  = new TreeLayer(FlattenLayer.Size(), vecsize);
     OutputLayer       = new DenseLayer(labels, CombinationLayer, Functions.Identity);
 }
Esempio n. 2
0
        public ConvolutionalLayerBackprop(ConvolutionalLayer unit)
        {
            int fsize = unit.Weights[0][0].RowCount;

            _unit     = unit;
            _outgoing = new Matrix <float> [unit.Prev.ChannelCount];
            for (int i = 0; i < _outgoing.Length; i++)
            {
                _outgoing[i] = Matrix <float> .Build.Dense(unit.Prev.SideLength, unit.Prev.SideLength);
            }
            _padded = new Matrix <float> [unit.Prev.ChannelCount];
            for (int i = 0; i < _padded.Length; i++)
            {
                _padded[i] = Matrix <float> .Build.Dense(unit.Prev.SideLength + fsize - 1, unit.Prev.SideLength + fsize - 1);
            }
            _input = new Matrix <float> [unit.Prev.ChannelCount];
            for (int i = 0; i < _input.Length; i++)
            {
                _input[i] = Matrix <float> .Build.Dense(unit.Prev.SideLength + fsize - 1, unit.Prev.SideLength + fsize - 1);
            }
            _ebuf = Matrix <float> .Build.Dense(unit.SideLength, unit.SideLength);

            _fbuf = Matrix <float> .Build.Dense(fsize, fsize);

            _subm = Matrix <float> .Build.Dense(fsize, fsize);

            _deltas = new Matrix <float> [unit.Prev.ChannelCount][];
            for (int i = 0; i < _deltas.Length; i++)
            {
                _deltas[i] = new Matrix <float> [unit.ChannelCount];
                for (int j = 0; j < unit.ChannelCount; j++)
                {
                    _deltas[i][j] = Matrix <float> .Build.Dense(fsize, fsize);
                }
            }
        }