<a id="easydeeplearning-training"></a>

# Training a Deep Learning Tool

<a id="easydeeplearning-training-dlstudio"></a>

## Deep Learning Studio

1. Create a new tool by clicking on `Add`
2. Configure the tool settings.
3. Select the dataset split to use for this tool.
4. Configure the training settings and click on `Train`.

![](assets/images/easydeeplearning/training_tool_1.webp)

<a id="easydeeplearning-training-api"></a>

## API

In the API, to train a deep learning tool, call the corresponding method:

* [`EClassifier::Train`](../../../doxygen_cpp/classeVision_1_1EasyDeepLearning_1_1EClassifier.html#aa144828bd74a48c1dd01f82ad470b84c) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyDeepLearning_1_1EClassifier.html#a26f9e63be479994e16574900b786107f) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyDeepLearning_1_1EClassifier.html#a802128cd3e7078ce468316ed6773219a)
* [`ELocatorBase::Train`](../../../doxygen_cpp/classeVision_1_1EasyDeepLearning_1_1ELocatorBase.html#a661fd1e5246e8cd27ef2bc9c8a290faf) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyDeepLearning_1_1ELocatorBase.html#af0640d57425f1711d22fc3cfe46f6f50) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyDeepLearning_1_1ELocatorBase.html#a249d14ecffa9c0193dd1b322f22a40aa)
* [`ESupervisedSegmenter::Train`](../../../doxygen_cpp/classeVision_1_1EasyDeepLearning_1_1ESupervisedSegmenter.html#a6db279d374dd76c7f9eb7e1aa5722c3f) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyDeepLearning_1_1ESupervisedSegmenter.html#a3a3cd0e85aad7c18dcff83a159a91630) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyDeepLearning_1_1ESupervisedSegmenter.html#aa24f6cb6f696e971812d43ab8568f8cf)
* [`EUnsupervisedSegmenter::Train`](../../../doxygen_cpp/classeVision_1_1EasyDeepLearning_1_1EUnsupervisedSegmenter.html#a054f8723fca628792bcf29b8e8cd36fc) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyDeepLearning_1_1EUnsupervisedSegmenter.html#ae474dfd2b09aa2f541e30e21beaa8268) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyDeepLearning_1_1EUnsupervisedSegmenter.html#a2856f8eee2c536b2f6a1b4ced1d18775)

<a id="easydeeplearning-training-settings"></a>

## Training Settings

![](assets/images/easydeeplearning/training_tool_4.webp)
* The number of `Iterations`. An  ***Iteration*** corresponds to going through all the images in the training set once.
  * The training process requires a large number of iterations to obtain good results.
  * The larger the number of iterations, the longer the training is and the better the results you obtain.
  * By default, the number of iteration is determined automatically during the training to stop when no progress has been made for a while.
    * This is called early stopping.
    * To disable this behavior, use the method `Train` of any tool with the iteration parameter.
  * An iteration is also called an *epoch*.

  #### NOTE
  We recommend to use more iterations than the default value in these cases:
  * For **EasyClassify** without pretraining, **EasyLocate** and **EasySegment**.
  * For smaller dataset because the training is harder (for example, 100 iterations for a dataset with 100 images, 200 iterations for a dataset with 50 images, 400 iterations for a dataset with 25 images…).
* The `Batch size` corresponds to the number of images or image patches that are processed together.
  * The training is influenced by the batch size.
  * A large batch size increases the processing speed of a single iteration on a GPU but requires more memory.
  * The training process is not able to learn a good model with too small batch sizes.
  * By default, the batch size is determined automatically during the training to optimize the training speed with respect to the available memory.
    * Use [`EDeepLearningTool::SetOptimizeBatchSize`](../../../doxygen_cpp/classeVision_1_1EasyDeepLearning_1_1EDeepLearningTool.html#ad053d92868d6f9cec9ea6137a9fb58e7) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyDeepLearning_1_1EDeepLearningTool.html#a832839abe210e804f2805dc958632ee1) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyDeepLearning_1_1EDeepLearningTool.html#a295132c781638575917a648624502a8c) to disable this behavior.
    * Use [`EDeepLearningTool::SetBatchSize`](../../../doxygen_cpp/classeVision_1_1EasyDeepLearning_1_1EDeepLearningTool.html#a08067d6a1df8bc6767e2072c4efde09a) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyDeepLearning_1_1EDeepLearningTool.html#a5d6d6c5c316f2171cc101e09d6008f85) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyDeepLearning_1_1EDeepLearningTool.html#a6faea0ff36adc9568c36fc73268d58f1) to change the size of your batch.
  * [`EDeepLearningTool::GetBatchSizeForMaximumInferenceSpeed`](../../../doxygen_cpp/classeVision_1_1EasyDeepLearning_1_1EDeepLearningTool.html#a9cc32853205dc6ee829863a4cdb7076d) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyDeepLearning_1_1EDeepLearningTool.html#a133b754d21e6eb8d6832d3b187c14eff) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyDeepLearning_1_1EDeepLearningTool.html#ae89570cc91862b690026a329d3d6042a) gets the batch size that maximizes the batch classification speed on the selected GPU (see [Execution Settings and Hardware Support (CPU/GPU)](../engines_and_hardware_support_cpu-gpu.html.md#easydeeplearning-hardware)) according to the available memory.
  * It is common to choose powers of 2 as the batch size for performance reasons.
* The `Data augmentation` settings.
* Whether to use `Deterministic training` or not.
  * The deterministic training allows to reproduce the exact same results when all the settings are the same (tool settings, dataset split and training settings).
  * The deterministic training fixes random seeds used in the training algorithm and uses deterministic algorithms.
  * The deterministic training is usually slower than a non-deterministic training.
  * In **Deep Learning Studio**, the option to use deterministic training and the random seed are available in the advanced parameters.
  * In the API, use [`EDeepLearningTool::SetEnableDeterministicTraining`](../../../doxygen_cpp/classeVision_1_1EasyDeepLearning_1_1EDeepLearningTool.html#a4bdebc50d048c5af74f861865aa16ec8) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyDeepLearning_1_1EDeepLearningTool.html#a473f58d48750eca6af8b41199f029532) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyDeepLearning_1_1EDeepLearningTool.html#ab73f9849e4b0fd81aa3103c496d8aa87) and [`EDeepLearningTool::SetDeterministicTrainingRandomSeed`](../../../doxygen_cpp/classeVision_1_1EasyDeepLearning_1_1EDeepLearningTool.html#aaa0bdb5fac451abf6afa9340111d13e7) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyDeepLearning_1_1EDeepLearningTool.html#a596f7d57c35c0d90607a464c7f5c161e) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyDeepLearning_1_1EDeepLearningTool.html#ac35ab63e06d181cc60be19b2b34c0dd1).

<a id="easydeeplearning-training-continue"></a>

## Continue the Training

You can continue to train a tool that is already trained.

In **Deep Learning Studio**, the dataset split associated with a trained tool is locked.

* You can only continue training a tool with the same dataset split.
* You can still add new training or validation images to the split by moving test images to the training set or the validation set of that split.

#### NOTE
If you used the early stopping (the default behavior) for the previous training, uncheck the `Automatic` button and provide the number of iterations to continue the training.

<a id="easydeeplearning-training-async"></a>

## Asynchronous Training

The training process is  ***asynchronous*** and performed in the background.

* In **Deep Learning Studio**:
  * The training processes are queued.
  * They are automatically executed one after the other.
  * You can manually reorder the training in the processing queue.

  ![](assets/images/easydeeplearning/training_tool_2.webp)
* In the API:
  * The `Train` method corresponding to your tool launches a new thread that does the training in the background.
  * [`WaitForTrainingCompletion`](../../../doxygen_cpp/classeVision_1_1EasyDeepLearning_1_1EDeepLearningTool.html#ab8c484c283f0504e9c2611adc72e7b48) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyDeepLearning_1_1EDeepLearningTool.html#a5d675f325d9f346da030d4b22d2edca4) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyDeepLearning_1_1EDeepLearningTool.html#a535b8be8b312aff38f5468271da17f5e) suspends the program until the whole training is completed.
  * [`WaitForIterationCompletion`](../../../doxygen_cpp/classeVision_1_1EasyDeepLearning_1_1EDeepLearningTool.html#a1fa25eca2d1adfbf42b977db08407baa) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyDeepLearning_1_1EDeepLearningTool.html#a950b8a304a7cf09dec5678f40dde9e39) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyDeepLearning_1_1EDeepLearningTool.html#a30ec50d4b5feaa1c3617a9d186b4aa9a) suspends the program until the current iteration is completed.
  * During the training, [`GetCurrentTrainingProgression`](../../../doxygen_cpp/classeVision_1_1EasyDeepLearning_1_1EDeepLearningTool.html#adf430db6b6af0e862bbe351b8869bcc5) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyDeepLearning_1_1EDeepLearningTool.html#a7ec6c660173ae063d721d4d1792964aa) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyDeepLearning_1_1EDeepLearningTool.html#a7474c3cd7cea13f830daae72cbf6b888) shows the progression of the training.
