# Training a Neural Network

Neural network training is performed in the following general way:

1. Each image in the image set that is being used for training is sampled across its full extent, using the specified Feature Size.
2. The resulting samples are provided as input to the VisionPro Deep Learning deep neural network.
3. For each sample, the neural network produces a specific response (depending on the tool type), and this response is compared with the image labeling associated with the sample's location in the training image.
4. The internal weights within the network are repeatedly adjusted as the samples are processed and reprocessed. The network training system continually adjusts the network weights with a goal of reducing the error (difference or discrepancy) between the network's response and the labeling provided by the user.
5. This overall process is repeated many times, until every sample from every training image has been included at least the number of times specified by the Epoch Count parameter.

Symbol | Definition
1 | The sampling region.
2 | The user-drawn, labeled defect region.
3 | The neural network.
4 | The response by the network.
5 | The iterative process of adjusting the weights to reduce the discrepancy (in other words, error) between the labeled defect (in yellow) and the network response (in blue).

The specific characteristics of the neural network training vary somewhat depending on the type of tool being trained. The largest single determinant that you can use to affect the network training phase is the composition of the training image set. The default behavior for all tools is to train using 50% of the images in the image set, with the images selected at random.

## Red Analyze Focused Supervised

The goal for network training of the Red Analyze tool in Supervised Mode is to reduce the spatial discrepancy between the defect labeling and the detected defects. For Red Analyze Focused Supervised, the network is trained to locate and identify defect regions within an image. The labeling that you perform for the Red Analyze tool in Supervised Mode labels all of the defect pixels in the labeled image. For a given sampling region within the image, the goal of training is for the network to correctly identify the defect pixels as defects.

- Sampling Region and Sampling Parameter

  Red Analyze Focused Supervised samples pixels with the sampler that is tied to a sampling region defined by the users with Sampling Parameters and thus it requires configuring the sampling parameters to determine a sampling region before start its training. If a sampling region does not include any defect pixels, then the network should produce no response.

- Training with Validation

  Red Analyze Focused Supervised does not support the training with the validation scheme and so it doesn't have the validation data set nor require configuring the validation set in Tool Parameters. The purpose of adopting the validation data is to validate each trained neural network and with the results from this validation data for selecting the most performing and stable neural network with the given training set.

## Red Analyze Focused Unsupervised

For the Red Analyze tool in Unsupervised, the network is trained with Good images to locate anomalies within an image. The training image set for the Red Analyze tool in Unsupervised Mode is simply a collection of known defect-free images.

- Sampling Region and Sampling Parameter

  Red Analyze Focused Unsupervised samples pixels with the sampler that is tied to a sampling region defined by the users with Sampling Parameters and thus it requires configuring the sampling parameters to determine a sampling region before start its training. If a sampling region does not include any defect pixels, then the network should produce no response.

- Training with Validation

  Red Analyze Focused Unsupervised does not support the training with the validation scheme and so it doesn't have the validation data set nor require configuring the validation set in Tool Parameters. The purpose of adopting the validation data is to validate each trained neural network and with the results from this validation data for selecting the most performing and stable neural network with the given training set.

## Red Analyze High Detail

The goal for network training of the Red Analyze tool in Supervised Mode is to reduce the spatial discrepancy between the defect labeling and the detected defects. For Red Analyze High Detail, network is also trained to locate and identify defect regions within an image, like Red Analyze Focused Supervised. The labeling that you perform for the Red Analyze tool in High Detail labels all of the defect pixels in the labeled image.

- Sampling Region and Sampling Parameter

  While Red Analyze Focused Supervised samples pixels with a sampling region defined by the users, Red Analyze High Detail samples from the entire image, so they don't have a sampling region, not requiring the sampling parameters in training.

- Training with Validation

  Red Analyze High Detail uses validation data set to validate each trained neural network and with these validation results selects the most performing and stable neural network with the given training set.

## Green Classify Focused

The goal for the Green Classify tool network training is to reduce the number of mismatches between labeled and detected classes. The Green Classify tool is unique among the Deep Learning tools in that it produces a single result for the entire input image. The tool collects image samples in the same way as the other tools, but the samples are pooled during processing and a single result for the entire image is produced.

- Sampling Region and Sampling Parameter

  Green Classify Focused samples pixels with a sampling region defined by the users with Sampling Parameters and thus it requires configuring the sampling parameters to determine a sampling region before start its training.

- Training with Validation

  Green Classify Focused does not support the training with the validation scheme and so it doesn't have the validation data set nor require configuring the validation set in Tool Parameters. The purpose of adopting the validation data is to validate each trained neural network and with the results from this validation data for selecting the most performing and stable neural network with the given training set.

## Green Classify High Detail

The goal for the Green Classify tool network training is to reduce the number of mismatches between labeled and detected classes. The Green Classify tool is unique among the Deep Learning tools in that it produces a single result for the entire input image. The tool collects image samples in the same way as the other tools, but the samples are pooled during processing and a single result for the entire image is produced.

- Sampling Region and Sampling Parameter

  While Green Classify Focused samples pixels with a sampling region defined by the users, Green Classify High Detail samples from the entire image, so they do not have a sampling region, not requiring the sampling parameters in training.

- Training with Validation

  Green Classify High Detail uses the validation data to validate each trained neural network and with these validation results selects the most performing and stable neural network with the given training set.

## Blue Locate

The goal for Blue Locate tool network training is to reduce the discrepancy between the actual feature pose and identity, as defined by your labeling of the image, and the detected pose and identity. For Blue Locate, network is trained to locate and identify features in an image. The Blue tool labeling that you perform identifies the locations and identities of all the features of interest in the image. For a given sampling region within the image, the goal of training is for the network to correctly return the pose of any features that lie within the sampling region. If a sampling region does not include any features, then the network should produce no response for that sample.

- Sampling Region and Sampling Parameter

  Blue Locate samples pixels with the sampler that is tied to a sampling region defined by the users with Sampling Parameters and thus it requires configuring the sampling parameters to determine a sampling region before start its training. If a sampling region does not include any feature pixel, then the network should produce no response.

- Training with Validation

  Blue Locate does not support the training with the validation scheme and so it doesn't have the validation data set nor require configuring the validation set in Tool Parameters. The purpose of adopting the validation data is to validate each trained neural network and with the results from this validation data for selecting the most performing and stable neural network with the given training set.

## Blue Read

The goal for Blue Read tool network training is to reduce the discrepancy between the actual character feature pose and identity, as defined by your labeling of the image, and the detected character pose and identity. The Blue Read tool uses the a similar approach to the Blue Locate tool, although less attention is paid to pose .

One important difference that distinguishes Blue Read from other tools is that its neural network is an already trained (pre-trained) one for character recognition. So, it's not necessary to label multiple instances of each character, but the more labeled instances there are, the better the results will be during the training phase. Training will increase the accuracy of the tool. The more you train, the more you tune your neural network towards your particular training set. The tool starts with a very generalized model, and every time you train, the tool is going to key in more and more to what you have in your training set. So, if your training set isn't a very good representation of what you'll encounter at run time, you would be better off to minimize the amount of training you'll do.

If you have labeled everything, and the labeled features represent the expected appearances (and preferably involve the instances of each character), training will improve the performance of the tool. However, if you have an unrepresentative set of images (for example, characters on a different background or a slant that isn't expected at runtime), training may narrow the performance to the unrepresentative set of characters, so training isn't advised. To have a successful implementation of the tool, you need to have a set of images that contain the full range of expected variations of the characters at runtime.

Note: If the tool is able to read the full image database of all of the characters in your images with 100% accuracy, you do not need to train.

- Sampling Region and Sampling Parameter

  Blue Read samples pixels with the sampler that is tied to a sampling region defined by the users with Sampling Parameters and thus it requires configuring the sampling parameters to determine a sampling region before start its training. If a sampling region does not include any feature pixel, then the network should produce no response.

- Training with Validation

  Blue Read does not support the training with the validation scheme and so it doesn't have the validation data set nor require configuring the validation set in Tool Parameters. The purpose of adopting the validation data is to validate each trained neural network and with the results from this validation data for selecting the most performing and stable neural network with the given training set.