GetClassifier() public method

public GetClassifier ( ) : IModel
return IModel
Example #1
0
        public override void Load(string filename)
        {
            Linerec linerec = LoadLinerec(filename);

            if (linerec != null)
            {
                this.classifier.Object = linerec.GetClassifier();
            }
        }
Example #2
0
        public void TestTrainLenetCseg()
        {
            string bookPath = "data\\0000\\";
            string netFileName = "latin-lenet.model";

            Linerec.GDef("linerec", "use_reject", 1);
            Linerec.GDef("lenet", "junk", 1);
            Linerec.GDef("lenet", "epochs", 4);

            // create Linerec
            Linerec linerec;
            if (File.Exists(netFileName))
                linerec = Linerec.LoadLinerec(netFileName);
            else
            {
                linerec = new Linerec("lenet");
                LenetClassifier classifier = linerec.GetClassifier() as LenetClassifier;
                if (classifier != null)
                    classifier.InitNumSymbLatinAlphabet();
            }

            // temporary disable junk
            //linerec.DisableJunk = true;

            linerec.StartTraining();
            int nepochs = 10;
            LineSource lines = new LineSource();
            lines.Init(new string[] { "data2" });

            //linerec.GetClassifier().Set("epochs", 1);

            for (int epoch = 1; epoch <= nepochs; epoch++)
            {
                linerec.Epoch(epoch);

                // load cseg samples
                while (!lines.Done())
                {
                    lines.MoveNext();
                    Intarray cseg = new Intarray();
                    //Bytearray image = new Bytearray();
                    string transcript = lines.GetTranscript();
                    //lines.GetImage(image);
                    if (!lines.GetCharSegmentation(cseg) && cseg.Length() == 0)
                    {
                        Global.Debugf("warn", "skipping book {0} page {1} line {2} (no or bad cseg)",
                            lines.CurrentBook, lines.CurrentPage, lines.Current);
                        continue;
                    }
                    SegmRoutine.make_line_segmentation_black(cseg);
                    linerec.AddTrainingLine(cseg, transcript);
                }

                lines.Reset();
                lines.Shuffle();
                // do Train and clear Dataset
                linerec.FinishTraining();
                // do save
                if (epoch % 1 == 0)
                    linerec.Save(netFileName);

                // recognize test line
                bool bakDisJunk = linerec.DisableJunk;
                linerec.DisableJunk = false;
                DoTestLinerecRecognize(linerec, "data2\\", "test1.png");
                linerec.DisableJunk = bakDisJunk;
            }

            // finnaly save
            linerec.Save(netFileName);
        }