예제 #1
0
        public void Conv2DLayer_MultipleBackwardsPasses()
        {
            var fanIn     = 3 * 3 * 3;
            var fanOut    = 2 * 2 * 2;
            var batchSize = 10;
            var random    = new Random(232);

            var sut = new Conv2DLayer(2, 2, 2);

            sut.Initialize(3, 3, 3, batchSize, Initialization.GlorotUniform, random);

            var input = Matrix <float> .Build.Random(batchSize, fanIn, random.Next());

            sut.Forward(input);

            var delta = Matrix <float> .Build.Dense(batchSize, fanOut, 1.0f);

            var expected = Matrix <float> .Build.Dense(batchSize, fanIn);

            sut.Backward(delta).CopyTo(expected);

            for (int i = 0; i < 20; i++)
            {
                var actual = sut.Backward(delta);
                Assert.AreEqual(expected, actual);
            }
        }
예제 #2
0
        public void Conv2DLayer_Backward()
        {
            var fanIn     = 3 * 3 * 3;
            var batchSize = 10;
            var random    = new Random(232);

            var sut = new Conv2DLayer(2, 2, 2);

            sut.Initialize(3, 3, 3, batchSize, Initialization.GlorotUniform, random);

            var input = Matrix <float> .Build.Random(batchSize, fanIn, random.Next());

            sut.Forward(input);

            var delta = Matrix <float> .Build.Random(batchSize, 8, random.Next());

            var actual = sut.Backward(delta);

            Trace.WriteLine(string.Join(", ", actual.ToColumnMajorArray()));

            var expected = Matrix <float> .Build.Dense(batchSize, 27, new float[] { -0.3012112f, -0.431109f, 0.3067777f, 1.202193f, -0.2970281f, -0.04250076f, 0.2061959f, 0.7989445f, -0.5996055f, 0.2316911f, 0.8747584f, 0.51476f, 0.7046955f, 0.7860816f, 0.8916292f, 0.3832603f, -0.8700395f, -0.5354695f, -0.3685025f, -0.1342522f, 0.1518587f, 0.2221017f, 0.1806079f, 0.07497367f, 0.3097255f, 0.1634672f, -0.4491678f, -0.17365f, -0.144638f, 0.004295252f, -0.3601557f, -1.119732f, -0.1934451f, -0.2176901f, 0.2700419f, 0.089331f, 0.1821172f, 0.883155f, -0.849492f, -0.1244191f, -0.2039348f, -0.1751226f, -0.06979793f, -1.079664f, -0.03928173f, 0.218465f, 1.629254f, -0.4939195f, 0.2245779f, -0.7562671f, -0.8274944f, -0.5467064f, -0.3680224f, -0.1386559f, -1.087083f, -0.2628459f, 1.822653f, 0.701782f, 0.4428222f, -0.1040708f, -0.7712241f, -0.3224123f, -0.01733552f, 0.86768f, 0.3000976f, -0.3464163f, 0.4350502f, 0.2027335f, 0.117341f, 0.1954426f, -0.5851873f, -0.05708569f, -0.4324316f, 0.2123868f, -0.002792224f, -0.9684533f, -0.6718895f, -0.7736996f, 0.03639168f, 0.6314194f, 0.8996651f, -0.3380031f, -0.5858002f, -0.3516838f, 0.3391975f, -0.6496764f, -1.470267f, -0.3591874f, -0.00506255f, 0.3587183f, -0.3065151f, -0.3236075f, -0.3906966f, -0.09693986f, 0.009184331f, -0.259648f, 0.4111665f, 0.6034111f, -0.1156556f, 0.2007988f, 0.6419388f, 0.08893928f, -0.5510148f, -1.088815f, 0.1288811f, -0.3150855f, 0.8156078f, -0.6915295f, 0.9525194f, -0.3977204f, -0.8499367f, -0.6417554f, -0.5841292f, -0.4173682f, -1.056341f, -0.4105635f, 1.05644f, 0.6464114f, 0.3108801f, 0.1191875f, -1.091015f, -0.6754146f, -0.09798362f, 1.521804f, 0.0538983f, -0.5595286f, 0.8281931f, 1.05391f, -0.2553593f, 0.5020249f, 0.5202242f, 0.2157923f, -0.4918408f, 0.170707f, 0.4082467f, -1.021097f, -0.533677f, -0.9184983f, 0.2424989f, 0.4848338f, 1.166928f, -0.3471279f, -0.6809464f, -0.09819638f, 0.1225361f, -0.7392287f, -0.520788f, 0.02109938f, 0.4813665f, 0.2430263f, -0.4380659f, -0.5662301f, 0.09159709f, 0.3489724f, 0.3382439f, 0.003150672f, 0.09243999f, 0.1749734f, -0.2740337f, -0.09017494f, -0.9974357f, -0.339394f, 0.07069169f, 0.1736448f, 0.01214228f, -0.2352773f, 0.009375662f, -0.4198866f, -0.4020877f, 0.1003972f, 0.1117148f, -0.2725339f, -0.1976277f, -0.2717598f, 0.1088151f, -0.272986f, -0.7224701f, -0.3619833f, -0.2441979f, 0.1247422f, 0.02018096f, 0.09719498f, -0.4377319f, -0.8641849f, 0.2047512f, -0.1255917f, 0.1056862f, -0.1779335f, 0.3336785f, -0.03628005f, -0.7774371f, -1.062242f, -0.5129448f, 0.5529103f, -0.9545653f, -0.615674f, 1.543631f, 1.37671f, -0.1174148f, 0.2789351f, 0.8581713f, 0.1639292f, 0.2462995f, 0.4195996f, 0.5214866f, 0.008561775f, 0.1065625f, -0.3906671f, 0.08749793f, -0.2356352f, -0.6500566f, 0.1207049f, -0.4108496f, 0.6503633f, -0.06599725f, -0.6515968f, 0.745948f, 0.4625394f, 0.4467969f, 0.5328804f, 0.1164707f, -1.545646f, -0.7757972f, 0.4053627f, 0.4717687f, -1.017592f, -0.0884065f, 0.6148586f, -0.3979636f, 0.3205289f, -0.06230295f, -0.4828503f, 0.1028745f, -0.02724302f, -0.008226641f, -0.2221806f, 0.4184201f, -0.675901f, -0.3388602f, -0.2884192f, -0.483782f, -0.1539764f, -0.02365633f, 0.562417f, 0.1671077f, -0.2424937f, 0.2923921f, 0.1196359f, 0.1165333f, 0.1479492f, -0.6982891f, -0.7252806f, -0.1735715f, 0.3851384f, 0.4009265f, -0.5441284f, -0.460577f, -0.2921039f, -0.3540158f, 0.242506f, -0.2498714f, -0.4901754f, -0.1536585f, -0.4801114f, 0.07474235f, -0.3067195f, -0.9593061f, -0.7042174f, -0.615593f, 0.1035262f });

            MatrixAsserts.AreEqual(expected, actual);
        }