Ejemplo n.º 1
0
        public override void Forward(SuperArray x)
        {
            base.Forward(x);
            var(n, c, s) = x.GetConv1DShape();

            Parameter weight = BuildParam("w", new Shape(Filters, c, KernalSize), KernalInitializer, KernalConstraint, KernalRegularizer);
            Parameter bias   = null;

            if (UseBias)
            {
                bias = BuildParam("b", new Shape(Filters, 1), BiasInitializer, BiasConstraint, BiasRegularizer);
            }

            int pad = 0;

            if (Padding == PaddingType.Same)
            {
                pad = 1;
            }
            else if (Padding == PaddingType.Full)
            {
                pad = 2;
            }

            KernalSize = (KernalSize - 1) * DilationRate + 1;

            var steps_out = (s - KernalSize + 2 * pad) / Strides + 1;

            xCols = ImUtil.Im2Col(x, Tuple.Create(KernalSize, KernalSize), pad, Strides);
            var wRows = weight.Data.Reshape(Filters, -1);

            Output = Ops.Dot(wRows, xCols);
            if (UseBias)
            {
                Output = Output + bias.Data;
            }

            Output = Output.Reshape(Filters, steps_out, n);
            Output = Output.Transpose(2, 0, 1);
        }
Ejemplo n.º 2
0
        public override void Forward(SuperArray x)
        {
            base.Forward(x);
            var(n, c, s) = x.GetConv1DShape();

            int pad = 0;

            if (Padding == PaddingType.Same)
            {
                pad = 1;
            }
            else if (Padding == PaddingType.Full)
            {
                pad = 2;
            }

            var s_out = (s - PoolSize) / Strides + 1;

            var x_reshaped = x.Reshape(n * c, 1, s);

            xCols  = ImUtil.Im2Col(x_reshaped, Tuple.Create(PoolSize, PoolSize), pad, Strides);
            Output = Ops.Mean(xCols, 0);
            Output = Output.Reshape(s_out, n, c).Transpose(2, 0, 1);
        }