示例#1
0
文件: Multibox.cs 项目: radtek/emgutf
        public Result[] Detect(Tensor imageResults)
        {
            if (_graph == null)
            {
                throw new NullReferenceException("The multibox graph has not been initialized. Please call the Init function first.");
            }
            Tensor[] finalTensor = _session.Run(new Output[] { _graph["ResizeBilinear"] }, new Tensor[] { imageResults },
                                                new Output[] { _graph["output_scores/Reshape"], _graph["output_locations/Reshape"] });

            int labelCount = finalTensor[0].Dim[1];

            Tensor[] topK = GetTopDetections(finalTensor[0], labelCount);

            float[] encodedScores    = topK[0].Flat <float>();
            float[] encodedLocations = finalTensor[1].Flat <float>();

            int[]     indices   = topK[1].Flat <int>();
            float[]   scores    = DecodeScoresEncoding(encodedScores);
            Result[]  results   = new Result[indices.Length];
            float[][] locations = MultiboxGraph.DecodeLocationsEncoding(encodedLocations, _boxPriors);
            for (int i = 0; i < indices.Length; i++)
            {
                results[i]                  = new Result();
                results[i].Scores           = scores[i];
                results[i].DecodedLocations = locations[indices[i]];
            }

            return(results);
        }
示例#2
0
        public Result[] Detect(Tensor imageResults)
        {
            Tensor[] finalTensor = _session.Run(new Output[] { _graph["ResizeBilinear"] }, new Tensor[] { imageResults },
                                                new Output[] { _graph["output_scores/Reshape"], _graph["output_locations/Reshape"] });

            int labelCount = finalTensor[0].Dim[1];

            Tensor[] topK = GetTopDetections(finalTensor[0], labelCount);

            float[] encodedScores    = topK[0].Flat <float>();
            float[] encodedLocations = finalTensor[1].Flat <float>();

            int[]     indices   = topK[1].Flat <int>();
            float[]   scores    = DecodeScoresEncoding(encodedScores);
            Result[]  results   = new Result[indices.Length];
            float[][] locations = MultiboxGraph.DecodeLocationsEncoding(encodedLocations, _boxPriors);
            for (int i = 0; i < indices.Length; i++)
            {
                results[i]                  = new Result();
                results[i].Scores           = scores[i];
                results[i].DecodedLocations = locations[indices[i]];
            }

            return(results);
        }
示例#3
0
        public Result Detect(Tensor imageResults)
        {
            Session multiboxSession = new Session(this);

            Tensor[] finalTensor = multiboxSession.Run(new Output[] { this["ResizeBilinear"] }, new Tensor[] { imageResults },
                                                       new Output[] { this["output_scores/Reshape"], this["output_locations/Reshape"] });

            int labelCount = finalTensor[0].Dim[1];

            Tensor[] topK = GetTopDetections(finalTensor, labelCount);

            float[] encodedScores = topK[0].Flat <float>();

            float[] encodedLocations = finalTensor[1].Flat <float>();

#if __ANDROID__
            float[] boxPriors = ReadBoxPriors(System.IO.Path.Combine(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath, Android.OS.Environment.DirectoryDownloads, _modelFiles[1]));
#else
            float[] boxPriors = ReadBoxPriors(_modelFiles[1]);
#endif


            Result result = new Result();
            result.Scores           = DecodeScoresEncoding(encodedScores);
            result.Indices          = topK[1].Flat <int>();
            result.DecodedLocations = MultiboxGraph.DecodeLocationsEncoding(encodedLocations, boxPriors);
            return(result);
        }
示例#4
0
        public Result Detect(Tensor imageResults)
        {
            Tensor[] finalTensor = _session.Run(new Output[] { _graph["ResizeBilinear"] }, new Tensor[] { imageResults },
                                                new Output[] { _graph["output_scores/Reshape"], _graph["output_locations/Reshape"] });

            int labelCount = finalTensor[0].Dim[1];

            Tensor[] topK = GetTopDetections(finalTensor, labelCount);

            float[] encodedScores = topK[0].Flat <float>();

            float[] encodedLocations = finalTensor[1].Flat <float>();

            Result result = new Result();

            result.Scores           = DecodeScoresEncoding(encodedScores);
            result.Indices          = topK[1].Flat <int>();
            result.DecodedLocations = MultiboxGraph.DecodeLocationsEncoding(encodedLocations, _boxPriors);
            return(result);
        }
示例#5
0
        public Result Detect(Tensor imageResults, SessionOptions sessionOptions = null)
        {
            Session multiboxSession = new Session(_graph, sessionOptions);

            Tensor[] finalTensor = multiboxSession.Run(new Output[] { _graph["ResizeBilinear"] }, new Tensor[] { imageResults },
                                                       new Output[] { _graph["output_scores/Reshape"], _graph["output_locations/Reshape"] });

            int labelCount = finalTensor[0].Dim[1];

            Tensor[] topK = GetTopDetections(finalTensor, labelCount);

            float[] encodedScores = topK[0].Flat <float>();

            float[] encodedLocations = finalTensor[1].Flat <float>();

            float[] boxPriors = ReadBoxPriors(_downloadManager.Files[1].LocalFile);

            Result result = new Result();

            result.Scores           = DecodeScoresEncoding(encodedScores);
            result.Indices          = topK[1].Flat <int>();
            result.DecodedLocations = MultiboxGraph.DecodeLocationsEncoding(encodedLocations, boxPriors);
            return(result);
        }
示例#6
0
        public Result Detect(Tensor imageResults)
        {
            Session multiboxSession = new Session(this);

            Tensor[] finalTensor = multiboxSession.Run(new Output[] { this["ResizeBilinear"] }, new Tensor[] { imageResults },
                                                       new Output[] { this["output_scores/Reshape"], this["output_locations/Reshape"] });

            int labelCount = finalTensor[0].Dim[1];

            Tensor[] topK = GetTopDetections(finalTensor, labelCount);

            float[] encodedScores = topK[0].Flat <float>();

            float[] encodedLocations = finalTensor[1].Flat <float>();

            float[] boxPriors = ReadBoxPriors(GetLocalFileName(_modelFiles[1]));

            Result result = new Result();

            result.Scores           = DecodeScoresEncoding(encodedScores);
            result.Indices          = topK[1].Flat <int>();
            result.DecodedLocations = MultiboxGraph.DecodeLocationsEncoding(encodedLocations, boxPriors);
            return(result);
        }