public override void Forward(Variable x) { Input = x; var(n, c, d, h, w) = x.Data.GetConv3DShape(); uint?pad = null; if (Padding == PaddingType.Same) { pad = 1; } else if (Padding == PaddingType.Full) { pad = 2; } var d_out = (d - PoolSize.Item1) / Strides + 1; var h_out = (h - PoolSize.Item2) / Strides + 1; var w_out = (w - PoolSize.Item3) / Strides + 1; var x_reshaped = x.Data.Reshape(n * c, 1, d, h, w); xCols = ImgUtil.Im2Col(x_reshaped, PoolSize, pad, Strides); Output = Argmax(xCols, 0); Output = Output.Reshape(d_out, h_out, w_out, n, c).Transpose(2, 3, 4, 0, 1); }
public override void Forward(Variable x) { //ToDo: Implement DilationRate Input = x; var(n, c, h, w) = x.Data.GetConv2DShape(); Variable weight = BuildVar("w", new long[] { Filters, c, KernalSize.Item1, KernalSize.Item2 }, x.Data.ElementType, KernalInitializer, KernalConstraint, KernalRegularizer); Variable bias = null; if (UseBias) { bias = BuildVar("b", new long[] { Filters, 1 }, x.Data.ElementType, BiasInitializer, BiasConstraint, BiasRegularizer); } uint?pad = null; if (Padding == PaddingType.Same) { pad = 1; } else if (Padding == PaddingType.Full) { pad = 2; } var h_out = (h - KernalSize.Item1 + 2 * pad) / Strides + 1; var w_out = (w - KernalSize.Item2 + 2 * pad) / Strides + 1; var wRows = weight.Data.Reshape(Filters, -1); xCols = ImgUtil.Im2Col(x.Data, KernalSize, pad, Strides); xCols.Print(); wRows.Print(); Output = Dot(wRows, xCols); if (UseBias) { Output = Output + bias.Data; } Output = Output.Reshape(Filters, h_out.Value, w_out.Value, n).Transpose(3, 0, 1, 2); }
public override void Forward(Variable x) { Input = x; var(n, c, s) = x.Data.GetConv1DShape(); uint?pad = null; if (Padding == PaddingType.Same) { pad = 1; } else if (Padding == PaddingType.Full) { pad = 2; } var s_out = (s - PoolSize) / Strides + 1; var x_reshaped = x.Data.Reshape(n * c, 1, s); xCols = ImgUtil.Im2Col(x_reshaped, PoolSize, pad, Strides); Output = Argmax(xCols, 0); Output = Output.Reshape(s_out, n, c).Transpose(2, 0, 1); }
public Tensor Im2Col(Tensor x, Tuple <int, int> kernalSize, int padding = 1, int stride = 1) { return(Out(ImgUtil.Im2Col(In(x), Tuple.Create <uint, uint>((uint)kernalSize.Item1, (uint)kernalSize.Item2), padding, (uint)stride))); }