# Process Neural Network (Inferencing)

At runtime, each sample from the runtime image is processed individually, using the tool's trained network, and an individual network response is obtained for each sample. The response from the network is expressed as a probability map, where each pixel in the sampled region of the input image is assigned a probability. The meaning of the probability map depends on which tool is being used. For the Green Classify tool, the response is the classification and the probability that the classification is correct.

These whole-image probability maps are assembled from the interpolated network responses to individual samples. The final results returned to the user (feature poses and identities, and defect regions) are based on a results formation process that the user controls by specifying thresholds for class probability.

In the above context, it is important to understand that the probability returned by a tool may not reflect well with our notion of how likely a certain judgment is. This is mostly due to the fact that the tools have a "limited view of the world" in that they do not return probabilities with respect to our wide and rich visual experience, but rather with respect to their very limited visual world of a couple of classes. Thus, for instance, in the case of a Green Classify tool, it is very well possible that the tool will assign a very high probability to a new and therefore unknown class even though these classes look very dissimilar to us. This is simply because to the tool that class looks many times more similar to that known class than any other.

The processing (inferencing) of a trained tool is automatically executed when the training is finished without issues. If you want to manually re-process the trained tool, click button.

## Feature Sampling for Processing

Each input image is exhaustively sampled at runtime, and the individual samples are then processed by the trained network. The same feature size used for training is also used at runtime (ensuring that the trained network is processing inputs that are consistent with the inputs used for training).

Unlike training, where the sampling density is determined automatically, you can control the runtime sampling density for all the Deep Learning tools. The sampling density determines the degree of overlap between adjacent samples. A sampling density rate of 1 means that the sampling location is incremented by the feature size between samples. The default sampling density rate for most tools is 3, which means that the sampling location is incremented by one third of the feature size.

Sampling Density = 1 (4 samples) | Sampling Density = 3 (4 samples)
--- | ---

Note:

For the Green Classify Tool in Focused mode, there is a fixed limit to the number of samples that can be processed for a single runtime image, which is 50,000. The number of samples is determined by the Feature Size (Sampling Parameters), the image size, and the Sampling Density, as shown in the following equation:

Note: If you have the Masking Mode parameter enabled, the sample count is reduced by the proportion of the pixels that are masked.
Tip:

When the combination of image size, Feature Size and Sampling Density settings exceeds the limit, the following error message may be displayed:

"Failed to process database sample 'image_file.name' (maximal number of samples exceeded, please reduce the sampling density, view size and/or feature size)."

In this event, consider options to reduce the number of pixels being processed, either through the use of a mask, focusing the ROI to specific areas or using a larger feature size setting.

## Configure Processing Parameters

The Processing parameters control the way that images are processed by the tool. This is often called ‘inference’ in deep learning. Processing with the same models will always give you the same results. Changing these parameters does not require the tool to be retrained; the effect can be seen right away by reprocessing the database. To re-process the tool, click button.

Parameter | Description
--- | ---
Sampling Density | Specifies the density of sampling points with respect to the tool's Feature Size (FS) setting. The sampling density determines the degree of overlap between adjacent samples. A sampling rate of 1 means that the sampling location is incremented by the feature size between samples. The default sampling rate for most tools is 3, which means that the sampling location is incremented by one third of the feature size. Tip: One key aspect of the Sampling Density parameter is the relationship between the tool's processing time and accuracy. A tool's processing time depends approximately quadratically to the Sampling Density (Sd) value. For example, a Sampling Density setting of 1 is approximately nine times faster than a setting of 3 (n2). While higher Sampling Density settings are more accurate, it significantly impacts the processing time of the tool.
Threshold | The Threshold parameter determines the minimum score that a view must have to be classified.