Creating a Dataset and Training a Locator

This code snippet shows how to create a dataset, train a Locator and get the best performance metrics obtained during the training.

C++

#include <eVision/EasyDeepLearning/EasyLocate/ELocator.h>
using namespace eVision;
using namespace eVision::EasyDeepLearning;

// Creating dataset and locator objects
EDataset dataset;
EDataset trainingDataset;
EDataset validationDataset;

// The ELocator class locates axis-aligned bounding boxes.
// The EInterestPointLocator class locates only points.

// EInterestPointLocator locator;
ELocator locator;

// Adding images using a glob pattern
dataset.AddImages("/my/image/path/*.png");

// Add labeling information
ERectangleRegion region1 = {50, 50, 10, 30};
ERectangleRegion region2 = {90, 130, 50, 60};
// ...

dataset.AddImageObject(0, "first object type", region1);
dataset.AddImageObject(1, "second object type", region2);
// ...

// Create data augmentation
EDataAugmentation augmentation;

// Rotation of up to 90
augmentation.SetMaxRotationAngle(90);

// Enabling horizontal flips
augmentation.SetEnableHorizontalFlip(true);

// Splitting the dataset with 80% of images for the training dataset
// and 20% for the validation dataset
dataset.SplitDatasetForLocator(trainingDataset, validationDataset, 0.8f);

// Training the locator for 50 epochs
locator.Train(trainingDataset, validationDataset, augmentation, 50);
locator.WaitForTrainingCompletion();

// Get the best metrics obtained on the validation dataset
ELocatorMetrics bestMetrics = locator.GetValidationMetrics(locator.GetBestIteration());

C#

using eVision;
using eVision.EasyDeepLearning;
// Creating dataset and locator objects
EDataset dataset = new EDataset();
EDataset trainingDataset = new EDataset();
EDataset validationDataset = new EDataset();

// The ELocator class locates axis-aligned bounding boxes.
// The EInterestPointLocator class locates only points.

// EInterestPointLocator locator = new EInterestPointLocator();
ELocator locator = new ELocator();

// Adding images using a glob pattern
dataset.AddImages("/my/image/path/*.png");

// Add labeling information
ERectangleRegion region1 = new ERectangleRegion(50, 50, 10, 30);
ERectangleRegion region2 = new ERectangleRegion(90, 130, 50, 60);
// ...

dataset.AddImageObject(0, "first object type", region1);
dataset.AddImageObject(1, "second object type", region2);
// ...

// Create data augmentation
EDataAugmentation augmentation = new EDataAugmentation();

// Rotation of up to 90°
augmentation.MaxRotationAngle = 90.0F;

// Enabling horizontal flips
augmentation.EnableHorizontalFlip = true;

// Splitting the dataset with 80% of images for the training dataset
// and 20% for the validation dataset
dataset.SplitDatasetForLocator(trainingDataset, validationDataset, 0.8F);

// Training the locator for 50 epochs
locator.Train(trainingDataset, validationDataset, augmentation, 50);
locator.WaitForTrainingCompletion();

// Get the best metrics obtained on the validation dataset
ELocatorMetrics bestMetrics = locator.GetValidationMetrics(locator.BestIteration);

Python

import eVision
from eVision import EasyDeepLearning as edl

# Creating dataset and locator objects
dataset = edl.EDataset()
training_dataset = edl.EDataset()
validation_dataset = edl.EDataset()

# The ELocator class locates axis-aligned bounding boxes.
# The EInterestPointLocator class locates only points.

# locator = edl.EInterestPointLocator()
locator = edl.ELocator()

# Adding images using a glob pattern
dataset.AddImages("/my/image/path/*.png")

# Add labeling information
region1 = eVision.ERectangleRegion(50, 50, 10, 30)
region2 = eVision.ERectangleRegion(90, 130, 50, 60)
# ...

dataset.AddImageObject(0, "first object type", region1)
dataset.AddImageObject(1, "second object type", region2)
# ...

# Create data augmentation
augmentation = edl.EDataAugmentation()

# Rotation of up to 90°
augmentation.MaxRotationAngle = 90.0

# Enabling horizontal flips
augmentation.EnableHorizontalFlip = True

# Splitting the dataset with 80% of images for the training dataset
# and 20% for the validation dataset
dataset.SplitDatasetForLocator(training_dataset, validation_dataset, 0.8)

# Training the locator for 50 epochs
locator.Train(training_dataset, validation_dataset, augmentation, 50)
locator.WaitForTrainingCompletion()

# Get the best metrics obtained on the validation dataset
best_metrics = locator.GetValidationMetrics(locator.BestIteration)