public void RunTest() { // create int array of ascii codes int[] classes = new int[strClasses.Length]; for (int i = 0; i < strClasses.Length; i++) { classes[i] = (int)strClasses[i]; } // init lenet IntPtr lenetptr; LenetWrapper.CreateLenet(out lenetptr, classes.Length, classes, false, false, true); // load network from file LenetWrapper.LoadNetwork(lenetptr, networkFileName); // read image variant 2 Bitmap bitmap = ImgIo.LoadBitmapFromFile(testPngFileName); int w = bitmap.Width; int h = bitmap.Height; byte[] buffer = LenetRoutines.ToMatrix <byte>(bitmap, false); // run recognize from buffer int answer; double rate; LenetWrapper.RecognizeRawData(lenetptr, buffer, buffer.Length, h, w, out answer, out rate); Console.WriteLine("BUFFER: Result index '{0}', rate '{1}'", answer, rate); // run recognize from file LenetWrapper.RecognizeImageFile(lenetptr, testPpmFileName, out answer, out rate); Console.WriteLine("FILE: Result index '{0}', rate '{1}'", answer, rate); // compute outputs int[] outclasses = new int[strClasses.Length]; double[] outenergies = new double[strClasses.Length]; int getsize; LenetWrapper.ComputeOutputs(lenetptr, buffer, buffer.Length, h, w, outclasses, outenergies, out getsize); PrintOutputs(classes, outenergies, getsize); // test CoTaskMemAlloc IntPtr ptrArray; int ptrSize; LenetWrapper.TestDoubleCoTaskMemAlloc(out ptrSize, out ptrArray); IntPtr curr = ptrArray; double[] valArray = new double[ptrSize]; Marshal.Copy(ptrArray, valArray, 0, ptrSize); Marshal.FreeCoTaskMem(ptrArray); }
public void TestSaveNetwork() { // create lenet LenetClassifier classifier = new LenetClassifier(); classifier.CharClass.TanhSigmoid = false; classifier.CharClass.NetNorm = false; classifier.CharClass.AsciiTarget = true; classifier.JunkClass.TanhSigmoid = false; classifier.Set("junk", 0); // disable junk classifier.SetExtractor("scaledfe"); classifier.Initialize(classesNums); // load char lenet from old file format LenetWrapper.LoadNetwork(classifier.CharClass.HrLenet, oldformatFileName); // save network to new format classifier.Save(networkFileName); }