Skip to content

Training a Classifier

Unlike AI Models, which run a pretrained deep-learning network you supply as a TorchScript export, the Train Classifier dialog trains a lightweight classical machine-learning model - Random Forest, k-Nearest Neighbors, or a small neural network (MLP) - directly from examples you paint on your own images. No external model file is needed to get started; the model is built entirely from your annotations and saved as an .evamodel file.

Train Classifier dialog, training a neural-network pixel classifier

Classifier TypeClassifiesFeature sourceComparable to
Pixel ClassifierEvery pixel of an image, independentlyIntensity and texture/edge filters computed around each pixelilastik-style pixel classification
Object ClassifierObjects already extracted by a pipeline (or painted directly)Shape and per-channel intensity metrics of each objectA learned alternative/complement to Classify Objects’s rule-based criteria

A Pixel Classifier produces a segmentation mask - the same output shape Threshold produces - so it slots into a pipeline before Connected Components/Extract Objects. An Object Classifier instead scores objects that already exist in the pipeline cache, the same input Classify Objects works from.

1. Provide examples with the painting tool

Section titled “1. Provide examples with the painting tool”

Both classifier types learn from objects you draw with the Region Annotation tool (Rectangle / Oval / Polygon - see Region Annotation), independent of any pipeline.

  • Pixel Classifier - paint a few representative patches of each class you want to predict, and paint a couple of background patches too. The classifier needs negative examples of everything that isn’t a target class, not just positive examples of the classes themselves - a model trained only on “Nucleus” patches has never seen what a non-nucleus pixel looks like.
  • Object Classifier - paint around whole objects (or run a segmentation pipeline first and use its output) - each candidate object gets its class assigned inside the training dialog itself, in the next step, not beforehand.

2. Open Train Classifier and set up the model

Section titled “2. Open Train Classifier and set up the model”

Pick Classifier Type (Pixel or Object Classifier) and a Model Name. Optionally click Load Existing Model… to continue training a previously-saved model instead of starting fresh.

The Training Objects list shows every manually-painted object in scope (the current image, or every project image if Include annotations from other images is enabled under Training Data Source). For each one:

  • Assign a class from the dropdown.
  • Uncheck Train on this to exclude a bad or outlier annotation from training without deleting it.

Only objects with a class assigned here are used as training samples.

The Classes to Train checklist controls which of the project’s classes become prediction targets. Classes with at least one labeled object are pre-checked, but any class can be selected ahead of labeling it.

Pick Random Forest, K-Nearest Neighbors, or Neural Network (MLP) and configure its hyperparameters - see Choosing a Model below.

Click Train. A status banner shows progress; for MLP, it streams live train/validation loss per epoch. Cancel stops an in-flight run. The dialog stays open after training finishes so you can inspect the result and retrain without losing your settings.

The trained model is saved to <project>/models/<model name>.evamodel. Add an AI Pixel Classifier or AI Object Classifier step to a pipeline and point it at that file.

AlgorithmGood default when…Key defaults
Random ForestYou want a robust first try - insensitive to feature scale, tolerates noisy or redundant features well50 trees, max depth 20 (capped deliberately - a pixel classifier re-walks every tree for every pixel of every image at inference time, so depth/tree-count trade accuracy for prediction speed)
k-Nearest NeighborsClasses form simple, well-separated clusters in feature spacek = 5, distance-weighted voting, Cover Tree search
Neural Network (MLP)You have a larger, more varied set of labeled examples and a feature set too complex for a simple decision boundaryHidden layers 64, 32, ReLU, 200 epochs, Adam optimizer (learning rate 0.001)

For MLP, watch the per-epoch status banner: if validation loss climbs while training loss keeps falling, the model is overfitting - add more/more varied examples, or shrink the hidden-layer sizes, rather than just training longer. A validation split is only computed once there are at least 25 total training samples; below that, only training loss is shown.

See Random Forest, k-Nearest Neighbors, and Neural Network (MLP) for a detailed look at how each algorithm actually works.

Each entry in Feature Channels is one input to the classifier, computed from the selected Image Channel:

FeatureCaptures
RawThe unfiltered pixel value - always worth including as a baseline
Gaussian BlurLocal intensity averaged over a radius (σ) - texture/context at a given scale
SobelEdge strength
LaplacianZero-crossing edges (second derivative)
Structure TensorLocal orientation and coherence (Eigenvalue X/Y, Coherence)
HessianBlob- and ridge-like structures (Determinant, Eigenvalue X/Y)
Rank FilterLocal statistics - mean, median, min, max, or outlier deviation

A few rules of thumb (the same approach ilastik’s pixel classification is built around):

  • Combine a few filter types across several scales, rather than many filter types at one scale. Use Quick add scales to add the same Gaussian Blur at several σ values at once (e.g. 1, 2, 4, 8) - small σ picks up fine detail, larger σ adds regional context.
  • Pair Laplacian/Hessian with pre-blurring. Both are second-derivative filters and amplify noise; enabling their Pre-blur option (Laplacian-/Hessian-of-Gaussian) smooths the image first.
  • Pixel classifiers train on a single image channel. If the discriminating signal is spread across channels, you’ll need to pick the most informative one or train separate models.
  • More features cost more inference time (every pixel of every image needs every feature computed) without necessarily improving accuracy - start small and add features only where the classifier is actually confusing two classes.

Choosing Object Metrics (Object Classifier)

Section titled “Choosing Object Metrics (Object Classifier)”

The Object Metrics checklist offers shape metrics (Area, Perimeter, Circularity, Solidity, Aspect Ratio, Roundness, Compactness, Feret/Min Feret Diameter, Ellipse Major/Minor/Angle, Eccentricity, Touches Edge) and per-channel intensity statistics (Sum, Min, Max, Average).

The object’s own assigned class and its centroid/position are deliberately excluded - including the class would leak the training label itself, and position would teach the model where an object is instead of what it looks like, a classic overfitting trap.

Pick a handful of metrics that actually distinguish your classes rather than checking everything - e.g. Circularity + Solidity to separate round vesicles from irregular debris, or a channel’s Intensity Average to separate marker-positive from marker-negative objects. Fewer, meaningful features generalize better from a limited set of hand-labeled examples.