Skip to main content

Execute Inference

Manual inference

You can test a manual inference of the brain with the Test inference button in the control panel of the brain topbar. This is used only for testing or measuring the inference time. The inference is done with a black image (empty image).

Brain control panel
Control panel.
info

By performing an inference like this you cannot see the result of the inference.

A manual inference of a brain can also be performed in the Home section. Read more

Execute inference programmatically

inference()

The function to perform an inference programmatically is inference(), which is part of the Brains module. Read more

This function is the equivalent of the Test inference button in the brain control panel, or the Inference button in the Home section.

patchInference()

Patch inference is normally used for segmentations on large images that cannot be processed in a single inference due to memory limitations. The image is divided into smaller patches, and each patch is processed individually. The results are then composed to form the final output.

To perform a patch inference from code with any model, use the patchInference() function, part of the Brains module. Read more

Patch inference using patches of 60x60 px, over an image of 210x90 px.
tip

If you need to diagnose patch inference, the result object of the patchInference() function contains a patches dictionary entry with a array of rectangles corresponding to the patches.

Context padding

When performing patch inference, it is very often beneficial to include some context around each patch to improve the accuracy of the inference. This is necessary because otherwise the context on the edges of each patch would be missing, leading to errors in many cases.

This is where the contextPadding option comes into play. It allows you to specify the number of pixels to pad around each patch during inference. In the following example, a value of 10 px is used for context padding.

Patch inference with 10 px of context padding, using patches of 60x60 px.
  • The overlapping distance between patches will be double the context padding value.
  • The last patches of the rows or columns, the context padding with previous patches can be higher than the specified value, as the image limits are reached.
  • Context padding in the border of the image is not applied, as there is no more image data.
  • Keep in mind that using context padding increases the computation time, as more pixels are processed in total.
tip

Context padding is generally recommended when using patch inference.

Choose an appropriate value based on your specific use case, but these can be used for a first test:

  • Minimum: 1/10 of the patch size. For example, for patches of 500x500 px, a minimum context padding of 50 px.
  • Maximum: 1/6th of the patch size. For example, for patches of 500x500 px, a maximum context padding of approximately 80 px.