EasyClassifyTrain¶
Support |
|
|---|---|
Required licenses |
EasyClassify |
Recommended images |
n/a |
Location |
|
Purpose¶
This sample program demonstrates how to:
Train an 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.
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; } }
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");
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);
Train the classifier and wait for the training to end.
newClassifier.Train(trainingDataset, validationDataset, 50); newClassifier.WaitForTrainingCompletion();
Check the validation accuracy of the classifier.
float newClassifierAccuracy = newClassifier.GetValidationMetrics(newClassifier.GetBestIteration()).GetAccuracy(); std::cout << "New classifier accuracy:" << newClassifierAccuracy << std::endl