Exemple #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 = "boost.yml";

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            using (var model = Boost.Create())
            {
                model.MaxDepth      = 1;
                model.UseSurrogates = false;
                model.Train(trainFeatures, SampleTypes.RowSample, trainLabels);

                model.Save(fileName);
            }

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

            string content = File.ReadAllText(fileName);

            //Console.WriteLine(content);

            // does not throw
            using (var model2 = Boost.Load(fileName))
            {
                GC.KeepAlive(model2);
            }
            using (var model2 = Boost.LoadFromString(content))
            {
                GC.KeepAlive(model2);
            }
        }