/// <summary>
        /// Create a new instance of the <see cref="UltraFace"/> class with the specified parameter.
        /// </summary>
        /// <param name="parameter">The parameter.</param>
        /// <returns>The <see cref="UltraFace"/> this method creates.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="parameter"/> is null.</exception>
        /// <exception cref="ArgumentException">The model binary file is null or whitespace. Or the param file is null or whitespace.</exception>
        /// <exception cref="FileNotFoundException">The model binary file is not found. Or the param file is not found.</exception>
        public static UltraFace Create(UltraFaceParameter parameter)
        {
            if (parameter == null)
            {
                throw new ArgumentNullException(nameof(parameter));
            }
            if (string.IsNullOrWhiteSpace(parameter.BinFilePath))
            {
                throw new ArgumentException("The model binary file is null or whitespace", nameof(parameter.BinFilePath));
            }
            if (string.IsNullOrWhiteSpace(parameter.ParamFilePath))
            {
                throw new ArgumentException("The param file is null or whitespace", nameof(parameter.ParamFilePath));
            }
            if (!File.Exists(parameter.BinFilePath))
            {
                throw new FileNotFoundException("The model binary file is not found.");
            }
            if (!File.Exists(parameter.ParamFilePath))
            {
                throw new FileNotFoundException("The param file is not found.");
            }

            return(new UltraFace(parameter));
        }
        private UltraFace(UltraFaceParameter parameter)
        {
            this._NumThread      = parameter.NumThread;
            this._TopK           = parameter.TopK;
            this._ScoreThreshold = parameter.ScoreThreshold;
            this._IouThreshold   = parameter.IouThreshold;
            this._InW            = parameter.InputWidth;
            this._InH            = parameter.InputLength;

            var whList = new float[] { parameter.InputWidth, parameter.InputLength };

            foreach (var size in whList)
            {
                var featureMapItem = this._Strides.Select(stride => (float)Math.Ceiling(size / stride)).ToArray();
                this._FeatureMapSize.Add(featureMapItem);
            }

            foreach (var _ in whList)
            {
                this._ShrinkageSize.Add(this._Strides);
            }

            for (var index = 0; index < NumFeatureMap; index++)
            {
                var scaleW = this._InW / this._ShrinkageSize[0][index];
                var scaleH = this._InH / this._ShrinkageSize[1][index];
                for (var j = 0; j < this._FeatureMapSize[1][index]; j++)
                {
                    for (var i = 0; i < this._FeatureMapSize[0][index]; i++)
                    {
                        var xCenter = (float)((i + 0.5) / scaleW);
                        var yCenter = (float)((j + 0.5) / scaleH);

                        foreach (var k in this._MinBoxes[index])
                        {
                            var w = k / this._InW;
                            var h = k / this._InH;

                            this._Priors.Add(
                                new[]
                            {
                                Clip(xCenter, 1),
                                Clip(yCenter, 1),
                                Clip(w, 1),
                                Clip(h, 1)
                            });
                        }
                    }
                }
            }

            this._NumAnchors = this._Priors.Count;

            this._UltraFace = new Net();
            this._UltraFace.LoadParam(parameter.ParamFilePath);
            this._UltraFace.LoadModel(parameter.BinFilePath);
        }
 public static UltraFace Create(UltraFaceParameter parameter)
 {
     return(new UltraFace(parameter));
 }