Esempio n. 1
0
        public static Tensor Deconv2D(Tensor input, Tensor filter, Tensor bias)
        {
            var channels = filter.Shape[3];
            var kernel   = "TransConv2D_" + (channels == 3 ? "final" : channels.ToString());

            return(GpuHelper.InvokeConvolutionKernel(GpuHelper.ConvolutionMode.Up, kernel, input, filter, bias));
        }
Esempio n. 2
0
        public static Tensor Conv2D(Tensor input, Tensor filter, Tensor bias)
        {
            var outChannels = filter.Shape[3];
            var kernel      = outChannels >= 512 ? "Conv2D_512_1" : "Conv2D_64_8";

            return(GpuHelper.InvokeConvolutionKernel(GpuHelper.ConvolutionMode.Down, kernel, input, filter, bias));
        }
Esempio n. 3
0
        public static Tensor Deconv2D(Tensor input, Tensor filter, Tensor bias)
        {
#if ENABLE_COMPUTE
            var outChannels = filter.Shape[2];
            var kernel      = outChannels >= 512 ? "Deconv2D_512_1_1" : "Deconv2D_64_16_1";
            if (outChannels == 3)
            {
                kernel = "Deconv2D_3_256_1";
            }
            return(GpuHelper.InvokeConvolutionKernel(GpuHelper.ConvolutionMode.Backward, kernel, input, filter, bias));
#else
            var inHeight   = input.Shape[0];
            var inWidth    = input.Shape[1];
            var inChannels = input.Shape[2];

            var outHeight   = inHeight * 2;
            var outWidth    = inWidth * 2;
            var outChannels = filter.Shape[2];

            var filterHeight = filter.Shape[0];
            var filterWidth  = filter.Shape[1];

            var output = new Tensor(new [] { outHeight, outWidth, outChannels });

            for (var oc = 0; oc < outChannels; oc++)
            {
                for (var oy = 0; oy < outHeight; oy++)
                {
                    var ymin = (oy - 1) / 2;

                    for (var ox = 0; ox < outWidth; ox++)
                    {
                        var xmin = (ox - 1) / 2;
                        var prod = 0.0f;

                        for (var fy = oy % 2; fy < filterHeight; fy += 2)
                        {
                            for (var fx = ox % 2; fx < filterWidth; fx += 2)
                            {
                                for (var ic = 0; ic < inChannels; ic++)
                                {
                                    var pixel  = input.Get(ymin + fy / 2, xmin + fx / 2, ic);
                                    var weight = filter.Get(
                                        filterHeight - 1 - fy,
                                        filterWidth - 1 - fx,
                                        oc, ic
                                        );
                                    prod += pixel * weight;
                                }
                            }
                        }

                        output.Set(oy, ox, oc, prod + bias.Get(oc));
                    }
                }
            }

            return(output);
#endif
        }
Esempio n. 4
0
        public static Tensor Deconv2D(Tensor input, Tensor filter, Tensor bias)
        {
            var outChannels = filter.Shape[2];
            var kernel      = outChannels >= 512 ? "TransConv2D_512_1" : "TransConv2D_64_8";

            if (outChannels == 3)
            {
                kernel = "TransConv2D_3_128";
            }
            return(GpuHelper.InvokeConvolutionKernel(GpuHelper.ConvolutionMode.Up, kernel, input, filter, bias));
        }
Esempio n. 5
0
        public static Tensor Conv2D(Tensor input, Tensor filter, Tensor bias)
        {
#if ENABLE_COMPUTE
            var outChannels = filter.Shape[3];
            var kernel      = outChannels >= 512 ? "Conv2D_512_1_1" : "Conv2D_64_16_1";
            return(GpuHelper.InvokeConvolutionKernel(GpuHelper.ConvolutionMode.Forward, kernel, input, filter, bias));
#else
            var inHeight   = input.Shape[0];
            var inWidth    = input.Shape[1];
            var inChannels = input.Shape[2];

            var outHeight   = inHeight / 2;
            var outWidth    = inWidth / 2;
            var outChannels = filter.Shape[3];

            var filterHeight = filter.Shape[0];
            var filterWidth  = filter.Shape[1];

            var output = new Tensor(new [] { outHeight, outWidth, outChannels });

            for (var oc = 0; oc < outChannels; oc++)
            {
                for (var oy = 0; oy < outHeight; oy++)
                {
                    var ymin = oy * 2 - filterHeight / 2 + 1;

                    for (var ox = 0; ox < outWidth; ox++)
                    {
                        var xmin = ox * 2 - filterWidth / 2 + 1;
                        var prod = 0.0f;

                        for (var fy = 0; fy < filterHeight; fy++)
                        {
                            for (var fx = 0; fx < filterWidth; fx++)
                            {
                                for (var ic = 0; ic < inChannels; ic++)
                                {
                                    var pixel  = input.Get(ymin + fy, xmin + fx, ic);
                                    var weight = filter.Get(fy, fx, ic, oc);
                                    prod += pixel * weight;
                                }
                            }
                        }

                        output.Set(oy, ox, oc, prod + bias.Get(oc));
                    }
                }
            }

            return(output);
#endif
        }
Esempio n. 6
0
        public static Tensor Deconv2D(Tensor input, Tensor filter, Tensor bias)
        {
            var kernel = "TransConv2D_" + filter.Shape[2];

            return(GpuHelper.InvokeConvolutionKernel(GpuHelper.ConvolutionMode.Up, kernel, input, filter, bias));
        }
Esempio n. 7
0
        public static Tensor Conv2D(Tensor input, Tensor filter, Tensor bias)
        {
            var kernel = "Conv2D_" + filter.Shape[3];

            return(GpuHelper.InvokeConvolutionKernel(GpuHelper.ConvolutionMode.Down, kernel, input, filter, bias));
        }