示例#1
0
        //TODO: implement feature map -> max pool simaltaneously
        protected override void ForwardPropagateInputLayer(int completedBatch)
        {
            FeatureMap featureMap = null;
            MaxPool    maxPool    = null;

            for (int feature = 0; feature < Props.NumberFeatures; feature++)
            {
                featureMap = FeatureMaps[feature];
                int outputPoolOffset = feature * Props.PoolSize;

                for (int featureRow = 0; featureRow < Props.FeatureRows; featureRow++)
                {
                    for (int featureCol = 0; featureCol < Props.FeatureCols; featureCol++)
                    {
                        featureMap.Features[featureRow][featureCol] = featureMap.Weights[featureMap.Weights.Length - 1];
                        int weightIndex = 0;
                        for (int y = 0; y < Props.NeighborhoodRows; y++)
                        {
                            for (int x = 0; x < Props.NeighborhoodCols; x++, weightIndex++)
                            {
                                featureMap.Features[featureRow][featureCol] +=
                                    InputSegment[y + featureRow][x + featureCol] * featureMap.Weights[weightIndex];
                            }
                        }
                    }
                }

                maxPool = MaxPools[feature];
                MaxPoolIndexPair pair = new MaxPoolIndexPair();
                float            max;
                int poolIndex = outputPoolOffset;
                for (int poolRow = 0; poolRow < Props.PoolRows; poolRow++)
                {
                    int featureRow = poolRow * Props.PoolSamplingRows;
                    for (int poolCol = 0; poolCol < Props.PoolCols; poolCol++, poolIndex++)
                    {
                        int featureCol = poolCol * Props.PoolSamplingCols;
                        max = featureMap.Features[featureRow][featureCol];
                        for (int y = 0; y < Props.PoolSamplingRows; y++)
                        {
                            for (int x = 0; x < Props.PoolSamplingCols; x++)
                            {
                                if (featureMap.Features[featureRow + y][featureCol + x] > max)
                                {
                                    max      = featureMap.Features[featureRow + y][featureCol + x];
                                    pair.col = x; pair.row = y;
                                }
                            }
                        }

                        maxPool.Pool[poolRow][poolCol]       = max;
                        maxPool.IndexPairs[poolRow][poolCol] = pair;

                        Perceptrons[poolIndex].Outputs[completedBatch] = max;
                    }
                }
            }
        }
示例#2
0
 public MaxPool(MaxPoolProps props)
 {
     Pool       = new float[props.PoolRows][];
     IndexPairs = new MaxPoolIndexPair[props.PoolRows][];
     for (int i = 0; i < IndexPairs.Length; i++)
     {
         Pool[i]       = new float[props.PoolCols];
         IndexPairs[i] = new MaxPoolIndexPair[props.PoolCols];
         for (int j = 0; j < IndexPairs[i].Length; j++)
         {
             IndexPairs[i][j] = new MaxPoolIndexPair();
         }
     }
 }