EasyLocateTrain¶
Support |
|
|---|---|
Required licenses |
EasyLocate |
Recommended images |
n/a |
Location |
|
Purpose¶
This sample program demonstrates how to:
Train an EasyLocate tool in console mode.
Code highlights¶
By default, the sample program trains a tool for the dataset ElectronicComponentsBag 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 segmenter that will be trained ELocator newLocator; // 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; } }
Load a dataset from a project.
const EClassificationDataset* dataset; EDeepLearningProject project; project.Load(PROJECT_PATH); dataset = &project.GetDataset();
Alternatively, load a dataset directly from a
.edldatasetfile.const EClassificationDataset* dataset; EClassificationDataset datasetHolder; datasetHolder.Load(DATASET_PATH); dataset = &datasetHolder;
Split the dataset in a training part and a validation part.
Note
Be careful that the method for splitting a dataset is different for each type of tool.
```c++
// Put 80% of images into the training dataset and 20% in the validation dataset
EClassificationDataset trainingDataset;
EClassificationDataset validationDataset;
dataset->SplitDatasetForLocator(trainingDataset, validationDataset, 0.8f);
```
Configure and train the EasyLocate tool and wait for the training to end.
newLocator.SetHeight(550); newLocator.SetWidth(345); newLocator.SetCapacity(ELocatorCapacity_Small); newLocator.SetChannels(1); newLocator.Train(trainingDataset, validationDataset, 1); newLocator.WaitForTrainingCompletion();
Check the validation F-Score of the tool we just trained.
float newLocatorFScore = newLocator.GetValidationMetrics(newLocator.GetBestIteration()).GetBestWeightedFScore(); std::cout << "New locator F-Score:" << newLocatorFScore << std::endl;