public SampleSqueezenet()
        {
            try
            {
                var modelPath   = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + @"Resources\", "squeezenet.onnx");
                var modelLabels = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + @"Resources\", "SqueezenetLabels.txt");
                using (var OnnxSesssion = new OnnxSession(modelPath, modelLabels))
                {
                    var     filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + @"Resources\", "bench.in");
                    float[] data     = DataHelper.LoadTensorFromFile(filePath);

                    if (OnnxSesssion.Infere(new float[][] { data }, out Results results))
                    {
                        results.PrintPrediction();
                    }
                    else
                    {
                        Console.WriteLine("Unable to infere model.");
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                Console.ReadLine();
            }
        }
        public SampleIdentifyDigit()
        {
            try
            {
                var modelPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + @"Resources\", "model.onnx");
                using (var OnnxSession = new OnnxSession(modelPath))
                {
                    using (Bitmap bitmap = (Bitmap)Bitmap.FromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory + @"Resources\", "seven.bmp")))
                    {
                        List <float[]> data = new List <float[]>();
                        foreach (var input in OnnxSession.InputShapes)
                        {
                            data.Add(DataHelper.GetBitmapFloatArray(bitmap, OnnxSession, input.Key, false));
                        }

                        if (OnnxSession.Infere(data.ToArray(), out Results results))
                        {
                            results.PrintPrediction();
                        }
                        else
                        {
                            Console.WriteLine("Unable to infere model.");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                Console.ReadLine();
            }
        }
Exemplo n.º 3
0
        public SampleSqueezenet2()
        {
            try
            {
                var modelPath   = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + @"Resources\", "squeezenet.onnx");
                var modelLabels = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + @"Resources\", "SqueezenetLabels.txt");
                using (var OnnxSesssion = new OnnxSession(modelPath, modelLabels))
                {
                    var bmapPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + @"Resources\", "dog2.jpg");
                    using (Bitmap bitmap = (Bitmap)Image.FromFile(bmapPath, false))
                    {
                        List <float[]> data = new List <float[]>();
                        foreach (var input in OnnxSesssion.InputShapes)
                        {
                            data.Add(DataHelper.GetBitmapFloatArray(bitmap, OnnxSesssion, input.Key, false));
                        }

                        if (OnnxSesssion.Infere(data.ToArray(), out Results results))
                        {
                            results.PrintPrediction();
                        }
                        else
                        {
                            Console.WriteLine("Unable to infere model.");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                Console.ReadLine();
            }
        }