예제 #1
0
        public override void CalculateGradients(Tensor nextLayerGradients)
        {
            for (int x = 0; x < In.Size.X; x++)
            {
                for (int y = 0; y < In.Size.Y; y++)
                {
                    Range range = MapToOutput(x, y);
                    for (int z = 0; z < In.Size.Z; z++)
                    {
                        float sum_error = 0;
                        for (int i = range.MinX; i <= range.MaxX; i++)
                        {
                            int minx = i * Stride;
                            for (int j = range.MinY; j <= range.MaxY; j++)
                            {
                                int miny = j * Stride;

                                int is_max = (In.Get(x, y, z) == Out.Get(i, j, z)) ? 1 : 0;
                                sum_error += is_max * nextLayerGradients.Get(i, j, z);
                            }
                        }
                        GradsIn.Set(x, y, z, sum_error);
                    }
                }
            }
        }