コード例 #1
0
        public List <ImageRepresentation> RecognizeImage(List <ImageRepresentation> Images)
        {
            Model MnistModel = new Model(ModelPath: Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\Backend\\RecognitionModel\\mnist-8.onnx");

            Parallelizer <ImageRepresentation, ImageRepresentation> ModelParallelizer = new Parallelizer <ImageRepresentation, ImageRepresentation>(MnistModel, UseServer: true);
            List <ImageRepresentation> result = ModelParallelizer.Run(Images);

            return(result);
        }
コード例 #2
0
        static int Main(string[] args)
        {
            Model MnistModel = new Model();

            Parallelizer <ImageRepresentation, ImageRepresentation> ModelParallelizer = new Parallelizer <ImageRepresentation, ImageRepresentation>(MnistModel);

            ModelParallelizer.OutputEvent += ConsoleOutput;

            string[] Files = null;
            try
            {
                Files = Directory.GetFiles(args.FirstOrDefault() ?? "images", "*.*").Where(s => s.EndsWith(".bmp") || s.EndsWith(".jpg") ||
                                                                                           s.EndsWith(".png") || s.EndsWith(".jpeg")).ToArray();

                // 0 images found after LINQ filtering
                if (Files == null)
                {
                    throw new ArgumentNullException("Files == NULL");
                }
                if (Files.Length == 0)
                {
                    throw new Exception("There is no images in the directory");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Wrong input" + ex.Message);
            }

            List <ImageRepresentation> Images = new List <ImageRepresentation>();

            foreach (string FilePath in Files)
            {
                byte[] ByteImage = File.ReadAllBytes(FilePath);
                Images.Add(new ImageRepresentation {
                    ImageName = FilePath, Base64Image = Convert.ToBase64String(ByteImage)
                });
            }

            ModelParallelizer.Run(Images);

            return(0);
        }