Dear sir or madam:
I want to verify the pictures which used to train to a classifier can be classified to correct class. But the Sample test result is differenent to my C# program test result.
My Experiment below
I create a new Polimago Classification & Regression to make a pass and fail classifier.
First, I load image and create the pass and fail classes.
Second, I do the Create Classifier to train the classifier.
Third, I save the Polimago classifier file.
Forth, I do the Sample Test to check the training result.
After using TeachBench to make classifier, I use the Visual Studio 2019 C# to Load the classifier I trained and Load the pictures which used to train classifier. But the test result is different to I use Teach Bech Sample Test result.
I also try CVB tutorial Handwriting classifier USDigits6000.pcc. The result is also different, show below.
My C# Code
using Stemmer.Cvb;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Cvb;
using CVBImage = Cvb.Image;
using System.IO;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
private Cvb.SharedPolimagoClf theClassifier_;// The Polimago classifier to be used.
string number = "1";
string file_path_ = @"D:\test\1";
string file_type_ = "*.bmp";
int pass_count_ = 0;
int fail_count_ = 0;
public Form1()
{
InitializeComponent();
LoadClassifier("USDigits6000.pcc");
Classify();
}
private void LoadClassifier(string fileName)
{
try
{
Cvb.SharedPolimagoClf tmp = Cvb.Polimago.OpenClf(fileName);
if (tmp != null)
{
theClassifier_ = tmp;
Console.WriteLine("Loaded classifier '" + fileName + "'");
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
private void Classify()
{
try
{
DirectoryInfo di = new DirectoryInfo(file_path_);
foreach (var fi in di.EnumerateFiles(file_type_))
{
Cvb.Image.IMG image = 0;
bool r = Cvb.Image.LoadImageFile(fi.FullName, out image);
Cvb.Image.IMG normalize_image = 0;
Cvb.Image.CreateNormalizedImage(image, CVBImage.TNormalizeMode.Normalize_MeanVariance, 128, 120, out normalize_image);
double quality;
string cls;
double[] confidences;
if (theClassifier_.Classify(normalize_image, 0, 0, out cls, out quality, out confidences))
{
if (cls == number)
{
pass_count_++;
}
else
{
string ng_message = fi.FullName + " ==> " + confidences[0].ToString() + " " + confidences[1].ToString();
Console.WriteLine(ng_message);
fail_count_++;
}
}
}
Console.WriteLine("Pass count : " + pass_count_.ToString());
Console.WriteLine("Fail count : " + fail_count_.ToString());
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}///////////////////////////////////////////
}