Example #1
0
        public static Tensor ResidualBlock(Tensor input, ResidualBlockData Data)
        {
            var n = Layers.Conv2D3x3(input, Data.Conv1_Weights, new Tensor(1, 1, 64));

            n = Layers.BatchNorm(n, Data.Conv1_Mean, Data.Conv1_Variance, Data.Conv1_Shift, Data.Conv1_Scale);
            n = Layers.ReLU(n);
            n = Layers.Conv2D3x3(n, Data.Conv2_Weights, new Tensor(1, 1, 64));
            n = Layers.BatchNorm(n, Data.Conv2_Mean, Data.Conv2_Variance, Data.Conv2_Shift, Data.Conv2_Scale);
            Parallel.For(0, 64, (int d) =>
            {
                for (int y = 0; y < input.Height; y++)
                {
                    for (int x = 0; x < input.Width; x++)
                    {
                        n.Set(x, y, d, n.Get(x, y, d) + input.Get(x, y, d));
                    }
                }
            });
            return(n);
        }
Example #2
0
        public Tensor Enhance(Tensor input)
        {
            var n = Layers.Conv2D3x3(input, Data.Conv1_Weights, Data.Conv1_Biases);

            n = Layers.ReLU(n);
            if (this.Step != null)
            {
                Step(2);
            }
            var temp = n;

            n = Layers.ResidualBlock(n, Data.Residual1);
            if (this.Step != null)
            {
                Step(7);
            }
            n = Layers.ResidualBlock(n, Data.Residual2);
            if (this.Step != null)
            {
                Step(12);
            }
            n = Layers.ResidualBlock(n, Data.Residual3);
            if (this.Step != null)
            {
                Step(17);
            }
            n = Layers.ResidualBlock(n, Data.Residual4);
            if (this.Step != null)
            {
                Step(22);
            }
            n = Layers.ResidualBlock(n, Data.Residual5);
            if (this.Step != null)
            {
                Step(27);
            }
            n = Layers.ResidualBlock(n, Data.Residual6);
            if (this.Step != null)
            {
                Step(32);
            }
            n = Layers.ResidualBlock(n, Data.Residual7);
            if (this.Step != null)
            {
                Step(37);
            }
            n = Layers.ResidualBlock(n, Data.Residual8);
            if (this.Step != null)
            {
                Step(42);
            }
            n = Layers.ResidualBlock(n, Data.Residual9);
            if (this.Step != null)
            {
                Step(47);
            }
            n = Layers.ResidualBlock(n, Data.Residual10);
            if (this.Step != null)
            {
                Step(52);
            }
            n = Layers.ResidualBlock(n, Data.Residual11);
            if (this.Step != null)
            {
                Step(57);
            }
            n = Layers.ResidualBlock(n, Data.Residual12);
            if (this.Step != null)
            {
                Step(62);
            }
            n = Layers.ResidualBlock(n, Data.Residual13);
            if (this.Step != null)
            {
                Step(67);
            }
            n = Layers.ResidualBlock(n, Data.Residual14);
            if (this.Step != null)
            {
                Step(72);
            }
            n = Layers.ResidualBlock(n, Data.Residual15);
            if (this.Step != null)
            {
                Step(77);
            }
            n = Layers.ResidualBlock(n, Data.Residual16);
            if (this.Step != null)
            {
                Step(82);
            }
            n = Layers.Conv2D3x3(n, Data.Conv2_Weights, new Tensor(1, 1, 64));
            n = Layers.BatchNorm(n, Data.Conv2_Mean, Data.Conv2_Variance, Data.Conv2_Shift, Data.Conv2_Scale);
            n = Layers.Elementwise(n, temp);
            if (this.Step != null)
            {
                Step(87);
            }
            n = Layers.Conv2D3x3(n, Data.Conv3_Weights, Data.Conv3_Biases);
            n = Layers.SubpixelConv2D(n);
            n = Layers.ReLU(n);
            if (this.Step != null)
            {
                Step(92);
            }
            n = Layers.Conv2D3x3(n, Data.Conv4_Weights, Data.Conv4_Biases);
            n = Layers.SubpixelConv2D(n);
            n = Layers.ReLU(n);
            if (this.Step != null)
            {
                Step(97);
            }
            n = Layers.Conv2D1x1(n, Data.Conv5_Weights, Data.Conv5_Biases);
            n = Layers.Tanh(n);
            if (this.Step != null)
            {
                Step(100);
            }
            return(n);
        }
        public Tensor Enhance(Tensor input)
        {
            var Temp = input;

            Temp = Layers.Conv2D3x3(Temp, this.Data.Conv1_Weights, this.Data.Conv1_Biases);
            if (this.Step != null)
            {
                Step(7);
            }
            Temp = Layers.LeakyReLU(Temp);
            if (this.Step != null)
            {
                Step(14);
            }
            Temp = Layers.Conv2D3x3(Temp, this.Data.Conv2_Weights, this.Data.Conv2_Biases);
            if (this.Step != null)
            {
                Step(21);
            }
            Temp = Layers.LeakyReLU(Temp);
            if (this.Step != null)
            {
                Step(28);
            }
            Temp = Layers.Conv2D3x3(Temp, this.Data.Conv3_Weights, this.Data.Conv3_Biases);
            if (this.Step != null)
            {
                Step(35);
            }
            Temp = Layers.LeakyReLU(Temp);
            if (this.Step != null)
            {
                Step(42);
            }
            Temp = Layers.Conv2D3x3(Temp, this.Data.Conv4_Weights, this.Data.Conv4_Biases);
            if (this.Step != null)
            {
                Step(49);
            }
            Temp = Layers.LeakyReLU(Temp);
            if (this.Step != null)
            {
                Step(56);
            }
            Temp = Layers.Conv2D3x3(Temp, this.Data.Conv5_Weights, this.Data.Conv5_Biases);
            if (this.Step != null)
            {
                Step(63);
            }
            Temp = Layers.LeakyReLU(Temp);
            if (this.Step != null)
            {
                Step(70);
            }
            Temp = Layers.Conv2D3x3(Temp, this.Data.Conv6_Weights, this.Data.Conv6_Biases);
            if (this.Step != null)
            {
                Step(77);
            }
            Temp = Layers.LeakyReLU(Temp);
            if (this.Step != null)
            {
                Step(84);
            }
            Temp = Layers.Conv2D3x3(Temp, this.Data.Conv7_Weights, this.Data.Conv7_Biases);
            if (this.Step != null)
            {
                Step(91);
            }
            Temp = Layers.LeakyReLU(Temp);
            if (this.Step != null)
            {
                Step(98);
            }
            return(Temp);
        }