private void startClassifying(object sender, DoWorkEventArgs e)
        {
            PredictionResults = new ObservableCollection <CustomTwoClassificationImagePredictionResults>();
            Console.WriteLine("-----------------------------------");
            Console.WriteLine(targetDirectoryPath);


            // set up output paths for all classes.

            var inventoryDir = System.IO.Path.Combine(targetDirectoryPath, "inventory");            /////////// inventory

            if (!System.IO.Directory.Exists(inventoryDir))
            {
                System.IO.Directory.CreateDirectory(inventoryDir);
            }


            var infrastructureDir = System.IO.Path.Combine(targetDirectoryPath, "infrastructure");            /////////////////infrasturcture

            Console.WriteLine(infrastructureDir);
            if (!System.IO.Directory.Exists(infrastructureDir))
            {
                System.IO.Directory.CreateDirectory(infrastructureDir);
            }


            var fieldDir = System.IO.Path.Combine(targetDirectoryPath, "field");            /////////field

            Console.WriteLine(fieldDir);
            if (!System.IO.Directory.Exists(fieldDir))
            {
                System.IO.Directory.CreateDirectory(fieldDir);
            }


            var vehiclesDir = System.IO.Path.Combine(targetDirectoryPath, "vehicles");            ///////////vehicles

            Console.WriteLine(vehiclesDir);
            if (!System.IO.Directory.Exists(vehiclesDir))
            {
                System.IO.Directory.CreateDirectory(vehiclesDir);
            }

            var roadDir = System.IO.Path.Combine(targetDirectoryPath, "road");            //////////road

            Console.WriteLine(roadDir);
            if (!System.IO.Directory.Exists(roadDir))
            {
                System.IO.Directory.CreateDirectory(roadDir);
            }

            var waterDir = System.IO.Path.Combine(targetDirectoryPath, "water");            ///////////water

            Console.WriteLine(waterDir);
            if (!System.IO.Directory.Exists(waterDir))
            {
                System.IO.Directory.CreateDirectory(waterDir);
            }


            foreach (var item in filesToProcess)
            {
                _imageClassificationCount++;
                Console.WriteLine(_imageClassificationCount); //parse to model input
                ModelInput mip = new ModelInput();
                mip.Label       = "none";
                mip.ImageSource = item;



                //##########################################################

                ModelOutput mop = ConsumeModel.Predict(mip, ConsumeModel.ClassicationModelEnum.classsix);



                string toprintDebugConsole = $"prediction class: {mop.Prediction}|| score: {mop.Score.FirstOrDefault()}";

                //##########################################################
                Console.WriteLine(toprintDebugConsole);
                Console.WriteLine(mop.Prediction.ToString());
                Console.WriteLine(mop.Score.FirstOrDefault());
                Console.WriteLine("##########################");
                Console.WriteLine(item);
                var filename = System.IO.Path.GetFileName(item);
                Console.WriteLine(filename);
                string disclass = System.IO.Path.Combine(targetDirectoryPath, mop.Prediction);
                Console.WriteLine(disclass);
                var destfile = System.IO.Path.Combine(disclass, filename);
                Console.WriteLine(destfile);
                System.IO.File.Copy(item, destfile, true);


                var newPredictionToUpdateOutputStatus = new CustomTwoClassificationImagePredictionResults();
                newPredictionToUpdateOutputStatus.PredictionId      = _imageClassificationCount.ToString();
                newPredictionToUpdateOutputStatus.ImageOriginalPath = item.ToString();
                Console.WriteLine(item.ToString());
                newPredictionToUpdateOutputStatus.ModelOutputscore      = mop.Score.FirstOrDefault().ToString();
                newPredictionToUpdateOutputStatus.ModelOutputPrediction = mop.Prediction;


                Console.WriteLine("number of items in observable collection");


                //from the backgroud thread in backgroudworker, I need to call the ui thread to update the listview
                uiContext.Send(x => PredictionResults.Add(newPredictionToUpdateOutputStatus), null);
                //PredictionResults.Add(newPredictionToUpdateOutputStatus);


                Console.WriteLine(PredictionResults.Count.ToString());
            }
        }
示例#2
0
        private void ImageBinaryClassificationAndDuplicateWorker(object sender, DoWorkEventArgs e)
        {
            //should probably check for inputdirecttext is validated
            _filesToProcess = Directory.GetFiles(InputDirText);
            //I need property and feild for data binding of the text box for model location
            //modelFilePath =
            _predictedResults          = new ObservableCollection <CustomTwoClassificationImagePredictionResults>();
            _targetOutputDirectoryPath = OutputDirText;


            //create output directories
            Console.WriteLine("-----------------------------------");
            Console.WriteLine(_targetOutputDirectoryPath);
            var inventoryDir = System.IO.Path.Combine(_targetOutputDirectoryPath, "inventory");

            Console.WriteLine(inventoryDir);
            Console.WriteLine(inventoryDir);
            var infrastructureDir = System.IO.Path.Combine(_targetOutputDirectoryPath, "infrastructure");

            Console.WriteLine(infrastructureDir);
            if (!System.IO.Directory.Exists(inventoryDir))
            {
                System.IO.Directory.CreateDirectory(inventoryDir);
            }
            if (!System.IO.Directory.Exists(infrastructureDir))
            {
                System.IO.Directory.CreateDirectory(infrastructureDir);
            }



            MLContext mlContext = new MLContext();
            // ModelOutput mop = ConsumeModel.Predict(mip, ConsumeModel.ClassicationModelEnum.classtwo);

            string modelPath = _modelInputFileText;

            //// Load model & create prediction engine
            ITransformer mlModel = mlContext.Model.Load(modelPath, out var modelInputSchema);

            foreach (var item in _filesToProcess)
            {
                Console.WriteLine(_imageClassificationCount.ToString());
                _imageClassificationCount++;
                Console.WriteLine(_imageClassificationCount); //parse to model input
                ModelInput mip = new ModelInput();
                mip.Label       = "none";                     //useful for evaluation section
                mip.ImageSource = item;



                //##########################################################

                var predEngine = mlContext.Model.CreatePredictionEngine <ModelInput, ModelOutput>(mlModel);

                Console.WriteLine($"number of columns is ======= {modelInputSchema.Count.ToString()}");
                foreach (var inputItem in modelInputSchema)
                {
                    Console.WriteLine($"name of column is ========={inputItem.Name}");
                }

                // Console.WriteLine($"count is ======= {modelInputSchema.}");

                // Use model to make prediction on input data
                ModelOutput result = predEngine.Predict(mip);



                string toprintDebugConsole = $"prediction class: {result.Prediction}|| score: {result.Score.FirstOrDefault()}";

                //##########################################################
                Console.WriteLine(toprintDebugConsole);
                Console.WriteLine(result.Prediction.ToString());
                Console.WriteLine(result.Score.FirstOrDefault());
                Console.WriteLine("##########################");
                Console.WriteLine(item);
                var filename = System.IO.Path.GetFileName(item);
                Console.WriteLine(filename);
                string disclass = System.IO.Path.Combine(_targetOutputDirectoryPath, result.Prediction);
                Console.WriteLine(disclass);
                var destfile = System.IO.Path.Combine(disclass, filename);
                Console.WriteLine(destfile);
                System.IO.File.Copy(item, destfile, true);



                //update ui with
                var newPredictionToUpdateOutputStatus = new CustomTwoClassificationImagePredictionResults();
                newPredictionToUpdateOutputStatus.PredictionId      = _imageClassificationCount.ToString();
                newPredictionToUpdateOutputStatus.ImageOriginalPath = item.ToString();
                Console.WriteLine(item.ToString());
                newPredictionToUpdateOutputStatus.ModelOutputscore      = result.Score.FirstOrDefault().ToString();
                newPredictionToUpdateOutputStatus.ModelOutputPrediction = result.Prediction;


                Console.WriteLine("number of items in observable collection");


                //from the backgroud thread in backgroudworker, I need to call the ui thread to update the listview
                uiContext.Send(x => PredictionResults.Add(newPredictionToUpdateOutputStatus), null);
                //PredictionResults.Add(newPredictionToUpdateOutputStatus);


                Console.WriteLine(PredictionResults.Count.ToString());
            }
        }