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); }
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.Conv2D9x9(Temp, this.Data.Conv1_Weights, this.Data.Conv1_Biases); if (this.Step != null) { Step(5); } Temp = Layers.ReLU(Temp); if (this.Step != null) { Step(10); } Temp = Layers.BatchNorm( Temp, this.Data.Conv1_Shift, this.Data.Conv1_Scale, this.Data.Conv1_Mean, this.Data.Conv1_Var); if (this.Step != null) { Step(15); } Temp = Layers.ResidualBlock( Temp, this.Data.Res1_Conv1_Weights, this.Data.Res1_Conv2_Weights, this.Data.Res1_Conv1_Biases, this.Data.Res1_Conv2_Biases, this.Data.Res1_Conv1_Shift, this.Data.Res1_Conv2_Shift, this.Data.Res1_Conv1_Scale, this.Data.Res1_Conv2_Scale, this.Data.Res1_Conv1_Mean, this.Data.Res1_Conv2_Mean, this.Data.Res1_Conv1_Var, this.Data.Res1_Conv2_Var); if (this.Step != null) { Step(20); } Temp = Layers.ResidualBlock( Temp, this.Data.Res2_Conv1_Weights, this.Data.Res2_Conv2_Weights, this.Data.Res2_Conv1_Biases, this.Data.Res2_Conv2_Biases, this.Data.Res2_Conv1_Shift, this.Data.Res2_Conv2_Shift, this.Data.Res2_Conv1_Scale, this.Data.Res2_Conv2_Scale, this.Data.Res2_Conv1_Mean, this.Data.Res2_Conv2_Mean, this.Data.Res2_Conv1_Var, this.Data.Res2_Conv2_Var); if (this.Step != null) { Step(25); } Temp = Layers.ResidualBlock( Temp, this.Data.Res3_Conv1_Weights, this.Data.Res3_Conv2_Weights, this.Data.Res3_Conv1_Biases, this.Data.Res3_Conv2_Biases, this.Data.Res3_Conv1_Shift, this.Data.Res3_Conv2_Shift, this.Data.Res3_Conv1_Scale, this.Data.Res3_Conv2_Scale, this.Data.Res3_Conv1_Mean, this.Data.Res3_Conv2_Mean, this.Data.Res3_Conv1_Var, this.Data.Res3_Conv2_Var); if (this.Step != null) { Step(30); } Temp = Layers.ResidualBlock( Temp, this.Data.Res4_Conv1_Weights, this.Data.Res4_Conv2_Weights, this.Data.Res4_Conv1_Biases, this.Data.Res4_Conv2_Biases, this.Data.Res4_Conv1_Shift, this.Data.Res4_Conv2_Shift, this.Data.Res4_Conv1_Scale, this.Data.Res4_Conv2_Scale, this.Data.Res4_Conv1_Mean, this.Data.Res4_Conv2_Mean, this.Data.Res4_Conv1_Var, this.Data.Res4_Conv2_Var); if (this.Step != null) { Step(35); } Temp = Layers.ResidualBlock( Temp, this.Data.Res5_Conv1_Weights, this.Data.Res5_Conv2_Weights, this.Data.Res5_Conv1_Biases, this.Data.Res5_Conv2_Biases, this.Data.Res5_Conv1_Shift, this.Data.Res5_Conv2_Shift, this.Data.Res5_Conv1_Scale, this.Data.Res5_Conv2_Scale, this.Data.Res5_Conv1_Mean, this.Data.Res5_Conv2_Mean, this.Data.Res5_Conv1_Var, this.Data.Res5_Conv2_Var); if (this.Step != null) { Step(40); } Temp = Layers.ResidualBlock( Temp, this.Data.Res6_Conv1_Weights, this.Data.Res6_Conv2_Weights, this.Data.Res6_Conv1_Biases, this.Data.Res6_Conv2_Biases, this.Data.Res6_Conv1_Shift, this.Data.Res6_Conv2_Shift, this.Data.Res6_Conv1_Scale, this.Data.Res6_Conv2_Scale, this.Data.Res6_Conv1_Mean, this.Data.Res6_Conv2_Mean, this.Data.Res6_Conv1_Var, this.Data.Res6_Conv2_Var); if (this.Step != null) { Step(45); } Temp = Layers.Conv2DTranspose3x3(Temp, this.Data.Deconv1_Weights, this.Data.Deconv1_Biases); if (this.Step != null) { Step(50); } Temp = Layers.ReLU(Temp); if (this.Step != null) { Step(55); } Temp = Layers.BatchNorm(Temp, this.Data.Deconv1_Shift, this.Data.Deconv1_Scale, this.Data.Deconv1_Mean, this.Data.Deconv1_Var); if (this.Step != null) { Step(60); } Temp = Layers.Conv2DTranspose3x3(Temp, this.Data.Deconv2_Weights, this.Data.Deconv2_Biases); if (this.Step != null) { Step(65); } Temp = Layers.ReLU(Temp); if (this.Step != null) { Step(70); } Temp = Layers.BatchNorm(Temp, this.Data.Deconv2_Shift, this.Data.Deconv2_Scale, this.Data.Deconv2_Mean, this.Data.Deconv2_Var); if (this.Step != null) { Step(75); } Temp = Layers.Conv2DTranspose9x9(Temp, this.Data.Deconv3_Weights, this.Data.Deconv3_Biases); if (this.Step != null) { Step(80); } Temp = Layers.ReLU(Temp); if (this.Step != null) { Step(85); } Temp = Layers.BatchNorm(Temp, this.Data.Deconv3_Shift, this.Data.Deconv3_Scale, this.Data.Deconv3_Mean, this.Data.Deconv3_Var); if (this.Step != null) { Step(90); } Temp = Layers.Tanh(Temp); if (this.Step != null) { Step(95); } return(Temp); }