예제 #1
0
        public void InitDataSets(ImageDatas imageDatas)
        {
            if (imageDatas == null)
            {
                throw new Exception("Invalid Image Datas!");
            }

            dataSets = new DataSets(width, height, imageDatas, 0);
            ResetPredictions();
        }
예제 #2
0
        public void InitDataSets(ImageDatas imageDatas, double split, int seed)
        {
            if (imageDatas == null)
            {
                throw new Exception("Invalid Image Datas!");
            }

            dataSets = new DataSets(width, height, imageDatas, split, seed);
            BuildDataSets();
        }
예제 #3
0
        // Performs predictions on a supplied dataset and loaded neural model:
        // Calculates prediction accuracies and errors relative to the expected labeling
        public ImageDatas Predict(bool isCNN)
        {
            if (model_loaded == null)
            {
                throw new Exception("Invalid Model!");
            }
            if (dataSets == null || !dataSets.isImageDatas())
            {
                throw new Exception("Invalid Dataset!");
            }

            ImageDatas    ids    = dataSets.GetImageDatas();
            ImageDatas    idf    = new ImageDatas();
            NDarray       x_data = dataSets.BuildDataSet();
            List <string> labels = ids.GetLabels();

            if (isCNN)
            {
                x_data = (K.ImageDataFormat() == "channels_first")
                    ? x_data.reshape(x_data.shape[0], 1, height, width)
                    : x_data.reshape(x_data.shape[0], height, width, 1);
            }

            Console.WriteLine("Predicting {0} Images", ids.Count);
            NDarray y = model_loaded.Predict(x_data, verbose: 2);

            int     index;
            NDarray result;

            for (int i = 0; i < y.len; i++)
            {
                result = y[i];
                result = result.argmax();
                index  = result.asscalar <int>();

                if (ids[i].Label != labels[index])
                {
                    ids[i].Index = labels.IndexOf(ids[i].Label) + 1;
                    idf.Add(ids[i]);
                }
            }
            double accuracy = Math.Round(((y.len - idf.Count) * 100) / (double)y.len, 2);

            idf.SetResults(string.Format("Predicted:{0} Correct: {1} Incorrect:{2} Accuracy:{3}", y.len, y.len - idf.Count, idf.Count, accuracy));
            return(idf);
        }
예제 #4
0
파일: DataSet.cs 프로젝트: drumzzzzz/MazeAI
        public DataSets(int Width, int Height, ImageDatas imageDatas, double split, int seed)
        {
            if (split < 0 || split > 1.00)
            {
                throw new Exception(string.Format("Invalid split parameter: {0}", split));
            }

            ImageSize = (Width * Height);

            this.imageDatas = imageDatas;
            this.split      = split;

            if (seed != 0)
            {
                r = new Random(seed);
            }
            else
            {
                r = new Random();
            }
        }
예제 #5
0
파일: DataSet.cs 프로젝트: drumzzzzz/MazeAI
 public DataSets(int Width, int Height, ImageDatas imageDatas, int seed)
 {
     ImageSize       = (Width * Height);
     this.imageDatas = imageDatas;
     imageDatas.InitLabelIndexes();
 }