Ejemplo n.º 1
0
        public void SaveLoadTest()
        {
            float[,] trainFeaturesData =
            {
                 {0, 0},
                 {0, 100},
                 {100, 0},
                 {100, 100},
            };
            var trainFeatures = new Mat(4, 2, MatType.CV_32F, trainFeaturesData);

            int[] trainLabelsData = { 1, -1, 1, -1 };
            var trainLabels = new Mat(4, 1, MatType.CV_32S, trainLabelsData);

            const string fileName = "rtrees.yml";
            if (File.Exists(fileName))
                File.Delete(fileName);

            using (var model = RTrees.Create())
            {
                model.Train(trainFeatures, SampleTypes.RowSample, trainLabels);

                model.Save(fileName);
            }

            Assert.True(File.Exists(fileName));

            string content = File.ReadAllText(fileName);
            //Console.WriteLine(content);

            // Assert.DoesNotThrow
            using (var model2 = RTrees.Load(fileName)) { }
            using (var model2 = RTrees.LoadFromString(content)) { }
        }
Ejemplo n.º 2
0
        public override void Load(string path)
        {
            if (TrainedModel != null)
            {
                throw new InvalidOperationException("May only train/load a model once");
            }

            TrainedModel = RTrees.Load(path);
        }
Ejemplo n.º 3
0
 // load
 public ModelOpenCV(string path)
 {
     TrainedModel = RTrees.Load(path);
 }