EasyClassifyTrain

Support

Required licenses

EasyClassify

Recommended images

N/A

Location

[…]C:\Users\Public\Documents\Euresys\Open eVision 24.02\Sample Programs
\[LANGUAGE] samples
\Deep Learning Inspection\EasyClassifyTrain

Purpose

This sample program demonstrates how to:

Train an EasyClassify tool in console mode.

Code highlights

By default, the sample program trains a tool for the dataset MiniWaffles in the Deep Learning Additional Resources.

NOTE: In the code, you need to replace DEEP_LEARNING_ADDITIONAL_RESOURCES by the path of the Deep Learning Additional Resources.
1. Select the first available GPU for the training.
// initialize a classifier that will be trained
EClassifier newClassifier;
// make sure that we have a GPU to use (note: GPU's can only be detected in x64 configuration)
std::vector<EDeepLearningDevice> devices = newClassifier.GetAvailableDevices();
bool foundGPU = false;
for (size_t i = 0; i < devices.size(); i++)
{
  if (devices[i].GetDeviceType() == EDeepLearningDeviceType_GPU)
  {
    newClassifier.SetActiveDevice(devices[i]);
    foundGPU = true;
    break;
  }
}
2. Create a dataset and add all the good and defective images to it.
// load the dataset
EClassificationDataset dataset;
dataset.AddImages(std::string(IMAGE_SOURCE_PATH) + "mw_good*.jpg", "Good");
dataset.AddImages(std::string(IMAGE_SOURCE_PATH) + "mw_bad*.jpg", "Bad");
3. Split the dataset in a training part and a validation part.
// Put 80% of images into the training dataset and 20% in the validation dataset
EClassificationDataset trainingDataset;
EClassificationDataset validationDataset;
dataset.SplitDataset(trainingDataset, validationDataset, 0.8f);
4. Train the classifier and wait for the training to end.
newClassifier.Train(trainingDataset, validationDataset, 50);
newClassifier.WaitForTrainingCompletion();
5. Check the validation accuracy of the classifier.
float newClassifierAccuracy = newClassifier.GetValidationMetrics(newClassifier.GetBestIteration()).GetAccuracy();

std::cout << "New classifier accuracy:" << newClassifierAccuracy << std::endl