示例#1
0
        public void ExecuteTest()
        {
            float max_err = 0;

            foreach (int batch in new int[] { 1, 2 })
            {
                foreach (int channels in new int[] { 1, 2, 3, 4, 5, 6, 7, 8 })
                {
                    foreach (int stride in new int[] { 2, 3, 4 })
                    {
                        foreach (int inwidth in new int[] { 5, 7, 11 })
                        {
                            foreach (int inheight in new int[] { 5, 7, 11 })
                            {
                                foreach (int indepth in new int[] { 5, 7, 11 })
                                {
                                    int outwidth = inwidth / stride, outheight = inheight / stride, outdepth = indepth / stride;

                                    float[] yval = (new float[outwidth * outheight * outdepth * channels * batch]).Select((_, idx) => idx * 1e-3f).ToArray();

                                    Map3D y = new Map3D(channels, outwidth, outheight, outdepth, batch, yval);

                                    Map3D x = Reference(y, inwidth, inheight, indepth, stride);

                                    OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map3D(channels, inwidth, inheight, indepth, batch));
                                    OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map3D(channels, outwidth, outheight, outdepth, batch), yval);

                                    AverageUnpooling ope = new AverageUnpooling(inwidth, inheight, indepth, channels, stride, batch);

                                    ope.Execute(y_tensor, x_tensor);

                                    float[] x_expect = x.ToArray();
                                    float[] x_actual = x_tensor.State;

                                    CollectionAssert.AreEqual(yval, y_tensor.State);

                                    AssertError.Tolerance(x_expect, x_actual, 1e-7f, 1e-5f, ref max_err, $"mismatch value {channels},{stride},{inwidth},{inheight},{indepth},{batch}");

                                    Console.WriteLine($"pass: {channels},{stride},{inwidth},{inheight},{indepth},{batch}");
                                }
                            }
                        }
                    }
                }
            }

            Console.WriteLine($"maxerr:{max_err}");
        }
示例#2
0
        public void SpeedTest()
        {
            int outwidth = 512, outheight = 512, channels = 32, stride = 2;
            int inwidth = outwidth / stride, inheight = outheight / stride;

            OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map2D(channels, inwidth, inheight));
            OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map2D(channels, outwidth, outheight));

            AverageUnpooling ope           = new AverageUnpooling(outwidth, outheight, channels, stride);

            Stopwatch sw = new Stopwatch();

            sw.Start();

            ope.Execute(x_tensor, y_tensor);
            ope.Execute(x_tensor, y_tensor);
            ope.Execute(x_tensor, y_tensor);
            ope.Execute(x_tensor, y_tensor);

            sw.Stop();

            Console.WriteLine($"{sw.ElapsedMilliseconds / 4} msec");
        }
示例#3
0
文件: Network.cs 项目: xuan2261/XNet
        public bool CreateLayer(int nCount, ELayerType type, ActivationSettings activationSettings)
        {
            Layer.Utility.Layer layer;
            switch (type)
            {
            case ELayerType.Invalid:
                throw new ArgumentException("Invalid \"type\" argument.");

            case ELayerType.AveragePooling:
                layer = new AveragePooling(nCount, Layers.Count, activationSettings);
                Layers.Add(layer);
                return(true);

            case ELayerType.AverageUnpooling:
                layer = new AverageUnpooling(nCount, Layers.Count, activationSettings);
                Layers.Add(layer);
                return(true);

            case ELayerType.Convolutional:
                layer = new Convolutional(nCount, Layers.Count, activationSettings);
                Layers.Add(layer);
                return(true);

            case ELayerType.Deconvolutional:
                layer = new Deconvolutional(nCount, Layers.Count, activationSettings);
                Layers.Add(layer);
                return(true);

            case ELayerType.Dropout:
                layer = new Dropout(nCount, Layers.Count, activationSettings);
                Layers.Add(layer);
                return(true);

            case ELayerType.FullyConnected:
                layer = new FullyConnected(nCount, Layers.Count, activationSettings);
                Layers.Add(layer);
                return(true);

            case ELayerType.GatedRecurrent:
                layer = new GatedRecurrent(nCount, Layers.Count, activationSettings);
                Layers.Add(layer);
                return(true);

            case ELayerType.LSTM:
                layer = new LSTM(nCount, Layers.Count, activationSettings);
                Layers.Add(layer);
                return(true);

            case ELayerType.MaxPooling:
                layer = new MaxPooling(nCount, Layers.Count, activationSettings);
                Layers.Add(layer);
                return(true);

            case ELayerType.MaxUnpooling:
                layer = new MaxUnpooling(nCount, Layers.Count, activationSettings);
                Layers.Add(layer);
                return(true);

            case ELayerType.Recurrent:
                layer = new Recurrent(nCount, Layers.Count, activationSettings);
                Layers.Add(layer);
                return(true);

            default:
                throw new ArgumentException("Invalid \"type\" argument.");
            }
        }