Example #1
0
        public double[] GetDenseWeights(double[] weights)
        {
            if (!prepared)
            {
                Prepare();
            }
            int             rows       = maps * Corners.Length;
            int             columns    = InputShape.Aggregate(1, (acc, val) => acc * val);
            int             kernelSize = KernelShape.Aggregate(1, (acc, val) => acc * val);
            Matrix <double> mat        = Matrix <double> .Build.Dense(rows, columns);

            for (int m = 0; m < maps; m++)
            {
                for (int i = 0; i < Corners.Length; i++)
                {
                    var c = Corners[i];
                    foreach (var o in Offsets)
                    {
                        var l = Location(c, o, InputShape);
                        if (l < 0)
                        {
                            continue;
                        }
                        var k = Location(null, o, KernelShape);
                        mat[m * Corners.Length + i, l] = weights[k + m * kernelSize];
                    }
                }
            }
            return(mat.ToRowMajorArray());
        }
Example #2
0
        public override void Prepare()
        {
            if (!layerPrepared)
            {
                convolutionEngine.Prepare();
                kernelSize = KernelShape.Aggregate(1, (acc, val) => acc * val);
                if (Bias == null)
                {
                    kernelSize++;
                }
                if (Weights == null)
                {
                    return;
                }
                PrepareWeightsWindows();
                double BiasScale = GetOutputScale();
                int    maps      = (MapCount == null) ? 1 : MapCount.Aggregate(1, (acc, val) => acc * val);
                if (HotIndices == null)
                {
                    HotIndices = Vector <double> .Build.Dense(Corners.Length) + 1;
                }
                if (Bias != null)
                {
                    biasVectors = new IVector[maps];
                    ParallelProcessInEnv(maps, (env, taskIndex, mapIndex) =>
                    {
                        biasVectors[mapIndex] = Factory.GetPlainVector(HotIndices * Bias[mapIndex], EVectorFormat.dense, Source.GetOutputScale() * WeightsScale);
                    });
                }
                else
                {
                    biasVectors = new IVector[maps];
                    ParallelProcessInEnv(maps, (env, taskIndex, mapIndex) =>
                    {
                        biasVectors[mapIndex] = Factory.GetPlainVector(HotIndices * Weights[(mapIndex + 1) * kernelSize - 1], EVectorFormat.dense, Source.GetOutputScale() * WeightsScale);
                    });
                }

                layerPrepared = true;
            }
        }
Example #3
0
        public override void Prepare()
        {
            if (layerPrepared)
            {
                return;
            }
            convolutionEngine.Prepare();

            kernelSize = KernelShape.Aggregate(1, (acc, val) => acc * val);
            if (Bias == null)
            {
                kernelSize++;
            }
            if (Weights == null)
            {
                return;
            }
            PrepareWeightsWindows();
            biasVectors   = null;
            layerPrepared = true;
        }