Beispiel #1
0
        public NNModel(string modelPath, string labelPath, string imageDirectory = "", int size = 28, bool grayMode = false)
        {
            if (modelPath == "")
            {
                ModelPath = Path.Combine(DefaultImageDir, "mnist-8.onnx");
                labelPath = Path.Combine(DefaultImageDir, "classlabel.txt");
                Trace.WriteLine("Model = " + ModelPath);
                Trace.WriteLine("label = " + labelPath);
            }
            else
            {
                ModelPath = modelPath;
            }

            //DefaultImageDir = Path.Combine(DefaultImageDir, "images");
            Session                   = new InferenceSession(ModelPath);
            ClassLabels               = File.ReadAllLines(labelPath);
            targetHeight              = size;
            targetWidth               = size;
            grayscaleMode             = grayMode;
            CQ                        = new ConcurrentQueue <RecognitionInfo>();
            cancel                    = new CancellationTokenSource();
            ImageDirectory            = imageDirectory;
            recognitionLibraryContext = new RecognitionLibraryContext();
        }