Exemple #1
0
        public void SpeedTest()
        {
            int inwidth = 64, inheight = 64, indepth = 64, inchannels = 32, scale = 2;
            int outwidth = inwidth / scale, outheight = inheight / scale, outdepth = indepth / scale, outchannels = inchannels * (scale * scale * scale);

            OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map3D(inchannels, inwidth, inheight, indepth));
            OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map3D(outchannels, outwidth, outheight, outdepth));

            SpaceToChannel ope             = new SpaceToChannel(inwidth, inheight, indepth, inchannels, scale);

            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");
        }
Exemple #2
0
        public void ExecuteTest()
        {
            float max_err = 0;

            foreach (int batch in new int[] { 1, 2 })
            {
                foreach (int inchannels in new int[] { 3, 5 })
                {
                    foreach (int scale in new int[] { 2, 3, 4 })
                    {
                        foreach (int outwidth in new int[] { 5, 7, 11 })
                        {
                            foreach (int outheight in new int[] { 5, 7, 11 })
                            {
                                foreach (int outdepth in new int[] { 5, 7, 11 })
                                {
                                    int inwidth = outwidth * scale, inheight = outheight * scale, indepth = outdepth * scale, outchannels = inchannels * scale * scale * scale;

                                    float[] xval = (new float[inwidth * inheight * indepth * inchannels * batch]).Select((_, idx) => idx * 1e-3f).ToArray();

                                    Map3D x = new Map3D(inchannels, inwidth, inheight, indepth, batch, xval);

                                    Map3D y = Reference(x, scale);

                                    OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map3D(inchannels, inwidth, inheight, indepth, batch), xval);
                                    OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map3D(outchannels, outwidth, outheight, outdepth, batch));

                                    SpaceToChannel ope = new SpaceToChannel(inwidth, inheight, indepth, inchannels, scale, batch);

                                    ope.Execute(x_tensor, y_tensor);

                                    float[] y_expect = y.ToArray();
                                    float[] y_actual = y_tensor.State;

                                    CollectionAssert.AreEqual(xval, x_tensor.State);

                                    AssertError.Tolerance(y_expect, y_actual, 1e-7f, 1e-5f, ref max_err, $"mismatch value {inchannels},{outchannels},{scale},{inwidth},{inheight},{indepth},{batch}");

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

            Console.WriteLine($"maxerr:{max_err}");
        }