# Training Parameters

The Deep Learning framework provides several general parameters that you can use to influence the training process: Epoch Count for all modes, Capacity (Red Analyze tool in Unsupervised Mode only) for Focused Mode, and Minimum Epochs, Patience Epochs, and Validation Set Ratio, Class Weights, Patch Size, and Stride for High Detail modes.

### Epoch Count

Epoch Count parameter lets you control how much network refinement is performed. As described in the Neural Network Training topic, the training process repeatedly processes input samples through the network, compares the network result with the user-supplied labeling, then adjusts the network weights with a goal of reducing this error. Because of the large number of network nodes (and thus weights), this process can be repeated almost indefinitely, with each iteration resulting in a progressively smaller improvement in the error. Increasing the Epoch Count parameter setting increases the number of iterations of training that are performed. This will reduce the network error on the training images at the cost of requiring more time for training.

It is important to keep in mind, however, that the goal for training the network is to perform accurately on all images, not just those used for training. As the epoch count is increased, the network will tend to experience overfitting, where the error on untrained images increases at the same time that the error on trained images decreases. For this reason, you should carefully monitor the network performance on all images as you adjust the epoch count. You have to choose an optimal Epoch for your dataset because its optimal value is different by dataset, particularly the statistical diversity of your dataset.

### Capacity

Red Analyze tool in Unsupervised Mode also exposes the Capacity parameter. In general, neural network capacity is a measure of the amount of information that can be encoded (learned) by the network. The Deep Learning network architecture is less capacity constrained for the Blue Locate, Blue Read, Green Classify and Red Analyze (in Supervised Mode) tools, because these tools process individual samples through the trained network. The Red Analyze tool in Unsupervised Mode uses a different network architecture that allows it to detect untrained defects in the entire image. For some high-complexity images, the tool may under-fit whereas for some low-complexity images, the tool may over-fit. Therefore, the tool response can be optimized on a given image set by choosing the appropriate network capacity.

### Minimum Epochs

Due to the validation set, High Detail mode can select the model created from low epoch as a final model to prevent overfitting. If you set a minimum epoch, High Detail mode selects a model created after this epoch as a final model.
If you get a good processing result to the train set, but not a good one to the test set, you may think overfitting. However, if the processing result is not good to the train and test set, it would be underfitting. In this case, it is recommended to use higher minimum epochs.

### Patience Epochs

Each time a fixed number of epochs (1/8 epochs) is executed, High Detail mode measures loss of the model. If no drop of loss is observed for N (the value of Patience Epochs) epochs, High Detail mode stops training and select the model with lowest loss until the epoch. You can utilize patience epoch for early stopping in case that there is no need to proceed a training process unless loss drops over a certain period.

Tip: If it is complicated to set a specific epoch count, you can increase the epoch count and create a model based on patience.

### Validation Set Ratio

It is the ratio of number of views which will be used as a validation set among training set. If you increase the validation set ratio while keeping the number of training set, the amount of data used for training will decrease. So, setting a high validation set ratio could affect the performance negatively when you are using small training set.
On the other hands, too low validation set ratio will not be helpful for selecting good model for unseen data set.

### Class Weights

Class weights are used to apply different batch sampling for each class.
When there are imbalances in the number of views per class (tag), you may use class weight to put different weights on each class for training. For example, the ratio of Class 1 to Class 2 as 2:1 means that the number of training images for Class 1 is as twice as Class 2.
To set class weights, click the hyperlink text of class weight in tool parameter panel and open the class weights dialog. If you double-click the weight cell of the list, you can edit the class weight. You cannot put decimal number in here (only natural numbers).

### Patch Size

Patch Size is the size of the square that divides each view into several chunks. Training (feature detection) and processing each view is executed based on each chunk. Generally, a smaller Patch Size works better for catching small subtle blobs, and a larger Patch Size for large obvious blobs in terms of convergence speed in training.

### Stride

Stride is the ratio of stride for a Patch when extracting features from a view with Patch.

- The width-wise pixel stride for a Patch = Patch width x Stride

- The height-wise pixel stride for a Patch = Patch height x Stride

For example, if a Patch's size is 128x128 and Stride is 25% then the steps for width-wise stride and height-wise stride for this Patch are 32 (128x0.25).

Generally, a smaller Stride works better in catching the details of an image so that increases the network model accuracy but slows down Train speed given a certain Epoch value.