private void InitBookstoreSource(string bookPaths) { try { string[] books = bookPaths.Split(';'); BookstoreSource.Clear(); lineSource.Init(bookPaths); BookstoreSource.FromLineSource(lineSource); if (bookstoreSource.Count > 0) { listBooksLine.SelectedIndex = 0; } } catch { } }
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); }
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); }