Пример #1
0
        private void GenerateBBox(ICollection <FaceInfo> boundingBoxCollection, Mat scores, Mat boxes, float scoreThreshold, int numAnchors)
        {
            using (var scoresChannel = scores.Channel(0))
                using (var boxesChannel = boxes.Channel(0))
                {
                    for (var i = 0; i < numAnchors; i++)
                    {
                        if (scoresChannel[i * 2 + 1] > scoreThreshold)
                        {
                            var rects   = new FaceInfo();
                            var xCenter = boxesChannel[i * 4] * CenterVariance * this._Priors[i][2] + this._Priors[i][0];
                            var yCenter = boxesChannel[i * 4 + 1] * CenterVariance * this._Priors[i][3] + this._Priors[i][1];
                            var w       = Math.Exp(boxesChannel[i * 4 + 2] * SizeVariance) * this._Priors[i][2];
                            var h       = Math.Exp(boxesChannel[i * 4 + 3] * SizeVariance) * this._Priors[i][3];

                            rects.X1    = Clip(xCenter - w / 2.0, 1) * this._ImageW;
                            rects.Y1    = Clip(yCenter - h / 2.0, 1) * this._ImageH;
                            rects.X2    = Clip(xCenter + w / 2.0, 1) * this._ImageW;
                            rects.Y2    = Clip(yCenter + h / 2.0, 1) * this._ImageH;
                            rects.Score = Clip(scoresChannel[i * 2 + 1], 1);

                            boundingBoxCollection.Add(rects);
                        }
                    }
                }
        }
Пример #2
0
        public static int CompareMat(Mat a, Mat b, float epsilon = 0.001f)
        {
            if (CheckMember(nameof(Mat.Dims), a.Dims, b.Dims) != 0)
            {
                return(-1);
            }
            if (CheckMember(nameof(Mat.W), a.W, b.W) != 0)
            {
                return(-1);
            }
            if (CheckMember(nameof(Mat.H), a.H, b.H) != 0)
            {
                return(-1);
            }
            if (CheckMember(nameof(Mat.C), a.C, b.C) != 0)
            {
                return(-1);
            }
            if (CheckMember(nameof(Mat.ElemSize), a.ElemSize, b.ElemSize) != 0)
            {
                return(-1);
            }
            if (CheckMember(nameof(Mat.ElemPack), a.ElemPack, b.ElemPack) != 0)
            {
                return(-1);
            }

            for (int q = 0, c = a.C; q < c; q++)
            {
                using (var ma = a.Channel(q))
                    using (var mb = b.Channel(q))
                    {
                        for (int i = 0, h = a.H; i < h; i++)
                        {
                            var pa = ma.Row(i);
                            var pb = mb.Row(i);
                            for (int j = 0, w = a.W; j < w; j++)
                            {
                                if (!FloatNearlyEqual(pa[j], pb[j], epsilon))
                                {
                                    Console.Error.WriteLine($"value not match at {q} {i} {j}    {pa[j]} {pb[j]}");
                                    return(-1);
                                }
                            }
                        }
                    }
            }

            return(0);
        }